Changeset View
Changeset View
Standalone View
Standalone View
src/merkleblock.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | uint256 CPartialMerkleTree::CalcHash(int height, size_t pos, | ||||
// otherwise. | // otherwise. | ||||
if (pos * 2 + 1 < CalcTreeWidth(height - 1)) { | if (pos * 2 + 1 < CalcTreeWidth(height - 1)) { | ||||
right = CalcHash(height - 1, pos * 2 + 1, vTxid); | right = CalcHash(height - 1, pos * 2 + 1, vTxid); | ||||
} else { | } else { | ||||
right = left; | right = left; | ||||
} | } | ||||
// Combine subhashes. | // Combine subhashes. | ||||
return Hash(left.begin(), left.end(), right.begin(), right.end()); | return Hash(left, right); | ||||
} | } | ||||
void CPartialMerkleTree::TraverseAndBuild(int height, size_t pos, | void CPartialMerkleTree::TraverseAndBuild(int height, size_t pos, | ||||
const std::vector<uint256> &vTxid, | const std::vector<uint256> &vTxid, | ||||
const std::vector<bool> &vMatch) { | const std::vector<bool> &vMatch) { | ||||
// Determine whether this node is the parent of at least one matched txid. | // Determine whether this node is the parent of at least one matched txid. | ||||
bool fParentOfMatch = false; | bool fParentOfMatch = false; | ||||
for (size_t p = pos << height; p < (pos + 1) << height && p < nTransactions; | for (size_t p = pos << height; p < (pos + 1) << height && p < nTransactions; | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if (pos * 2 + 1 < CalcTreeWidth(height - 1)) { | ||||
// transaction hashes covered by them must each be unique. | // transaction hashes covered by them must each be unique. | ||||
fBad = true; | fBad = true; | ||||
} | } | ||||
} else { | } else { | ||||
right = left; | right = left; | ||||
} | } | ||||
// and combine them before returning. | // and combine them before returning. | ||||
return Hash(left.begin(), left.end(), right.begin(), right.end()); | return Hash(left, right); | ||||
} | } | ||||
CPartialMerkleTree::CPartialMerkleTree(const std::vector<uint256> &vTxid, | CPartialMerkleTree::CPartialMerkleTree(const std::vector<uint256> &vTxid, | ||||
const std::vector<bool> &vMatch) | const std::vector<bool> &vMatch) | ||||
: nTransactions(vTxid.size()), fBad(false) { | : nTransactions(vTxid.size()), fBad(false) { | ||||
// reset state | // reset state | ||||
vBits.clear(); | vBits.clear(); | ||||
vHash.clear(); | vHash.clear(); | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |