Skip to content

Commit

Permalink
chore: rename types and add TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Dec 14, 2023
1 parent 1457f8c commit ee4a87e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ You can also contribute to our [bounty program](https://github.com/getAlby/light
`pay_keysend`

⚠️ `make_invoice`
- ⚠️ invoice in response missing (TODO)
- ⚠️ does not match spec

⚠️ `lookup_invoice`
- ⚠️ invoice in response missing (TODO)
- ⚠️ response does not match spec, missing fields
- ⚠️ does not match spec

`list_transactions`
- ⚠️ from and until in request not supported
Expand All @@ -165,11 +164,10 @@ You can also contribute to our [bounty program](https://github.com/getAlby/light

⚠️ `make_invoice`
- ⚠️ expiry in request not supported
- ⚠️ invoice in response missing (TODO)
- ⚠️ does not match spec

⚠️ `lookup_invoice`
- ⚠️ invoice in response missing (TODO)
- ⚠️ response does not match spec, missing fields (TODO)
- ⚠️ does not match spec

`list_transactions`
- ⚠️ offset and unpaid in request not supported
Expand Down
2 changes: 1 addition & 1 deletion alby.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (svc *AlbyOAuthService) GetBalance(ctx context.Context, senderPubkey string
return 0, errors.New(errorPayload.Message)
}

func (svc *AlbyOAuthService) ListTransactions(ctx context.Context, senderPubkey string, from, until, limit, offset uint64, unpaid bool, invoiceType string) (invoices []Invoice, err error) {
func (svc *AlbyOAuthService) ListTransactions(ctx context.Context, senderPubkey string, from, until, limit, offset uint64, unpaid bool, invoiceType string) (invoices []Nip47Transaction, err error) {
app := App{}
err = svc.db.Preload("User").First(&app, &App{
NostrPubkey: senderPubkey,
Expand Down
8 changes: 4 additions & 4 deletions lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type LNClient interface {
GetInfo(ctx context.Context, senderPubkey string) (info *NodeInfo, err error)
MakeInvoice(ctx context.Context, senderPubkey string, amount int64, description string, descriptionHash string, expiry int64) (invoice string, paymentHash string, err error)
LookupInvoice(ctx context.Context, senderPubkey string, paymentHash string) (invoice string, paid bool, err error)
ListTransactions(ctx context.Context, senderPubkey string, from, until, limit, offset uint64, unpaid bool, invoiceType string) (invoices []Invoice, err error)
ListTransactions(ctx context.Context, senderPubkey string, from, until, limit, offset uint64, unpaid bool, invoiceType string) (invoices []Nip47Transaction, err error)
}

// wrap it again :sweat_smile:
Expand Down Expand Up @@ -57,7 +57,7 @@ func (svc *LNDService) GetBalance(ctx context.Context, senderPubkey string) (bal
return int64(resp.LocalBalance.Sat), nil
}

func (svc *LNDService) ListTransactions(ctx context.Context, senderPubkey string, from, until, limit, offset uint64, unpaid bool, invoiceType string) (invoices []Invoice, err error) {
func (svc *LNDService) ListTransactions(ctx context.Context, senderPubkey string, from, until, limit, offset uint64, unpaid bool, invoiceType string) (invoices []Nip47Transaction, err error) {
maxInvoices := uint64(limit)
if err != nil {
return nil, err
Expand All @@ -84,7 +84,7 @@ func (svc *LNDService) ListTransactions(ctx context.Context, senderPubkey string
}
}
for _, inv := range incomingInvoices {
invoice := Invoice{
invoice := Nip47Transaction{
Type: "incoming",
Invoice: inv.PaymentRequest,
Description: inv.Memo,
Expand All @@ -110,7 +110,7 @@ func (svc *LNDService) ListTransactions(ctx context.Context, senderPubkey string
outgoingInvoices = outgoingResp.Payments
}
for _, inv := range outgoingInvoices {
invoice := Invoice{
invoice := Nip47Transaction{
Type: "outgoing",
Invoice: inv.PaymentRequest,
Preimage: inv.PaymentPreimage,
Expand Down
7 changes: 5 additions & 2 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ type Payment struct {
UpdatedAt time.Time
}

type Invoice struct {
// TODO: move to models/Nip47
type Nip47Transaction struct {
Type string `json:"type"`
Invoice string `json:"invoice"`
Description string `json:"description"`
Expand Down Expand Up @@ -168,11 +169,13 @@ type MakeInvoiceRequest struct {
DescriptionHash string `json:"description_hash"`
}

// TODO: this should have the same content as Nip46Transaction
type MakeInvoiceResponse struct {
PaymentRequest string `json:"payment_request"`
PaymentHash string `json:"payment_hash"`
}

// TODO: this should have the same content as Nip46Transaction
type LookupInvoiceResponse struct {
PaymentRequest string `json:"payment_request"`
Settled bool `json:"settled"`
Expand Down Expand Up @@ -283,5 +286,5 @@ type Nip47ListTransactionsParams struct {
}

type Nip47ListTransactionsResponse struct {
Transactions []Invoice `json:"transactions"`
Transactions []Nip47Transaction `json:"transactions"`
}
24 changes: 12 additions & 12 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var mockNodeInfo = NodeInfo{
BlockHash: "123blockhash",
}

var mockInvoices = []Invoice{
var mockTransactions = []Nip47Transaction{
{
Type: "incoming",
Invoice: mockInvoice,
Expand Down Expand Up @@ -562,15 +562,15 @@ func TestHandleEvent(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 2, len(received.Result.(*Nip47ListTransactionsResponse).Transactions))
transaction := received.Result.(*Nip47ListTransactionsResponse).Transactions[0]
assert.Equal(t, mockInvoices[0].Type, transaction.Type)
assert.Equal(t, mockInvoices[0].Invoice, transaction.Invoice)
assert.Equal(t, mockInvoices[0].Description, transaction.Description)
assert.Equal(t, mockInvoices[0].DescriptionHash, transaction.DescriptionHash)
assert.Equal(t, mockInvoices[0].Preimage, transaction.Preimage)
assert.Equal(t, mockInvoices[0].PaymentHash, transaction.PaymentHash)
assert.Equal(t, mockInvoices[0].Amount, transaction.Amount)
assert.Equal(t, mockInvoices[0].FeesPaid, transaction.FeesPaid)
assert.Equal(t, mockInvoices[0].SettledAt.Unix(), transaction.SettledAt.Unix())
assert.Equal(t, mockTransactions[0].Type, transaction.Type)
assert.Equal(t, mockTransactions[0].Invoice, transaction.Invoice)
assert.Equal(t, mockTransactions[0].Description, transaction.Description)
assert.Equal(t, mockTransactions[0].DescriptionHash, transaction.DescriptionHash)
assert.Equal(t, mockTransactions[0].Preimage, transaction.Preimage)
assert.Equal(t, mockTransactions[0].PaymentHash, transaction.PaymentHash)
assert.Equal(t, mockTransactions[0].Amount, transaction.Amount)
assert.Equal(t, mockTransactions[0].FeesPaid, transaction.FeesPaid)
assert.Equal(t, mockTransactions[0].SettledAt.Unix(), transaction.SettledAt.Unix())

// get_info: without permission
newPayload, err = nip04.Encrypt(nip47GetInfoJson, ss)
Expand Down Expand Up @@ -680,6 +680,6 @@ func (mln *MockLn) LookupInvoice(ctx context.Context, senderPubkey string, payme
return mockInvoice, false, nil
}

func (mln *MockLn) ListTransactions(ctx context.Context, senderPubkey string, from, until, limit, offset uint64, unpaid bool, invoiceType string) (invoices []Invoice, err error) {
return mockInvoices, nil
func (mln *MockLn) ListTransactions(ctx context.Context, senderPubkey string, from, until, limit, offset uint64, unpaid bool, invoiceType string) (invoices []Nip47Transaction, err error) {
return mockTransactions, nil
}

0 comments on commit ee4a87e

Please sign in to comment.