@@ -1010,7 +1010,7 @@ func (r *rpcServer) checkBalanceOverflow(ctx context.Context,
10101010 case assetID != nil :
10111011 // Retrieve the current asset balance.
10121012 balances , err := r .cfg .AssetStore .QueryBalancesByAsset (
1013- ctx , assetID , true ,
1013+ ctx , assetID , true , fn . None [asset. ScriptKeyType ](),
10141014 )
10151015 if err != nil {
10161016 return fmt .Errorf ("unable to query asset balance: %w" ,
@@ -1026,7 +1026,7 @@ func (r *rpcServer) checkBalanceOverflow(ctx context.Context,
10261026 case groupPubKey != nil :
10271027 // Retrieve the current balance of the group.
10281028 balances , err := r .cfg .AssetStore .QueryAssetBalancesByGroup (
1029- ctx , groupPubKey , true ,
1029+ ctx , groupPubKey , true , fn . None [asset. ScriptKeyType ](),
10301030 )
10311031 if err != nil {
10321032 return fmt .Errorf ("unable to query group balance: %w" ,
@@ -1105,9 +1105,18 @@ func (r *rpcServer) ListAssets(ctx context.Context,
11051105 filters .AnchorPoint = outPoint
11061106 }
11071107
1108+ scriptKeyType , includeSpent , err := taprpc .ParseScriptKeyTypeQuery (
1109+ req .ScriptKeyType ,
1110+ )
1111+ if err != nil {
1112+ return nil , fmt .Errorf ("unable to parse script key type " +
1113+ "query: %w" , err )
1114+ }
1115+ filters .ScriptKeyType = scriptKeyType
1116+
11081117 rpcAssets , err := r .fetchRpcAssets (
1109- ctx , req .WithWitness , req .IncludeSpent , req . IncludeLeased ,
1110- filters ,
1118+ ctx , req .WithWitness , req .IncludeSpent || includeSpent ,
1119+ req . IncludeLeased , filters ,
11111120 )
11121121
11131122 if err != nil {
@@ -1218,11 +1227,12 @@ func (r *rpcServer) MarshalChainAsset(ctx context.Context, a asset.ChainAsset,
12181227}
12191228
12201229func (r * rpcServer ) listBalancesByAsset (ctx context.Context ,
1221- assetID * asset.ID , includeLeased bool ) (* taprpc.ListBalancesResponse ,
1230+ assetID * asset.ID , includeLeased bool ,
1231+ skt fn.Option [asset.ScriptKeyType ]) (* taprpc.ListBalancesResponse ,
12221232 error ) {
12231233
12241234 balances , err := r .cfg .AssetStore .QueryBalancesByAsset (
1225- ctx , assetID , includeLeased ,
1235+ ctx , assetID , includeLeased , skt ,
12261236 )
12271237 if err != nil {
12281238 return nil , fmt .Errorf ("unable to list balances: %w" , err )
@@ -1253,11 +1263,12 @@ func (r *rpcServer) listBalancesByAsset(ctx context.Context,
12531263}
12541264
12551265func (r * rpcServer ) listBalancesByGroupKey (ctx context.Context ,
1256- groupKey * btcec.PublicKey ,
1257- includeLeased bool ) (* taprpc.ListBalancesResponse , error ) {
1266+ groupKey * btcec.PublicKey , includeLeased bool ,
1267+ skt fn.Option [asset.ScriptKeyType ]) (* taprpc.ListBalancesResponse ,
1268+ error ) {
12581269
12591270 balances , err := r .cfg .AssetStore .QueryAssetBalancesByGroup (
1260- ctx , groupKey , includeLeased ,
1271+ ctx , groupKey , includeLeased , skt ,
12611272 )
12621273 if err != nil {
12631274 return nil , fmt .Errorf ("unable to list balances: %w" , err )
@@ -1292,8 +1303,22 @@ func (r *rpcServer) listBalancesByGroupKey(ctx context.Context,
12921303func (r * rpcServer ) ListUtxos (ctx context.Context ,
12931304 req * taprpc.ListUtxosRequest ) (* taprpc.ListUtxosResponse , error ) {
12941305
1306+ scriptKeyType , includeSpent , err := taprpc .ParseScriptKeyTypeQuery (
1307+ req .ScriptKeyType ,
1308+ )
1309+ if err != nil {
1310+ return nil , fmt .Errorf ("unable to parse script key type " +
1311+ "query: %w" , err )
1312+ }
1313+
1314+ filters := & tapdb.AssetQueryFilters {
1315+ CommitmentConstraints : tapfreighter.CommitmentConstraints {
1316+ ScriptKeyType : scriptKeyType ,
1317+ },
1318+ }
1319+
12951320 rpcAssets , err := r .fetchRpcAssets (
1296- ctx , false , false , req .IncludeLeased , nil ,
1321+ ctx , false , includeSpent , req .IncludeLeased , filters ,
12971322 )
12981323 if err != nil {
12991324 return nil , err
@@ -1395,6 +1420,14 @@ func (r *rpcServer) ListGroups(ctx context.Context,
13951420func (r * rpcServer ) ListBalances (ctx context.Context ,
13961421 req * taprpc.ListBalancesRequest ) (* taprpc.ListBalancesResponse , error ) {
13971422
1423+ scriptKeyType , _ , err := taprpc .ParseScriptKeyTypeQuery (
1424+ req .ScriptKeyType ,
1425+ )
1426+ if err != nil {
1427+ return nil , fmt .Errorf ("unable to parse script key type " +
1428+ "query: %w" , err )
1429+ }
1430+
13981431 switch groupBy := req .GroupBy .(type ) {
13991432 case * taprpc.ListBalancesRequest_AssetId :
14001433 if ! groupBy .AssetId {
@@ -1411,7 +1444,9 @@ func (r *rpcServer) ListBalances(ctx context.Context,
14111444 copy (assetID [:], req .AssetFilter )
14121445 }
14131446
1414- return r .listBalancesByAsset (ctx , assetID , req .IncludeLeased )
1447+ return r .listBalancesByAsset (
1448+ ctx , assetID , req .IncludeLeased , scriptKeyType ,
1449+ )
14151450
14161451 case * taprpc.ListBalancesRequest_GroupKey :
14171452 if ! groupBy .GroupKey {
@@ -1429,7 +1464,7 @@ func (r *rpcServer) ListBalances(ctx context.Context,
14291464 }
14301465
14311466 return r .listBalancesByGroupKey (
1432- ctx , groupKey , req .IncludeLeased ,
1467+ ctx , groupKey , req .IncludeLeased , scriptKeyType ,
14331468 )
14341469
14351470 default :
0 commit comments