Hi team, please provide some info or code (JS, rust, go) example about node calculate Tx Hash function. thx
Our node is written partly in Rust and Haskell. This part of the haskell code base calculates the transaction hash:
The transaction hash is just the SHA256 hash of the serialized transaction.
In Rust, the SDK provides BlockItem::hash()
for computing the hash.
so, just want to confirm, it’s all AccountTransaction
info to serialize and then sha256 to get? There are no other steps. right? ( I refer to the version of Rust and will convert it to the version of Go
It’s the SHA256 hash of the serialized BlockItem
. There are several types of BlockItem
(AccountTransaction
being one of them) so there is a tag that distinguishes the type at the start. Explicitly the serialization format for an AccountTransaction
BlockItem
is:
type: 1 byte
0 for an AccountTransaction
transaction:
signature:
credential_count: 1 byte
the number of credentials signing the transaction
credential_signature: (repeated `credential_count` times)
the signatures for each account credential signing the transaction, in increasing order of index
credential index: 1 byte
the index of the credential on the account the signature is for
signature_count: 1 byte
the number of signatures present for this credential
key_signature: (repeated `signature_count` times)
the signatures for each credential key signing the transaction, in increasing order of index
key index: 1 byte
the index of the key on for the particular credential
signature_length: 2 bytes (big endian)
the length of the signature in bytes (currently always 64)
signature: `signature_length` bytes
the cryptographic signature
header:
sender: 32 bytes
the address of the account sending the transaction
nonce: 8 bytes (big endian)
the sequence number of the transaction
energy: 8 bytes (big endian)
the amount of energy dedicated to the transaction
payload_size: 8 bytes (big endian)
the size of the payload in bytes
expiry_time: 8 bytes (big endian)
the time (in seconds since the Unix epoch) after which the transaction can no longer be included in a new block
payload: `payload_size` bytes
the serialized transaction payload