| 43 | |
| 44 | |
| 45 | uint256 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 | |
| 65 | uint256 BlockMerkleRoot(const CBlock& block, bool* mutated) |