19 std::vector<bool> vMatch;
20 std::vector<uint256> vHashes;
22 vMatch.reserve(block.
vtx.size());
23 vHashes.reserve(block.
vtx.size());
25 for (
unsigned int i = 0; i < block.
vtx.size(); i++)
28 if (txids && txids->count(hash)) {
29 vMatch.push_back(
true);
31 vMatch.push_back(
true);
34 vMatch.push_back(
false);
36 vHashes.push_back(hash);
45 assert(vTxid.size() != 0);
51 uint256 left = CalcHash(height-1, pos*2, vTxid), right;
53 if (pos*2+1 < CalcTreeWidth(height-1))
54 right = CalcHash(height-1, pos*2+1, vTxid);
64 bool fParentOfMatch =
false;
65 for (
unsigned int p = pos << height; p < (pos+1) << height && p < nTransactions; p++)
66 fParentOfMatch |= vMatch[p];
68 vBits.push_back(fParentOfMatch);
69 if (height==0 || !fParentOfMatch) {
71 vHash.push_back(CalcHash(height, pos, vTxid));
74 TraverseAndBuild(height-1, pos*2, vTxid, vMatch);
75 if (pos*2+1 < CalcTreeWidth(height-1))
76 TraverseAndBuild(height-1, pos*2+1, vTxid, vMatch);
81 if (nBitsUsed >= vBits.size()) {
86 bool fParentOfMatch = vBits[nBitsUsed++];
87 if (height==0 || !fParentOfMatch) {
89 if (nHashUsed >= vHash.size()) {
94 const uint256 &hash = vHash[nHashUsed++];
95 if (height==0 && fParentOfMatch) {
96 vMatch.push_back(hash);
97 vnIndex.push_back(pos);
102 uint256 left = TraverseAndExtract(height-1, pos*2, nBitsUsed, nHashUsed, vMatch, vnIndex), right;
103 if (pos*2+1 < CalcTreeWidth(height-1)) {
104 right = TraverseAndExtract(height-1, pos*2+1, nBitsUsed, nHashUsed, vMatch, vnIndex);
153 unsigned int nBitsUsed = 0, nHashUsed = 0;
159 if ((nBitsUsed+7)/8 != (
vBits.size()+7)/8)
162 if (nHashUsed !=
vHash.size())
164 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
unsigned int GetMaxBlockWeight()
bool IsRelevantAndUpdate(const CTransaction &tx)
Also adds any outputs which match the filter to the filter (to match their spending txes) ...
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.
#define BEGIN(a)
Utilities for converting data from/to strings.
std::vector< uint256 > vHash
txids and internal hashes
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
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) ...