Crate bitcoin_merkle

source ·

Structs

  • | Used to relay blocks as header + vector<merkle | branch> to filtered nodes. | | ———– | @note | | The class assumes that the given CBlock | has at least 1 transaction. If the | CBlock has 0 txs, it will hit an assertion. |
  • | Data structure that represents a partial merkle | tree. | | It represents a subset of the txid’s of a known | block, in a way that allows recovery of the | list of txid’s and the merkle root, in an | authenticated way. | | The encoding works as follows: we traverse the | tree in depth-first order, storing a bit for | each traversed node, signifying whether the | node is the parent of at least one matched leaf | txid (or a matched txid itself). In case we are | at the leaf level, or this bit is 0, its merkle | node hash is stored, and its children are not | explored further. Otherwise, no hash is stored, | but we recurse into both (or the only) child | branch. During decoding, the same depth-first | traversal is performed, consuming bits and | hashes as they written during encoding. | | The serialization is fixed and provides a hard | guarantee about the encoded size: | | SIZE <= 10 + ceil(32.25N) | | Where N represents the number of leaf nodes of | the partial tree. N itself is bounded by: | | N <= total_transactions | N <= 1 + matched_transactionstree_height | | The serialization format: | | - uint32 total_transactions (4 bytes) | | - varint number of hashes (1-3 bytes) | | - uint256[] hashes in depth-first order (<= | 32N bytes) | | - varint number of bytes of flag bits (1-3 | bytes) | | - byte[] flag bits, packed per 8 in | a byte, least significant bit | first (<= 2N-1 bits) | | The size constraints follow from this.

Functions