Changeset View
Changeset View
Standalone View
Standalone View
src/merkleblock.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <merkleblock.h> | #include <merkleblock.h> | ||||
#include <consensus/consensus.h> | #include <consensus/consensus.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
CMerkleBlock::CMerkleBlock(const CBlock &block, CBloomFilter &filter) { | CMerkleBlock::CMerkleBlock(const CBlock &block, CBloomFilter *filter, | ||||
const std::set<TxId> *txids) { | |||||
header = block.GetBlockHeader(); | header = block.GetBlockHeader(); | ||||
std::vector<bool> vMatch; | std::vector<bool> vMatch; | ||||
std::vector<uint256> vHashes; | std::vector<uint256> vHashes; | ||||
vMatch.reserve(block.vtx.size()); | vMatch.reserve(block.vtx.size()); | ||||
vHashes.reserve(block.vtx.size()); | vHashes.reserve(block.vtx.size()); | ||||
if (filter) { | |||||
for (const auto &tx : block.vtx) { | for (const auto &tx : block.vtx) { | ||||
vMatch.push_back(filter.MatchAndInsertOutputs(*tx)); | vMatch.push_back(filter->MatchAndInsertOutputs(*tx)); | ||||
} | |||||
} | } | ||||
for (size_t i = 0; i < block.vtx.size(); i++) { | for (size_t i = 0; i < block.vtx.size(); i++) { | ||||
const CTransaction *tx = block.vtx[i].get(); | const CTransaction *tx = block.vtx[i].get(); | ||||
const TxId &txid = tx->GetId(); | const TxId &txid = tx->GetId(); | ||||
if (filter) { | |||||
if (!vMatch[i]) { | if (!vMatch[i]) { | ||||
vMatch[i] = filter.MatchInputs(*tx); | vMatch[i] = filter->MatchInputs(*tx); | ||||
} | } | ||||
if (vMatch[i]) { | if (vMatch[i]) { | ||||
vMatchedTxn.push_back(std::make_pair(i, txid)); | vMatchedTxn.push_back(std::make_pair(i, txid)); | ||||
} | } | ||||
} else { | |||||
vHashes.push_back(txid); | vMatch.push_back(txids && txids->count(txid)); | ||||
} | |||||
txn = CPartialMerkleTree(vHashes, vMatch); | |||||
} | } | ||||
CMerkleBlock::CMerkleBlock(const CBlock &block, const std::set<TxId> &txids) { | |||||
header = block.GetBlockHeader(); | |||||
std::vector<bool> vMatch; | |||||
std::vector<uint256> vHashes; | |||||
vMatch.reserve(block.vtx.size()); | |||||
vHashes.reserve(block.vtx.size()); | |||||
for (const auto &tx : block.vtx) { | |||||
const TxId &txid = tx->GetId(); | |||||
vMatch.push_back(txids.count(txid)); | |||||
vHashes.push_back(txid); | vHashes.push_back(txid); | ||||
} | } | ||||
txn = CPartialMerkleTree(vHashes, vMatch); | txn = CPartialMerkleTree(vHashes, vMatch); | ||||
} | } | ||||
uint256 CPartialMerkleTree::CalcHash(int height, size_t pos, | uint256 CPartialMerkleTree::CalcHash(int height, size_t pos, | ||||
const std::vector<uint256> &vTxid) { | const std::vector<uint256> &vTxid) { | ||||
▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines |