Changeset View
Changeset View
Standalone View
Standalone View
src/merkleblock.h
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | public: | ||||
* their respective indices within the partial tree. Returns the merkle | * their respective indices within the partial tree. Returns the merkle | ||||
* root, or 0 in case of failure. | * root, or 0 in case of failure. | ||||
*/ | */ | ||||
uint256 ExtractMatches(std::vector<uint256> &vMatch, | uint256 ExtractMatches(std::vector<uint256> &vMatch, | ||||
std::vector<unsigned int> &vnIndex); | std::vector<unsigned int> &vnIndex); | ||||
}; | }; | ||||
/** | /** | ||||
* Used to relay blocks as header + vector<merkle branch> | * Used to create a Merkle proof (usually from a subset of transactions), | ||||
* to filtered nodes. | * which consists of a block header and partial Merkle Tree. | ||||
* SPV clients typically use this Merkle proof to limit bandwidth and | |||||
* computation requirements to process incoming transactions. | |||||
* From the peer-node's perspective, the SPV client is a "filtered node". | |||||
* See BIP37 for details: | |||||
* https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki | |||||
*/ | */ | ||||
class CMerkleBlock { | class CMerkleBlock { | ||||
public: | public: | ||||
/** Public only for unit testing */ | /** Public only for unit testing */ | ||||
CBlockHeader header; | CBlockHeader header; | ||||
CPartialMerkleTree txn; | CPartialMerkleTree txn; | ||||
public: | |||||
/** Public only for unit testing and relay testing (not relayed) */ | /** Public only for unit testing and relay testing (not relayed) */ | ||||
std::vector<std::pair<unsigned int, uint256>> vMatchedTxn; | std::vector<std::pair<unsigned int, uint256>> vMatchedTxn; | ||||
/** | /** | ||||
* Create from a CBlock, filtering transactions according to filter. Note | * Create a Merkle proof according to a bloom filter. Note | ||||
* that this will call IsRelevantAndUpdate on the filter for each | * that this will call IsRelevantAndUpdate on the filter for each | ||||
* transaction, thus the filter will likely be modified. | * transaction, thus the filter will likely be modified. | ||||
*/ | */ | ||||
CMerkleBlock(const CBlock &block, CBloomFilter &filter); | CMerkleBlock(const CBlock &block, CBloomFilter &filter); | ||||
// Create from a CBlock, matching the txids in the set. | /** | ||||
* Create a Merkle proof for a set of transactions. | |||||
*/ | |||||
CMerkleBlock(const CBlock &block, const std::set<TxId> &txids); | CMerkleBlock(const CBlock &block, const std::set<TxId> &txids); | ||||
CMerkleBlock() {} | CMerkleBlock() {} | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(header); | READWRITE(header); | ||||
READWRITE(txn); | READWRITE(txn); | ||||
} | } | ||||
}; | }; | ||||
#endif // BITCOIN_MERKLEBLOCK_H | #endif // BITCOIN_MERKLEBLOCK_H |