diff --git a/README.md b/README.md index 2b6eb268..c1501031 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/alby.go b/alby.go index 617e5e2d..96024e18 100644 --- a/alby.go +++ b/alby.go @@ -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, diff --git a/lnd.go b/lnd.go index a39ab204..f1f11ca3 100644 --- a/lnd.go +++ b/lnd.go @@ -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: @@ -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 @@ -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, @@ -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, diff --git a/models.go b/models.go index 6254cd27..014ae931 100644 --- a/models.go +++ b/models.go @@ -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"` @@ -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"` @@ -283,5 +286,5 @@ type Nip47ListTransactionsParams struct { } type Nip47ListTransactionsResponse struct { - Transactions []Invoice `json:"transactions"` + Transactions []Nip47Transaction `json:"transactions"` } diff --git a/service_test.go b/service_test.go index e74fcfc1..befaac36 100644 --- a/service_test.go +++ b/service_test.go @@ -110,7 +110,7 @@ var mockNodeInfo = NodeInfo{ BlockHash: "123blockhash", } -var mockInvoices = []Invoice{ +var mockTransactions = []Nip47Transaction{ { Type: "incoming", Invoice: mockInvoice, @@ -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) @@ -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 }