17 std::vector<bool> vMatch;
18 std::vector<uint256> vHashes;
20 vMatch.reserve(block.
vtx.size());
21 vHashes.reserve(block.
vtx.size());
23 for (
unsigned int i = 0; i < block.
vtx.size(); i++)
26 if (txids && txids->count(hash)) {
27 vMatch.push_back(
true);
29 vMatch.push_back(
true);
32 vMatch.push_back(
false);
34 vHashes.push_back(hash);
43 assert(vTxid.size() != 0);
52 right =
CalcHash(height-1, pos*2+1, vTxid);
62 bool fParentOfMatch =
false;
63 for (
unsigned int p = pos << height; p < (pos+1) << height && p <
nTransactions; p++)
64 fParentOfMatch |= vMatch[p];
66 vBits.push_back(fParentOfMatch);
67 if (height==0 || !fParentOfMatch) {
79 if (nBitsUsed >=
vBits.size()) {
84 bool fParentOfMatch =
vBits[nBitsUsed++];
85 if (height==0 || !fParentOfMatch) {
87 if (nHashUsed >=
vHash.size()) {
93 if (height==0 && fParentOfMatch) {
94 vMatch.push_back(hash);
95 vnIndex.push_back(pos);
138 if (
nTransactions > MAX_BLOCK_WEIGHT / MIN_TRANSACTION_WEIGHT)
151 unsigned int nBitsUsed = 0, nHashUsed = 0;
157 if ((nBitsUsed+7)/8 != (
vBits.size()+7)/8)
160 if (nHashUsed !=
vHash.size())
162 return hashMerkleRoot;
CBlockHeader header
Public only for unit testing.
uint256 ExtractMatches(std::vector< uint256 > &vMatch, std::vector< unsigned int > &vnIndex)
extract the matching txid's represented by this partial merkle tree and their respective indices with...
void TraverseAndBuild(int height, unsigned int pos, const std::vector< uint256 > &vTxid, const std::vector< bool > &vMatch)
recursive function that traverses tree nodes, storing the data as bits and hashes ...
CBlockHeader GetBlockHeader() const
unsigned int nTransactions
the total number of transactions in the block
bool fBad
flag set when encountering invalid data
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
unsigned int CalcTreeWidth(int height) const
helper function to efficiently calculate the number of nodes at given height in the merkle tree ...
Data structure that represents a partial merkle tree.
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
#define BEGIN(a)
Utilities for converting data from/to strings.
std::vector< uint256 > vHash
txids and internal hashes
std::vector< bool > vBits
node-is-parent-of-matched-txid bits
std::vector< CTransactionRef > vtx
uint256 TraverseAndExtract(int height, unsigned int pos, unsigned int &nBitsUsed, unsigned int &nHashUsed, std::vector< uint256 > &vMatch, std::vector< unsigned int > &vnIndex)
recursive function that traverses tree nodes, consuming the bits and hashes produced by TraverseAndBu...
std::vector< std::pair< unsigned int, uint256 > > vMatchedTxn
Public only for unit testing and relay testing (not relayed).
uint256 CalcHash(int height, unsigned int pos, const std::vector< uint256 > &vTxid)
calculate the hash of a node in the merkle tree (at leaf level: the txid's themselves) ...