47 static void MerkleComputation(
const std::vector<uint256>& leaves,
uint256* proot,
bool* pmutated, uint32_t branchpos, std::vector<uint256>* pbranch) {
48 if (pbranch) pbranch->clear();
49 if (leaves.size() == 0) {
50 if (pmutated) *pmutated =
false;
66 while (count < leaves.size()) {
68 bool matchh = count == branchpos;
74 for (level = 0; !(count & (((uint32_t)1) << level)); level++) {
77 pbranch->push_back(inner[level]);
78 }
else if (matchlevel == level) {
79 pbranch->push_back(h);
83 mutated |= (inner[level] == h);
98 while (!(count & (((uint32_t)1) << level))) {
102 bool matchh = matchlevel == level;
103 while (count != (((uint32_t)1) << level)) {
107 if (pbranch && matchh) {
108 pbranch->push_back(h);
113 count += (((uint32_t)1) << level);
116 while (!(count & (((uint32_t)1) << level))) {
119 pbranch->push_back(inner[level]);
120 }
else if (matchlevel == level) {
121 pbranch->push_back(h);
130 if (pmutated) *pmutated = mutated;
131 if (proot) *proot = h;
136 MerkleComputation(leaves, &hash, mutated, -1,
nullptr);
141 std::vector<uint256> ret;
142 MerkleComputation(leaves,
nullptr,
nullptr, position, &ret);
148 for (std::vector<uint256>::const_iterator it = vMerkleBranch.begin(); it != vMerkleBranch.end(); ++it) {
161 std::vector<uint256> leaves;
162 leaves.resize(block.
vtx.size());
163 for (
size_t s = 0; s < block.
vtx.size(); s++) {
164 leaves[s] = block.
vtx[s]->GetHash();
171 std::vector<uint256> leaves;
172 leaves.resize(block.
vtx.size());
174 for (
size_t s = 1; s < block.
vtx.size(); s++) {
175 leaves[s] = block.
vtx[s]->GetWitnessHash();
182 std::vector<uint256> leaves;
183 leaves.resize(block.
vtx.size());
184 for (
size_t s = 0; s < block.
vtx.size(); s++) {
185 leaves[s] = block.
vtx[s]->GetHash();
CHash256 & Write(const unsigned char *data, size_t len)
std::vector< uint256 > BlockMerkleBranch(const CBlock &block, uint32_t position)
std::vector< uint256 > ComputeMerkleBranch(const std::vector< uint256 > &leaves, uint32_t position)
uint256 ComputeMerkleRootFromBranch(const uint256 &leaf, const std::vector< uint256 > &vMerkleBranch, uint32_t nIndex)
uint256 BlockWitnessMerkleRoot(const CBlock &block, bool *mutated)
A hasher class for Raven's 256-bit hash (double SHA-256).
uint256 ComputeMerkleRoot(const std::vector< uint256 > &leaves, bool *mutated)
#define BEGIN(a)
Utilities for converting data from/to strings.
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
std::vector< CTransactionRef > vtx