Whats the distinction between “txid” and “hash” – getrawtransaction bitcoind

0
20
Whats the distinction between “txid” and “hash” – getrawtransaction bitcoind


Abstract: The distinction is when the tx is a segwit tx, the calculation of txid doesn’t embrace the witness information, whereas the hash does.

The definition of transaction hash stays the identical as txid for non-witness transactions (non Segwit). The rationale the mainnet tx has a special hash than the txid is as a result of it’s a witness transaction. When you run bitcoin-cli assist getrawtransaction it would present you:

End result (if verbose is ready to true):
{
  ...
  "txid" : "id",        (string) The transaction id (similar as supplied)
  "hash" : "id",        (string) The transaction hash (differs from txid for witness transactions)
  ...

Segregated Witness

The next is from BIP 141.

Notice that the BIP states, “signature information is now not a part of the transaction hash.”

Transaction ID

A brand new information construction, witness, is outlined. Every transaction could have 2 IDs.

Definition of txid stays unchanged: the double SHA256 of the standard serialization format:

[nVersion][txins][txouts][nLockTime]

A brand new wtxid is outlined: the double SHA256 of the brand new serialization with witness information:

[nVersion][marker][flag][txins][txouts][witness][nLockTime]

Format of nVersion, txins, txouts, and nLockTime are similar as conventional serialization.

The marker MUST be a 1-byte zero worth: 0x00.

The flag MUST be a 1-byte non-zero worth. At present, 0x01 MUST be used.

The witness is a serialization of all witness information of the transaction. Every txin is related to a witness subject. A witness subject begins with a var_int to point the variety of stack objects for the txin. It’s adopted by stack objects, with every merchandise begins with a var_int to point the size. Witness information is NOT script.

A non-witness program (outlined hereinafter) txin MUST be related to an empty witness subject, represented by a 0x00. If all txins will not be witness program, a transaction’s wtxid is the same as its txid.

LEAVE A REPLY

Please enter your comment!
Please enter your name here