Changeset View
Changeset View
Standalone View
Standalone View
src/merkleblock.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | for (const auto &tx : block.vtx) { | ||||
vHashes.push_back(txid); | vHashes.push_back(txid); | ||||
} | } | ||||
txn = CPartialMerkleTree(vHashes, vMatch); | txn = CPartialMerkleTree(vHashes, vMatch); | ||||
} | } | ||||
uint256 CPartialMerkleTree::CalcHash(int height, unsigned int pos, | uint256 CPartialMerkleTree::CalcHash(int height, unsigned int pos, | ||||
const std::vector<uint256> &vTxid) { | const std::vector<uint256> &vTxid) { | ||||
// we can never have zero txs in a merkle block, we always need the | |||||
// coinbase tx if we do not have this assert, we can hit a memory | |||||
// access violation when indexing into vTxid | |||||
assert(vTxid.size() != 0); | |||||
if (height == 0) { | if (height == 0) { | ||||
// hash at height 0 is the txids themself. | // hash at height 0 is the txids themself. | ||||
return vTxid[pos]; | return vTxid[pos]; | ||||
} | } | ||||
// Calculate left hash. | // Calculate left hash. | ||||
uint256 left = CalcHash(height - 1, pos * 2, vTxid), right; | uint256 left = CalcHash(height - 1, pos * 2, vTxid), right; | ||||
// Calculate right hash if not beyond the end of the array - copy left hash | // Calculate right hash if not beyond the end of the array - copy left hash | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |