Files
thehub/libs/utils/merkleblock.cpp
tomFlowee 0a2e552168 Move more logic over to byte-array based Block
This introduces a new BlockHeader helper class which Block and
MutableBlock can both produce, which helps a lot of methods to
be ported to no longer be dependent on us using a MutableBlock
object, which is too costly to use when we have no intention
to alter the block.
2026-04-20 22:21:18 +02:00

70 lines
2.1 KiB
C++

/*
* This file is part of the Flowee project
* Copyright (c) 2009-2010 Satoshi Nakamoto
* Copyright (c) 2009-2015 The Bitcoin Core developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "merkleblock.h"
CMerkleBlock::CMerkleBlock(const MutableBlock &block, CBloomFilter &filter)
{
header = block;
std::vector<bool> vMatch;
std::vector<uint256> vHashes;
vMatch.reserve(block.vtx.size());
vHashes.reserve(block.vtx.size());
for (const auto &tx : block.vtx) {
vMatch.push_back(filter.matchAndInsertOutputs(tx));
}
for (unsigned int i = 0; i < block.vtx.size(); i++) {
const uint256& hash = block.vtx[i].GetHash();
if (!vMatch[i])
vMatch[i] = filter.matchInputs(block.vtx[i]);
if (vMatch[i])
vMatchedTxn.push_back(std::make_pair(i, hash));
vHashes.push_back(hash);
}
txn = CPartialMerkleTree(vHashes, vMatch);
}
CMerkleBlock::CMerkleBlock(const MutableBlock &block, const std::set<uint256> &txids)
{
header = block;
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 (txids.count(hash))
vMatch.push_back(true);
else
vMatch.push_back(false);
vHashes.push_back(hash);
}
txn = CPartialMerkleTree(vHashes, vMatch);
}