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 13, 2024
1 parent b9c8ce7 commit 7f7febe
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: %v", err)

Check failure on line 894 in cmd/tapcli/assets.go

View workflow job for this annotation

GitHub Actions / Lint check

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}

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

Check failure on line 900 in cmd/tapcli/assets.go

View workflow job for this annotation

GitHub Actions / Lint check

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}

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

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: %v", err)

Check failure on line 921 in cmd/tapcli/assets.go

View workflow job for this annotation

GitHub Actions / Lint check

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}

printRespJSON(resp)
return nil
}

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

0 comments on commit 7f7febe

Please sign in to comment.