aboutsummaryrefslogtreecommitdiff
path: root/src/merkleblock.cpp
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@gmail.com>2017-09-11 17:42:37 -0700
committerJames O'Beirne <james.obeirne@gmail.com>2017-09-20 20:35:54 -0700
commit5ab586f90b74d84e29156ebf6692b9e9055aa047 (patch)
treedf40944f8ec6d4135bb2a610095f1b5d6924548a /src/merkleblock.cpp
parent3255d6347b1f9eccbec3d6d93d4a424087a3b35b (diff)
downloadbitcoin-5ab586f90b74d84e29156ebf6692b9e9055aa047.tar.xz
Consolidate CMerkleBlock constructor into a single method
Incorporates feedback suggested by @sipa, @promag, @TheBlueMatt.
Diffstat (limited to 'src/merkleblock.cpp')
-rw-r--r--src/merkleblock.cpp35
1 files changed, 7 insertions, 28 deletions
diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp
index f0abea0611..3f07b4dac4 100644
--- a/src/merkleblock.cpp
+++ b/src/merkleblock.cpp
@@ -9,33 +9,8 @@
#include "consensus/consensus.h"
#include "utilstrencodings.h"
-CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter& filter)
-{
- header = block.GetBlockHeader();
- std::vector<bool> vMatch;
- std::vector<uint256> vHashes;
-
- vMatch.reserve(block.vtx.size());
- vHashes.reserve(block.vtx.size());
-
- for (unsigned int i = 0; i < block.vtx.size(); i++)
- {
- const uint256& hash = block.vtx[i]->GetHash();
- if (filter.IsRelevantAndUpdate(*block.vtx[i]))
- {
- vMatch.push_back(true);
- vMatchedTxn.push_back(std::make_pair(i, hash));
- }
- else
- vMatch.push_back(false);
- vHashes.push_back(hash);
- }
-
- txn = CPartialMerkleTree(vHashes, vMatch);
-}
-
-CMerkleBlock::CMerkleBlock(const CBlock& block, const std::set<uint256>& txids)
+CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter* filter, const std::set<uint256>* txids)
{
header = block.GetBlockHeader();
@@ -48,10 +23,14 @@ CMerkleBlock::CMerkleBlock(const CBlock& block, const std::set<uint256>& txids)
for (unsigned int i = 0; i < block.vtx.size(); i++)
{
const uint256& hash = block.vtx[i]->GetHash();
- if (txids.count(hash))
+ if (txids && txids->count(hash)) {
vMatch.push_back(true);
- else
+ } else if (filter && filter->IsRelevantAndUpdate(*block.vtx[i])) {
+ vMatch.push_back(true);
+ vMatchedTxn.emplace_back(i, hash);
+ } else {
vMatch.push_back(false);
+ }
vHashes.push_back(hash);
}