Skip to content

Commit 74f32a4

Browse files
committed
cmd: asset list to correctly filter on and display anchor txid
1 parent 88bb940 commit 74f32a4

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
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
}

0 commit comments

Comments
 (0)