Skip to content

Commit

Permalink
taprpc: Updated ListAssetRequest to include additional filter options
Browse files Browse the repository at this point in the history
  • Loading branch information
itsrachelfish committed Nov 20, 2024
1 parent 77e8b28 commit ccf4b76
Show file tree
Hide file tree
Showing 4 changed files with 1,009 additions and 881 deletions.
27 changes: 23 additions & 4 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/lightninglabs/taproot-assets/rfqmsg"
"github.com/lightninglabs/taproot-assets/rpcperms"
"github.com/lightninglabs/taproot-assets/tapchannel"
"github.com/lightninglabs/taproot-assets/tapdb"
"github.com/lightninglabs/taproot-assets/tapfreighter"
"github.com/lightninglabs/taproot-assets/tapgarden"
"github.com/lightninglabs/taproot-assets/tappsbt"
Expand Down Expand Up @@ -953,8 +954,13 @@ func (r *rpcServer) ListAssets(ctx context.Context,
}

rpcAssets, err := r.fetchRpcAssets(
ctx, req.WithWitness, req.IncludeSpent, req.IncludeLeased,
ctx,
req.WithWitness,
req.IncludeSpent,
req.IncludeLeased,
req.MinAmount,
)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1007,10 +1013,20 @@ func (r *rpcServer) ListAssets(ctx context.Context,
}

func (r *rpcServer) fetchRpcAssets(ctx context.Context, withWitness,
includeSpent, includeLeased bool) ([]*taprpc.Asset, error) {
includeSpent, includeLeased bool,
minAmountFilter uint64) ([]*taprpc.Asset, error) {

constraints := tapfreighter.CommitmentConstraints{
CoinSelectType: tapsend.ScriptTreesAllowed,
MinAmt: minAmountFilter,
}

filters := &tapdb.AssetQueryFilters{
CommitmentConstraints: constraints,
}

assets, err := r.cfg.AssetStore.FetchAllAssets(
ctx, includeSpent, includeLeased, nil,
ctx, includeSpent, includeLeased, filters,
)
if err != nil {
return nil, fmt.Errorf("unable to read chain assets: %w", err)
Expand Down Expand Up @@ -1161,7 +1177,10 @@ func (r *rpcServer) listBalancesByGroupKey(ctx context.Context,
func (r *rpcServer) ListUtxos(ctx context.Context,
req *taprpc.ListUtxosRequest) (*taprpc.ListUtxosResponse, error) {

rpcAssets, err := r.fetchRpcAssets(ctx, false, false, req.IncludeLeased)
rpcAssets, err := r.fetchRpcAssets(
ctx, false, false, req.IncludeLeased, 0,
)

if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit ccf4b76

Please sign in to comment.