Skip to content

Commit 500f80d

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 396fe9e commit 500f80d

File tree

5 files changed

+941
-850
lines changed

5 files changed

+941
-850
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)

rpcserver.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,34 @@ 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+
for idx := range rpcAssets {
986+
switch {
987+
// If the asset isn't confirmed yet, we count it but only
988+
// include it in the output list if the client requested it.
989+
case rpcAssets[idx].ChainAnchor.BlockHeight == 0:
990+
unconfirmedMints++
991+
992+
if req.IncludeUnconfirmedMints {
993+
filteredAssets = append(
994+
filteredAssets, rpcAssets[idx],
995+
)
996+
}
997+
998+
// Don't filter out confirmed assets.
999+
default:
1000+
filteredAssets = append(
1001+
filteredAssets, rpcAssets[idx],
1002+
)
1003+
}
1004+
}
1005+
9781006
// We will also report the number of unconfirmed transfers. This is
9791007
// useful for clients as unconfirmed asset coins are not included in the
9801008
// asset list.
@@ -985,8 +1013,9 @@ func (r *rpcServer) ListAssets(ctx context.Context,
9851013
}
9861014

9871015
return &taprpc.ListAssetResponse{
988-
Assets: rpcAssets,
1016+
Assets: filteredAssets,
9891017
UnconfirmedTransfers: uint64(len(outboundParcels)),
1018+
UnconfirmedMints: unconfirmedMints,
9901019
}, nil
9911020
}
9921021

0 commit comments

Comments
 (0)