Older version of the merkle root computation code, for comparison.
| 128 | |
| 129 | // Older version of the merkle root computation code, for comparison. |
| 130 | static uint256 BlockBuildMerkleTree(const CBlock& block, bool* fMutated, std::vector<uint256>& vMerkleTree) |
| 131 | { |
| 132 | vMerkleTree.clear(); |
| 133 | vMerkleTree.reserve(block.vtx.size() * 2 + 16); // Safe upper bound for the number of total nodes. |
| 134 | for (std::vector<CTransactionRef>::const_iterator it(block.vtx.begin()); it != block.vtx.end(); ++it) |
| 135 | vMerkleTree.push_back((*it)->GetHash()); |
| 136 | int j = 0; |
| 137 | bool mutated = false; |
| 138 | for (int nSize = block.vtx.size(); nSize > 1; nSize = (nSize + 1) / 2) |
| 139 | { |
| 140 | for (int i = 0; i < nSize; i += 2) |
| 141 | { |
| 142 | int i2 = std::min(i+1, nSize-1); |
| 143 | if (i2 == i + 1 && i2 + 1 == nSize && vMerkleTree[j+i] == vMerkleTree[j+i2]) { |
| 144 | // Two identical hashes at the end of the list at a particular level. |
| 145 | mutated = true; |
| 146 | } |
| 147 | vMerkleTree.push_back(Hash(vMerkleTree[j+i], vMerkleTree[j+i2])); |
| 148 | } |
| 149 | j += nSize; |
| 150 | } |
| 151 | if (fMutated) { |
| 152 | *fMutated = mutated; |
| 153 | } |
| 154 | return (vMerkleTree.empty() ? uint256() : vMerkleTree.back()); |
| 155 | } |
| 156 | |
| 157 | // Older version of the merkle branch computation code, for comparison. |
| 158 | static std::vector<uint256> BlockGetMerkleBranch(const CBlock& block, const std::vector<uint256>& vMerkleTree, int nIndex) |