15 std::vector<unsigned char>
BitsToBytes(
const std::vector<bool>& bits)
17 std::vector<unsigned char> ret((bits.size() + 7) / 8);
18 for (
unsigned int p = 0; p < bits.size(); p++) {
19 ret[p / 8] |= bits[p] << (p % 8);
24 std::vector<bool>
BytesToBits(
const std::vector<unsigned char>& bytes)
26 std::vector<bool> ret(bytes.size() * 8);
27 for (
unsigned int p = 0; p < ret.size(); p++) {
28 ret[p] = (bytes[p / 8] & (1 << (p % 8))) != 0;
37 std::vector<bool> vMatch;
38 std::vector<uint256> vHashes;
40 vMatch.reserve(block.
vtx.size());
41 vHashes.reserve(block.
vtx.size());
43 for (
unsigned int i = 0; i < block.
vtx.size(); i++) {
45 if (txids && txids->count(hash)) {
46 vMatch.push_back(
true);
48 vMatch.push_back(
true);
51 vMatch.push_back(
false);
53 vHashes.push_back(hash);
69 right =
CalcHash(height - 1, pos * 2 + 1, vTxid);
80 bool fParentOfMatch =
false;
81 for (
unsigned int p = pos << height; p < (pos + 1) << height && p <
nTransactions; p++)
82 fParentOfMatch |= vMatch[p];
84 vBits.push_back(fParentOfMatch);
85 if (height == 0 || !fParentOfMatch) {
98 if (nBitsUsed >=
vBits.size()) {
103 bool fParentOfMatch =
vBits[nBitsUsed++];
104 if (height == 0 || !fParentOfMatch) {
106 if (nHashUsed >=
vHash.size()) {
112 if (height == 0 && fParentOfMatch)
113 vMatch.push_back(hash);
164 unsigned int nBitsUsed = 0, nHashUsed = 0;
170 if ((nBitsUsed + 7) / 8 != (
vBits.size() + 7) / 8)
173 if (nHashUsed !=
vHash.size())
175 return hashMerkleRoot;
std::vector< CTransactionRef > vtx
CBlockHeader GetBlockHeader() const
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
bool IsRelevantAndUpdate(const CTransaction &tx)
Also adds any outputs which match the filter to the filter (to match their spending txes)
CBlockHeader header
Public only for unit testing.
std::vector< std::pair< unsigned int, uint256 > > vMatchedTxn
Public only for unit testing and relay testing (not relayed).
Data structure that represents a partial merkle tree.
unsigned int nTransactions
the total number of transactions in the block
std::vector< bool > vBits
node-is-parent-of-matched-txid bits
bool fBad
flag set when encountering invalid data
uint256 ExtractMatches(std::vector< uint256 > &vMatch)
extract the matching txid's represented by this partial merkle tree.
uint256 TraverseAndExtract(int height, unsigned int pos, unsigned int &nBitsUsed, unsigned int &nHashUsed, std::vector< uint256 > &vMatch)
recursive function that traverses tree nodes, consuming the bits and hashes produced by TraverseAndBu...
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
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)
unsigned int CalcTreeWidth(int height)
helper function to efficiently calculate the number of nodes at given height in the merkle tree
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 > BytesToBits(const std::vector< unsigned char > &bytes)
std::vector< unsigned char > BitsToBytes(const std::vector< bool > &bits)
const uint256 UINT256_ZERO
constant uint256 instances
#define BEGIN(a)
Utilities for converting data from/to strings.