Skip to content

Commit f081d59

Browse files
committed
cmd+rpcserver+taprpc: filter unconfirmed assets by default
By default, we only want to show assets in the asset list that are ready to be spent. So we don't want to include not yet confirmed freshly minted assets (those are the only assets that are materialized in the asset table while not being confirmed yet). We add a new RPC and CLI flag that allows the user to show the assets on explicit request.
1 parent e4148fd commit f081d59

File tree

6 files changed

+947
-851
lines changed

6 files changed

+947
-851
lines changed

cmd/tapcli/assets.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var (
4747
assetGroupedAssetName = "grouped_asset"
4848
assetShowWitnessName = "show_witness"
4949
assetShowSpentName = "show_spent"
50+
assetShowUnconfMintsName = "show_unconfirmed_mints"
5051
assetGroupKeyName = "group_key"
5152
assetGroupAnchorName = "group_anchor"
5253
batchKeyName = "batch_key"
@@ -554,6 +555,11 @@ var listAssetsCommand = cli.Command{
554555
Name: assetShowSpentName,
555556
Usage: "include fully spent assets in the list",
556557
},
558+
cli.BoolFlag{
559+
Name: assetShowUnconfMintsName,
560+
Usage: "include freshly minted and not yet confirmed " +
561+
"assets in the list",
562+
},
557563
},
558564
Action: listAssets,
559565
}
@@ -566,8 +572,9 @@ func listAssets(ctx *cli.Context) error {
566572
// TODO(roasbeef): need to reverse txid
567573

568574
resp, err := client.ListAssets(ctxc, &taprpc.ListAssetRequest{
569-
WithWitness: ctx.Bool(assetShowWitnessName),
570-
IncludeSpent: ctx.Bool(assetShowSpentName),
575+
WithWitness: ctx.Bool(assetShowWitnessName),
576+
IncludeSpent: ctx.Bool(assetShowSpentName),
577+
IncludeUnconfirmedMints: ctx.Bool(assetShowUnconfMintsName),
571578
})
572579
if err != nil {
573580
return fmt.Errorf("unable to list assets: %w", err)

itest/utils.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ func FinalizeBatchUnconfirmed(t *testing.T, minerClient *rpcclient.Client,
358358
// Make sure the assets were all minted within the same anchor but don't
359359
// yet have a block hash associated with them.
360360
listRespUnconfirmed, err := tapClient.ListAssets(
361-
ctxt, &taprpc.ListAssetRequest{},
361+
ctxt, &taprpc.ListAssetRequest{
362+
IncludeUnconfirmedMints: true,
363+
},
362364
)
363365
require.NoError(t, err)
364366

rpcserver.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,37 @@ func (r *rpcServer) ListAssets(ctx context.Context,
975975
return nil, err
976976
}
977977

978+
var (
979+
filteredAssets []*taprpc.Asset
980+
unconfirmedMints uint64
981+
)
982+
983+
// We now count and filter the assets according to the
984+
// IncludeUnconfirmedMints flag.
985+
//
986+
// TODO(guggero): Do this on the SQL level once we add pagination to the
987+
// asset list query, as this will no longer work with pagination.
988+
for idx := range rpcAssets {
989+
switch {
990+
// If the asset isn't confirmed yet, we count it but only
991+
// include it in the output list if the client requested it.
992+
case rpcAssets[idx].ChainAnchor.BlockHeight == 0:
993+
unconfirmedMints++
994+
995+
if req.IncludeUnconfirmedMints {
996+
filteredAssets = append(
997+
filteredAssets, rpcAssets[idx],
998+
)
999+
}
1000+
1001+
// Don't filter out confirmed assets.
1002+
default:
1003+
filteredAssets = append(
1004+
filteredAssets, rpcAssets[idx],
1005+
)
1006+
}
1007+
}
1008+
9781009
// We will also report the number of unconfirmed transfers. This is
9791010
// useful for clients as unconfirmed asset coins are not included in the
9801011
// asset list.
@@ -985,8 +1016,9 @@ func (r *rpcServer) ListAssets(ctx context.Context,
9851016
}
9861017

9871018
return &taprpc.ListAssetResponse{
988-
Assets: rpcAssets,
1019+
Assets: filteredAssets,
9891020
UnconfirmedTransfers: uint64(len(outboundParcels)),
1021+
UnconfirmedMints: unconfirmedMints,
9901022
}, nil
9911023
}
9921024

0 commit comments

Comments
 (0)