Skip to content

Commit

Permalink
cmd: add listburns command
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeTsagk committed Nov 26, 2024
1 parent a21e4eb commit e9364e0
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions cmd/tapcli/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var assetsCommands = []cli.Command{
listAssetBalancesCommand,
sendAssetsCommand,
burnAssetsCommand,
listBurnsCommand,
listTransfersCommand,
fetchMetaCommand,
},
Expand All @@ -52,6 +53,7 @@ var (
assetShowUnconfMintsName = "show_unconfirmed_mints"
assetGroupKeyName = "group_key"
assetGroupAnchorName = "group_anchor"
anchorTxidName = "anchor_txid"
batchKeyName = "batch_key"
groupByGroupName = "by_group"
assetIDName = "asset_id"
Expand Down Expand Up @@ -858,6 +860,71 @@ func burnAssets(ctx *cli.Context) error {
return nil
}

var listBurnsCommand = cli.Command{
Name: "listburns",
Usage: "list burnt assets",
Description: `
List assets that have been burned by this daemon. These are assets that
have been destroyed and are no longer spendable.
Some filters may be used to return more specific results.
`,
Flags: []cli.Flag{
cli.StringFlag{
Name: assetIDName,
Usage: "the asset ID of the burnt asset",
},
cli.StringFlag{
Name: assetGroupKeyName,
Usage: "the group key of the burnt asset",
},
cli.StringFlag{
Name: anchorTxidName,
Usage: "the txid of the transaction the burn was " +
"anchored to",
},
},
Action: listBurns,
}

func listBurns(ctx *cli.Context) error {
assetIDHex := ctx.String(assetIDName)
assetIDBytes, err := hex.DecodeString(assetIDHex)
if err != nil {
return fmt.Errorf("invalid asset ID: %w", err)
}

groupKeyHex := ctx.String(assetGroupKeyName)
groupKeyBytes, err := hex.DecodeString(groupKeyHex)
if err != nil {
return fmt.Errorf("invalid group key: %w", err)
}

anchorTxidStr := ctx.String(anchorTxidName)
anchorTxid, err := hex.DecodeString(anchorTxidStr)
if err != nil {
return fmt.Errorf("invalid anchor txid: %w", err)
}

ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()

resp, err := client.ListBurns(
ctxc, &taprpc.ListBurnsRequest{
AssetId: assetIDBytes,
TweakedGroupKey: groupKeyBytes,
AnchorTxid: anchorTxid,
},
)
if err != nil {
return fmt.Errorf("could not list burns: %w", err)
}

printRespJSON(resp)
return nil
}

var listTransfersCommand = cli.Command{
Name: "transfers",
ShortName: "t",
Expand Down

0 comments on commit e9364e0

Please sign in to comment.