Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2015-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_CONSENSUS_MERKLE_H6#define BITCOIN_CONSENSUS_MERKLE_H8#include <uint256.h>10#include <cstdint>11#include <vector>13class CBlock;15/**16* Compute a Merkle root from the provided leaf hashes.17* If non-null, `*mutated` is set to true if two identical hashes are paired at18* any tree level before the odd-count hash duplication step, and false otherwise.19*/20uint256 ComputeMerkleRoot(std::vector<uint256> hashes, bool* mutated = nullptr);22/*23* Compute the Merkle root of the transactions in a block.24* *mutated is set to true if a duplicated subtree was found.25*/26uint256 BlockMerkleRoot(const CBlock& block, bool* mutated = nullptr);28/*29* Compute the Merkle root of the witness transactions in a block.30*/31uint256 BlockWitnessMerkleRoot(const CBlock& block);33/**34* Compute merkle path to the specified transaction35*36* @param[in] block the block37* @param[in] position transaction for which to calculate the merkle path (0 is the coinbase)38*39* @return merkle path ordered from the deepest40*/41std::vector<uint256> TransactionMerklePath(const CBlock& block, uint32_t position);43#endif // BITCOIN_CONSENSUS_MERKLE_H