Skip to content

Commit

Permalink
rpc: add ChainHash message with both bytes and string representations
Browse files Browse the repository at this point in the history
This commit introduces the `ChainHash` RPC message, which contains two
fields:
- A raw byte representation of the hash, ideal for direct use in
  Go RPC calls.
- A byte-reversed hexadecimal string representation of the hash,
  convenient for users who need to copy and paste the value, such as
  when passing it as a command-line argument.
  • Loading branch information
ffranr committed Aug 15, 2024
1 parent 8fcd27c commit 139669b
Show file tree
Hide file tree
Showing 5 changed files with 1,066 additions and 921 deletions.
11 changes: 7 additions & 4 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3387,18 +3387,21 @@ func marshalOutboundParcel(

anchorTxHash := parcel.AnchorTx.TxHash()

// Marshal the anchor tx block hash.
var anchorTxBlockHashBytes []byte
// Marshal the anchor tx block hash into its RPC counterpart.
var anchorTxBlockHash *taprpc.ChainHash
parcel.AnchorTxBlockHash.WhenSome(func(hash chainhash.Hash) {
anchorTxBlockHashBytes = hash[:]
anchorTxBlockHash = &taprpc.ChainHash{
Hash: hash[:],
HashStr: hash.String(),
}
})

return &taprpc.AssetTransfer{
TransferTimestamp: parcel.TransferTime.Unix(),
AnchorTxHash: anchorTxHash[:],
AnchorTxHeightHint: parcel.AnchorTxHeightHint,
AnchorTxChainFees: parcel.ChainFees,
AnchorTxBlockHash: anchorTxBlockHashBytes,
AnchorTxBlockHash: anchorTxBlockHash,
Inputs: rpcInputs,
Outputs: rpcOutputs,
}, nil
Expand Down
20 changes: 17 additions & 3 deletions taprpc/assetwalletrpc/assetwallet.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,8 @@
"description": "Describes the set of newly created asset outputs."
},
"anchor_tx_block_hash": {
"type": "string",
"format": "byte",
"description": "The block hash the contains the anchor transaction above. If unset, the\nanchor transaction is unconfirmed."
"$ref": "#/definitions/taprpcChainHash",
"description": "The block hash of the blockchain block that contains the anchor\ntransaction. If this value is unset, the anchor transaction is\nunconfirmed."
}
}
},
Expand All @@ -910,6 +909,21 @@
"default": "ASSET_VERSION_V0",
"description": " - ASSET_VERSION_V0: ASSET_VERSION_V0 is the default asset version. This version will include\nthe witness vector in the leaf for a tap commitment.\n - ASSET_VERSION_V1: ASSET_VERSION_V1 is the asset version that leaves out the witness vector\nfrom the MS-SMT leaf encoding."
},
"taprpcChainHash": {
"type": "object",
"properties": {
"hash": {
"type": "string",
"format": "byte",
"description": "The raw hash value in byte format.\n\nThis format is optimized for programmatic use, particularly for Go\ndevelopers, enabling easy integration with other RPC calls or binary\noperations."
},
"hash_str": {
"type": "string",
"description": "The byte-reversed hash value as a hexadecimal string.\n\nThis format is intended for human interaction, making it easy to copy,\npaste, and use in contexts like command-line arguments or configuration\nfiles."
}
},
"description": "ChainHash represents a hash value, typically a double SHA-256 of some data.\nCommon examples include block hashes and transaction hashes.\n\nThis versatile message type is used in various Bitcoin-related messages and\nstructures, providing two different formats of the same hash to accommodate\nboth developer and user needs."
},
"taprpcKeyDescriptor": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit 139669b

Please sign in to comment.