/* * 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 . */ #include "merkleblock.h" CMerkleBlock::CMerkleBlock(const MutableBlock &block, CBloomFilter &filter) { header = block; std::vector vMatch; std::vector 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 &txids) { header = block; std::vector vMatch; std::vector 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); }