Skip to content

Commit

Permalink
taprpc: Update ListAssetRequest to include additional filter options
Browse files Browse the repository at this point in the history
  • Loading branch information
itsrachelfish committed Dec 4, 2024
1 parent 84adc01 commit f5d1985
Show file tree
Hide file tree
Showing 4 changed files with 1,060 additions and 911 deletions.
46 changes: 43 additions & 3 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,45 @@ func (r *rpcServer) ListAssets(ctx context.Context,
"and include_leased")
}

var assetSpecifier *asset.Specifier

if req.GroupKey != nil {
groupKey, err := btcec.ParsePubKey(req.GroupKey[:])
if err != nil {
return nil, fmt.Errorf("error parsing group key: %w",
err)
}

// Construct an asset specifier using the requested group key
groupSpecifier, err := asset.NewSpecifier(
nil, groupKey, nil, false,
)
if err != nil {
return nil, fmt.Errorf(
"error creating asset specifier: %w",
err)
}

assetSpecifier = &groupSpecifier
}

constraints := tapfreighter.CommitmentConstraints{
AssetSpecifier: *assetSpecifier,
MinAmt: req.MinAmount,
MaxAmt: req.MaxAmount,
CoinSelectType: tapsend.ScriptTreesAllowed,
}

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

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

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

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

assets, err := r.cfg.AssetStore.FetchAllAssets(
ctx, includeSpent, includeLeased, nil,
ctx, includeSpent, includeLeased, queryFilters,
)
if err != nil {
return nil, fmt.Errorf("unable to read chain assets: %w", err)
Expand Down Expand Up @@ -1178,7 +1215,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, nil,
)

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

0 comments on commit f5d1985

Please sign in to comment.