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 20, 2024
1 parent cf67d1f commit 850c549
Show file tree
Hide file tree
Showing 4 changed files with 1,241 additions and 1,027 deletions.
66 changes: 63 additions & 3 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,65 @@ func (r *rpcServer) ListAssets(ctx context.Context,
"and include_leased")
}

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

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)
}

constraints.AssetSpecifier = groupSpecifier
}

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

if req.ScriptKey != nil {
scriptKey, err := taprpc.UnmarshalScriptKey(req.ScriptKey)
if err != nil {
return nil, fmt.Errorf("unable to decode script key: "+
"%w", err)
}

filters.ScriptKey = scriptKey
}

if req.AnchorOutpoint != nil {
txid, err := chainhash.NewHash(req.AnchorOutpoint.Txid)
if err != nil {
return nil, fmt.Errorf("error parsing outpoint: %w",
err)
}
outPoint := &wire.OutPoint{
Hash: *txid,
Index: req.AnchorOutpoint.OutputIndex,
}

filters.AnchorPoint = outPoint
}

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

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1024,10 +1080,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 +1235,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 850c549

Please sign in to comment.