Skip to content

Commit 9cc6dcb

Browse files
wallet: add pagination to wallets
1 parent 7c78cac commit 9cc6dcb

File tree

14 files changed

+901
-101
lines changed

14 files changed

+901
-101
lines changed

wallet/internal/db/data_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ type Block struct {
240240
Timestamp time.Time
241241
}
242242

243+
// ListWalletsQuery contains the parameters for listing wallets.
244+
type ListWalletsQuery struct {
245+
// Page holds the pagination parameters for this query.
246+
Page page.Request[uint32]
247+
}
248+
243249
// CreateWalletParams contains the parameters required to create a new wallet.
244250
type CreateWalletParams struct {
245251
// Name is the name of the new wallet.

wallet/internal/db/interface.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,15 @@ type WalletStore interface {
123123
// error if the wallet is not found.
124124
GetWallet(ctx context.Context, name string) (*WalletInfo, error)
125125

126-
// ListWallets returns a slice of WalletInfo for all wallets stored in
127-
// the database. It returns an empty slice if no wallets are found, or
128-
// an error if the retrieval fails.
129-
ListWallets(ctx context.Context) ([]WalletInfo, error)
126+
// ListWallets returns one page of wallets for the given query,
127+
// including a next-cursor for the following page.
128+
ListWallets(ctx context.Context, query ListWalletsQuery) (
129+
page.Result[WalletInfo, uint32], error)
130+
131+
// IterWallets returns an iterator that fetches pages transparently and
132+
// yields wallets one by one until exhaustion or error.
133+
IterWallets(ctx context.Context,
134+
query ListWalletsQuery) iter.Seq2[WalletInfo, error]
130135

131136
// UpdateWallet updates various properties of a wallet, such as its
132137
// birthday, birthday block, or sync state. The specific fields to

0 commit comments

Comments
 (0)