mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
accounts: add payment methods to Store interface
Introduce the ListAccountPayments and CountAccountPayments methods to the accounts Store interface. ListAccountPayments enables retrieval of a paginated list of payment entries associated with a given account ID, supporting offset and limit. CountAccountPayments returns the total number of payments associated with the account.
This commit is contained in:
parent
857fb900fd
commit
009a5c28bc
2 changed files with 84 additions and 0 deletions
|
|
@ -285,6 +285,16 @@ type Store interface {
|
|||
DeleteAccountPayment(_ context.Context, id AccountID,
|
||||
hash lntypes.Hash) error
|
||||
|
||||
// ListAccountPayments returns a paginated list of payments
|
||||
// associated with the given account, sorted in ascending
|
||||
// lexicographical order of their payment hash.
|
||||
ListAccountPayments(ctx context.Context, id AccountID, offset,
|
||||
limit int32) ([]*AccountPaymentEntry, error)
|
||||
|
||||
// CountAccountPayments returns the total number of payments associated
|
||||
// with the given account.
|
||||
CountAccountPayments(ctx context.Context, id AccountID) (uint64, error)
|
||||
|
||||
// RemoveAccount finds an account by its ID and removes it from the¨
|
||||
// store.
|
||||
RemoveAccount(ctx context.Context, id AccountID) error
|
||||
|
|
|
|||
|
|
@ -906,3 +906,77 @@ func TestCheckLabel(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestListAccountPayments tests listing and counting payment entries associated
|
||||
// with a given account.
|
||||
func TestListAccountPayments(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
|
||||
store := NewTestDB(t, clock.NewTestClock(time.Now()))
|
||||
|
||||
// Listing payments for non-existent account should fail.
|
||||
_, err := store.ListAccountPayments(
|
||||
ctx, AccountID{}, 0, 0,
|
||||
)
|
||||
require.ErrorIs(t, err, ErrAccNotFound)
|
||||
|
||||
acct, err := store.NewAccount(
|
||||
ctx, 10000, time.Time{}, "payment-list",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Initially, there should be no payments.
|
||||
payments, err := store.ListAccountPayments(
|
||||
ctx, acct.ID, 0, 0,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, payments)
|
||||
|
||||
count, err := store.CountAccountPayments(ctx, acct.ID)
|
||||
require.NoError(t, err)
|
||||
require.Zero(t, count)
|
||||
|
||||
// Add 3 payments.
|
||||
hash1 := lntypes.Hash{1}
|
||||
hash2 := lntypes.Hash{2}
|
||||
hash3 := lntypes.Hash{3}
|
||||
|
||||
_, err = store.UpsertAccountPayment(
|
||||
ctx, acct.ID, hash1, 100, lnrpc.Payment_IN_FLIGHT,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = store.UpsertAccountPayment(
|
||||
ctx, acct.ID, hash2, 200, lnrpc.Payment_SUCCEEDED,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = store.UpsertAccountPayment(
|
||||
ctx, acct.ID, hash3, 300, lnrpc.Payment_FAILED,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test counting all payments.
|
||||
count, err = store.CountAccountPayments(ctx, acct.ID)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 3, count)
|
||||
|
||||
// List all payments in default order (ascending by hash).
|
||||
payments, err = store.ListAccountPayments(
|
||||
ctx, acct.ID, 0, 3,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, payments, 3)
|
||||
require.Equal(t, hash1, payments[0].Hash)
|
||||
require.Equal(t, hash2, payments[1].Hash)
|
||||
require.Equal(t, hash3, payments[2].Hash)
|
||||
|
||||
// Test offset and limit.
|
||||
payments, err = store.ListAccountPayments(
|
||||
ctx, acct.ID, 1, 1,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, payments, 1)
|
||||
require.Equal(t, hash2, payments[0].Hash)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue