Skip to content

Commit e98acfb

Browse files
authored
Merge pull request #1734 from bhandras/listassets-fixups
cmd: asset list to correctly filter on and display anchor txid
2 parents 88bb940 + c9b71df commit e98acfb

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

cmd/commands/assets.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,29 +1243,46 @@ var listTransfersCommand = cli.Command{
12431243
Name: "transfers",
12441244
ShortName: "t",
12451245
Usage: "list asset transfers",
1246-
Description: "list outgoing transfers of all assets or a selected " +
1247-
"asset",
1246+
Description: "list outgoing transfer for a specific anchor or if " +
1247+
"not set, all transfers",
12481248
Action: listTransfers,
12491249
Flags: []cli.Flag{
12501250
cli.StringFlag{
1251-
Name: assetIDName,
1252-
Usage: "A specific asset ID to list outgoing " +
1253-
"transfers for",
1251+
Name: anchorTxidName,
1252+
Usage: "A specific anchor transaction ID to run the " +
1253+
" transfer query against. If not set, all " +
1254+
" transfers will be returned.",
12541255
},
12551256
},
12561257
}
12571258

1259+
// reverseByteOrder reverses the byte order of the byte slice in place.
1260+
func reverseByteOrder(b []byte) {
1261+
for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
1262+
b[i], b[j] = b[j], b[i]
1263+
}
1264+
}
1265+
12581266
func listTransfers(ctx *cli.Context) error {
12591267
ctxc := getContext()
12601268
client, cleanUp := getClient(ctx)
12611269
defer cleanUp()
12621270

1263-
req := &taprpc.ListTransfersRequest{}
1271+
req := &taprpc.ListTransfersRequest{
1272+
AnchorTxid: ctx.String(anchorTxidName),
1273+
}
12641274
resp, err := client.ListTransfers(ctxc, req)
12651275
if err != nil {
12661276
return fmt.Errorf("unable to list asset transfers: %w", err)
12671277
}
12681278

1279+
// As the anchor TX hash is returned in a byte slice we need to reverse
1280+
// the byte order to match the expected hex format of string serialized
1281+
// transaction IDs.
1282+
for _, transfer := range resp.Transfers {
1283+
reverseByteOrder(transfer.AnchorTxHash)
1284+
}
1285+
12691286
printRespJSON(resp)
12701287
return nil
12711288
}

taprpc/assetwalletrpc/assetwallet.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@
950950
"anchor_tx_hash": {
951951
"type": "string",
952952
"format": "byte",
953-
"description": "The new transaction that commits to the set of Taproot Assets found\nat the above new anchor point."
953+
"description": "The new transaction that commits to the set of Taproot Assets found at\nthe above new anchor point. Note that this is in raw byte format, not\nthe reversed hex string format that is used for displayed txids. When\nlisting assets on the CLI we purposefully use the display format so it\nis easier to copy and paste into other tools."
954954
},
955955
"anchor_tx_height_hint": {
956956
"type": "integer",

taprpc/taprootassets.pb.go

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

taprpc/taprootassets.proto

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,11 @@ message AssetTransfer {
799799
// The timestamp of the transfer in UTC Unix time seconds.
800800
int64 transfer_timestamp = 1;
801801

802-
// The new transaction that commits to the set of Taproot Assets found
803-
// at the above new anchor point.
802+
// The new transaction that commits to the set of Taproot Assets found at
803+
// the above new anchor point. Note that this is in raw byte format, not
804+
// the reversed hex string format that is used for displayed txids. When
805+
// listing assets on the CLI we purposefully use the display format so it
806+
// is easier to copy and paste into other tools.
804807
bytes anchor_tx_hash = 2;
805808

806809
// The height hint of the anchor transaction. This is the height at which

taprpc/taprootassets.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@
16711671
"anchor_tx_hash": {
16721672
"type": "string",
16731673
"format": "byte",
1674-
"description": "The new transaction that commits to the set of Taproot Assets found\nat the above new anchor point."
1674+
"description": "The new transaction that commits to the set of Taproot Assets found at\nthe above new anchor point. Note that this is in raw byte format, not\nthe reversed hex string format that is used for displayed txids. When\nlisting assets on the CLI we purposefully use the display format so it\nis easier to copy and paste into other tools."
16751675
},
16761676
"anchor_tx_height_hint": {
16771677
"type": "integer",

0 commit comments

Comments
 (0)