16 std::vector<bool> vMatch;
17 std::vector<uint256> vHashes;
19 vMatch.reserve(block.
vtx.size());
20 vHashes.reserve(block.
vtx.size());
22 for (
unsigned int i = 0; i < block.
vtx.size(); i++)
27 vMatch.push_back(
true);
31 vMatch.push_back(
false);
32 vHashes.push_back(hash);
42 std::vector<bool> vMatch;
43 std::vector<uint256> vHashes;
45 vMatch.reserve(block.
vtx.size());
46 vHashes.reserve(block.
vtx.size());
48 for (
unsigned int i = 0; i < block.
vtx.size(); i++)
51 if (txids.count(hash))
52 vMatch.push_back(
true);
54 vMatch.push_back(
false);
55 vHashes.push_back(hash);
70 uint256 left = CalcHash(height-1, pos*2, vTxid), right;
72 if (pos*2+1 < CalcTreeWidth(height-1))
73 right = CalcHash(height-1, pos*2+1, vTxid);
83 bool fParentOfMatch =
false;
84 for (
unsigned int p = pos << height; p < (pos+1) << height && p < nTransactions; p++)
85 fParentOfMatch |= vMatch[p];
87 vBits.push_back(fParentOfMatch);
88 if (height==0 || !fParentOfMatch) {
90 vHash.push_back(CalcHash(height, pos, vTxid));
93 TraverseAndBuild(height-1, pos*2, vTxid, vMatch);
94 if (pos*2+1 < CalcTreeWidth(height-1))
95 TraverseAndBuild(height-1, pos*2+1, vTxid, vMatch);
100 if (nBitsUsed >= vBits.size()) {
105 bool fParentOfMatch = vBits[nBitsUsed++];
106 if (height==0 || !fParentOfMatch) {
108 if (nHashUsed >= vHash.size()) {
113 const uint256 &hash = vHash[nHashUsed++];
114 if (height==0 && fParentOfMatch) {
115 vMatch.push_back(hash);
116 vnIndex.push_back(pos);
121 uint256 left = TraverseAndExtract(height-1, pos*2, nBitsUsed, nHashUsed, vMatch, vnIndex), right;
122 if (pos*2+1 < CalcTreeWidth(height-1)) {
123 right = TraverseAndExtract(height-1, pos*2+1, nBitsUsed, nHashUsed, vMatch, vnIndex);
173 unsigned int nBitsUsed = 0, nHashUsed = 0;
179 if ((nBitsUsed+7)/8 != (
vBits.size()+7)/8)
182 if (nHashUsed !=
vHash.size())
184 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 ...
unsigned int nTransactions
the total number of transactions in the block
bool fBad
flag set when encountering invalid data
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...
assert(len-trim+(2 *lenIndices)<=WIDTH)
Data structure that represents a partial merkle tree.
unsigned int dgpMaxBlockSize
#define BEGIN(a)
Utilities for converting data from/to strings.
std::vector< uint256 > vHash
txids and internal hashes
unsigned int CalcTreeWidth(int height)
helper function to efficiently calculate the number of nodes at given height in the merkle tree ...
CBlockHeader GetBlockHeader() const
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...
uint8_t const size_t const size
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) ...