Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/merkleblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std::vector<bool> BytesToBits(const std::vector<unsigned char>& bytes)
return ret;
}

CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter* filter, const std::set<uint256>* txids)
CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter* filter, const std::set<Txid>* txids)
{
header = block.GetBlockHeader();

Expand All @@ -51,9 +51,8 @@ CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter* filter, const std:
for (unsigned int i = 0; i < block.vtx.size(); i++)
{
const auto& tx = *block.vtx[i];
const uint256& hash = tx.GetHash();
const Txid& hash{tx.GetHash()};
bool isAllowedType = !tx.IsSpecialTxVersion() || allowedTxTypes.count(tx.nType) != 0;

if (txids && txids->count(hash)) {
vMatch.push_back(true);
} else if (isAllowedType && filter && filter->IsRelevantAndUpdate(*block.vtx[i])) {
Expand Down
5 changes: 3 additions & 2 deletions src/merkleblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <serialize.h>
#include <uint256.h>

#include <set>
#include <vector>

// Helper functions for serialization.
Expand Down Expand Up @@ -144,15 +145,15 @@ class CMerkleBlock
CMerkleBlock(const CBlock& block, CBloomFilter& filter) : CMerkleBlock(block, &filter, nullptr) { }

// Create from a CBlock, matching the txids in the set
CMerkleBlock(const CBlock& block, const std::set<uint256>& txids) : CMerkleBlock(block, nullptr, &txids) { }
CMerkleBlock(const CBlock& block, const std::set<Txid>& txids) : CMerkleBlock{block, nullptr, &txids} {}

CMerkleBlock() {}

SERIALIZE_METHODS(CMerkleBlock, obj) { READWRITE(obj.header, obj.txn); }

private:
// Combined constructor to consolidate code
CMerkleBlock(const CBlock& block, CBloomFilter* filter, const std::set<uint256>* txids);
CMerkleBlock(const CBlock& block, CBloomFilter* filter, const std::set<Txid>* txids);
};

#endif // BITCOIN_MERKLEBLOCK_H
6 changes: 3 additions & 3 deletions src/rpc/txoutproof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ static RPCHelpMan gettxoutproof()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
std::set<uint256> setTxids;
std::set<Txid> setTxids;
UniValue txids = request.params[0].get_array();
if (txids.empty()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Parameter 'txids' cannot be empty");
}
for (unsigned int idx = 0; idx < txids.size(); idx++) {
auto ret = setTxids.insert(ParseHashV(txids[idx], "txid"));
auto ret{setTxids.insert(Txid::FromUint256(ParseHashV(txids[idx], "txid")))};
if (!ret.second) {
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated txid: ") + txids[idx].get_str());
}
Expand All @@ -74,7 +74,7 @@ static RPCHelpMan gettxoutproof()

// Loop through txids and try to find which block they're in. Exit loop once a block is found.
for (const auto& tx : setTxids) {
const Coin& coin = AccessByTxid(active_chainstate.CoinsTip(), tx);
const Coin& coin{AccessByTxid(active_chainstate.CoinsTip(), tx)};
if (!coin.IsSpent()) {
pblockindex = active_chainstate.m_chain[coin.nHeight];
break;
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/merkleblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ FUZZ_TARGET(merkleblock)
CMerkleBlock merkle_block;
const std::optional<CBlock> opt_block = ConsumeDeserializable<CBlock>(fuzzed_data_provider);
CBloomFilter bloom_filter;
std::set<uint256> txids;
std::set<Txid> txids;
if (opt_block && !opt_block->vtx.empty()) {
if (fuzzed_data_provider.ConsumeBool()) {
merkle_block = CMerkleBlock{*opt_block, bloom_filter};
} else if (fuzzed_data_provider.ConsumeBool()) {
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
txids.insert(ConsumeUInt256(fuzzed_data_provider));
txids.insert(Txid::FromUint256(ConsumeUInt256(fuzzed_data_provider)));
}
merkle_block = CMerkleBlock{*opt_block, txids};
}
Expand Down
10 changes: 5 additions & 5 deletions src/test/merkleblock_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_found)
{
CBlock block = getBlock13b8a();

std::set<uint256> txids;
std::set<Txid> txids;

// Last txn in block.
uint256 txhash1 = uint256S("0x74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20");
Txid txhash1{TxidFromString("0x74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20")};

// Second txn in block.
uint256 txhash2 = uint256S("0xf9fc751cb7dc372406a9f8d738d5e6f8f63bab71986a39cf36ee70ee17036d07");
Txid txhash2{TxidFromString("0xf9fc751cb7dc372406a9f8d738d5e6f8f63bab71986a39cf36ee70ee17036d07")};

txids.insert(txhash1);
txids.insert(txhash2);
Expand Down Expand Up @@ -62,8 +62,8 @@ BOOST_AUTO_TEST_CASE(merkleblock_construct_from_txids_not_found)
{
CBlock block = getBlock13b8a();

std::set<uint256> txids2;
txids2.insert(uint256S("0xc0ffee00003bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"));
std::set<Txid> txids2;
txids2.insert(TxidFromString("0xc0ffee00003bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"));
CMerkleBlock merkleBlock(block, txids2);

BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex());
Expand Down
Loading