Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions funding.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,14 @@ func (w *wallet) Balance(ctx context.Context) (*types.Balance, error) {
}, nil
}

func (w *wallet) ListSpendableVtxos(ctx context.Context) ([]clienttypes.Vtxo, error) {
if err := w.safeCheck(); err != nil {
return nil, err
}

return w.store.VtxoStore().GetSpendableVtxos(ctx)
}

func (w *wallet) ListVtxos(
ctx context.Context,
) ([]clienttypes.Vtxo, []clienttypes.Vtxo, error) {
ctx context.Context, page types.Page, filter types.VtxoFilter,
) ([]clienttypes.Vtxo, error) {
if err := w.safeCheck(); err != nil {
return nil, nil, err
return nil, err
}

return w.store.VtxoStore().GetAllVtxos(ctx)
return w.store.VtxoStore().GetVtxos(ctx, page, filter)
}

func (w *wallet) NotifyIncomingFunds(
Expand All @@ -157,7 +149,7 @@ func (w *wallet) newOffchainAddress(ctx context.Context) (string, error) {
func (w *wallet) getOffchainBalance(
ctx context.Context,
) (*types.OffchainBalance, map[string]uint64, error) {
vtxos, _, err := w.store.VtxoStore().GetAllVtxos(ctx)
vtxos, err := w.store.VtxoStore().GetVtxos(ctx, types.Page{}, types.VtxoFilterSpendable)
if err != nil {
return nil, nil, err
}
Expand All @@ -170,10 +162,6 @@ func (w *wallet) getOffchainBalance(
amountByExpiration = make(map[int64]uint64)
)
for _, vtxo := range vtxos {
if vtxo.Spent || vtxo.Unrolled {
continue
}

// Classify VTXO by state. Priority: Recoverable > Preconfirmed > default.
switch {
case vtxo.IsRecoverable():
Expand Down
3 changes: 2 additions & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ func (w *wallet) scheduleNextSettlement() {

nextSettlement := w.scheduler.GetTaskScheduledAt()

vtxos, err := w.store.VtxoStore().GetSpendableVtxos(context.Background())
vtxos, err := w.store.VtxoStore().
GetVtxos(context.Background(), types.Page{}, types.VtxoFilterSpendable)
if err != nil {
log.WithError(err).Warn("failed to get spendable vtxos while scheduling next settlement")
return
Expand Down
7 changes: 5 additions & 2 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ type Wallet interface {
CompleteUnroll(ctx context.Context, to string) (string, error)
OnboardAgainAllExpiredBoardings(ctx context.Context) (string, error)
WithdrawFromAllExpiredBoardings(ctx context.Context, to string) (string, error)
ListVtxos(ctx context.Context) (spendable, spent []clienttypes.Vtxo, err error)
ListSpendableVtxos(ctx context.Context) ([]clienttypes.Vtxo, error)
ListVtxos(
ctx context.Context,
page types.Page,
filter types.VtxoFilter,
Copy link
Copy Markdown
Contributor

@altafan altafan May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't be nice to keep having the option pattern so the user just calls (?):

ListVtxos(ctx) -> gets all vtxos, paginated by default if the response is too big
// Or
ListVtxos(ctx, WithPage(token)) -> gets a specific page given its token
// Or
ListVtxos(ctx, WithSpendableOnly()) -> gets only spendable vtxos, paginated by default if the response is too big
// Or
ListVtxos(ctx, WithSpendableOnly(), WithPage(token)) -> gets a specific page of only spendable vtxos

) ([]clienttypes.Vtxo, error)
Dump(ctx context.Context) (seed string, err error)
GetTransactionHistory(ctx context.Context) ([]clienttypes.Transaction, error)
GetTransactionEventChannel(ctx context.Context) <-chan types.TransactionEvent
Expand Down
3 changes: 2 additions & 1 deletion send.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func (w *wallet) getSpendableVtxos(
ctx context.Context, withRecoverable bool,
) ([]clienttypes.VtxoWithTapTree, error) {
w.dbMu.Lock()
spendableVtxos, err := w.store.VtxoStore().GetSpendableVtxos(ctx)
spendableVtxos, err := w.store.VtxoStore().
GetVtxos(ctx, types.Page{}, types.VtxoFilterSpendable)
w.dbMu.Unlock()
if err != nil {
return nil, err
Expand Down
Loading
Loading