MCPcopy Create free account
hub / github.com/ElementsProject/elements / ComputeMerkleRoot

Function ComputeMerkleRoot

src/consensus/merkle.cpp:45–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43
44
45uint256 ComputeMerkleRoot(std::vector<uint256> hashes, bool* mutated) {
46 bool mutation = false;
47 while (hashes.size() > 1) {
48 if (mutated) {
49 for (size_t pos = 0; pos + 1 < hashes.size(); pos += 2) {
50 if (hashes[pos] == hashes[pos + 1]) mutation = true;
51 }
52 }
53 if (hashes.size() & 1) {
54 hashes.push_back(hashes.back());
55 }
56 SHA256D64(hashes[0].begin(), hashes[0].begin(), hashes.size() / 2);
57 hashes.resize(hashes.size() / 2);
58 }
59 if (mutated) *mutated = mutation;
60 if (hashes.size() == 0) return uint256();
61 return hashes[0];
62}
63
64
65uint256 BlockMerkleRoot(const CBlock& block, bool* mutated)

Callers 6

BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
MerkleRootFunction · 0.85
BlockMerkleRootFunction · 0.85
BlockWitnessMerkleRootFunction · 0.85

Calls 6

SHA256D64Function · 0.85
uint256Class · 0.50
sizeMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
resizeMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68