Edit: Take a look at MSG_MERKLEBLOCK. Included data is: Block Header
, Transaction Rely
, Hash Rely
, hashes
, flag byte depend
, and flags
.
hashes
embrace all the things from the leaf to root, and flags
provides the positions of the leaf within the Merkle tree.
For the reason that index of the transaction provides it’s place from the left among the many leaves within the Merkle Tree, along with the transaction depend it’s enough to infer whether or not it’s the left or proper accomplice in every concatenation.
(Outdated reply under.)
The leaves of the Merkle tree are left to proper in the identical order because the transaction checklist of the block. Every layer above is shaped by concatenating the kids after which performing advert double SHA-256. When solely a single entry is left in a layer, we name that the Merkle root.
If a transaction doesn’t have a accomplice, it’s paired with itself as a substitute.
HASH(Hash(AB)Hash(CC))
/
Hash(AB) HASH(CC)
/ /
A B C -
Legend: A,B,C are txid; Hash is brief for SHA-256d.
Which means that every transaction’s place within the tree is totally outlined simply by it’s index within the transaction checklist. Due to this fact, the place of its companions on every layer is deductible from that alone: For those who write the transaction indices (beginning to depend with 0) out in Binary, you get the next:
A: 00
B: 01
C: 10
Studying from again to entrance, every 1
stands for “proper place” and every 0
stands for “left place”.
Instance: B(01)
, B
’s final place is 1
and B is the proper accomplice to A
. B
’s second to final place is 0
and HASH(AB) is the left accomplice to HASH(CC).
Due to this fact it’s enough so as to add the index within the transaction checklist and the variety of transactions within the block to your proposed “Leaf, Root, Nodes”.
Sadly, I don’t know what commonplace is getting used to switch this data. Perhaps you’ll find it within the Bitcoin Core code catering to the requests of the SPV purchasers polling nodes for data.