7 #ifndef RAVEN_MERKLEBLOCK_H 8 #define RAVEN_MERKLEBLOCK_H 68 return (nTransactions+(1 << height)-1) >> height;
72 uint256 CalcHash(
int height,
unsigned int pos,
const std::vector<uint256> &vTxid);
75 void TraverseAndBuild(
int height,
unsigned int pos,
const std::vector<uint256> &vTxid,
const std::vector<bool> &vMatch);
81 uint256 TraverseAndExtract(
int height,
unsigned int pos,
unsigned int &nBitsUsed,
unsigned int &nHashUsed, std::vector<uint256> &vMatch, std::vector<unsigned int> &vnIndex);
88 template <
typename Stream,
typename Operation>
92 std::vector<unsigned char> vBytes;
93 if (ser_action.ForRead()) {
96 us.
vBits.resize(vBytes.size() * 8);
97 for (
unsigned int p = 0; p < us.
vBits.size(); p++)
98 us.
vBits[p] = (vBytes[p / 8] & (1 << (p % 8))) != 0;
101 vBytes.resize((vBits.size()+7)/8);
102 for (
unsigned int p = 0; p < vBits.size(); p++)
103 vBytes[p / 8] |= vBits[p] << (p % 8);
109 CPartialMerkleTree(
const std::vector<uint256> &vTxid,
const std::vector<bool> &vMatch);
157 template <
typename Stream,
typename Operation>
168 #endif // RAVEN_MERKLEBLOCK_H 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 ...
void SerializationOp(Stream &s, Operation ser_action)
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.
std::vector< uint256 > vHash
txids and internal hashes
Used to relay blocks as header + vector<merkle branch> to filtered nodes.
ADD_SERIALIZE_METHODS
serialization implementation
std::vector< bool > vBits
node-is-parent-of-matched-txid bits
CMerkleBlock(const CBlock &block, const std::set< uint256 > &txids)
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).
CMerkleBlock(const CBlock &block, CBloomFilter &filter)
Create from a CBlock, filtering transactions according to filter Note that this will call IsRelevantA...
void SerializationOp(Stream &s, Operation ser_action)
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) ...