Skip to content

Commit 30da90d

Browse files
committed
Add CMerkleBlock constructor for tx set + block and an empty one
1 parent 734f80a commit 30da90d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/merkleblock.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter& filter)
3737
txn = CPartialMerkleTree(vHashes, vMatch);
3838
}
3939

40+
CMerkleBlock::CMerkleBlock(const CBlock& block, const std::set<uint256>& txids)
41+
{
42+
header = block.GetBlockHeader();
43+
44+
vector<bool> vMatch;
45+
vector<uint256> vHashes;
46+
47+
vMatch.reserve(block.vtx.size());
48+
vHashes.reserve(block.vtx.size());
49+
50+
for (unsigned int i = 0; i < block.vtx.size(); i++)
51+
{
52+
const uint256& hash = block.vtx[i].GetHash();
53+
if (txids.count(hash))
54+
vMatch.push_back(true);
55+
else
56+
vMatch.push_back(false);
57+
vHashes.push_back(hash);
58+
}
59+
60+
txn = CPartialMerkleTree(vHashes, vMatch);
61+
}
62+
4063
uint256 CPartialMerkleTree::CalcHash(int height, unsigned int pos, const std::vector<uint256> &vTxid) {
4164
if (height == 0) {
4265
// hash at height 0 is the txids themself

src/merkleblock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ class CMerkleBlock
139139
*/
140140
CMerkleBlock(const CBlock& block, CBloomFilter& filter);
141141

142+
// Create from a CBlock, matching the txids in the set
143+
CMerkleBlock(const CBlock& block, const std::set<uint256>& txids);
144+
145+
CMerkleBlock() {}
146+
142147
ADD_SERIALIZE_METHODS;
143148

144149
template <typename Stream, typename Operation>

0 commit comments

Comments
 (0)