mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
Ignore blocks that do not match the filter in getmerkleblocks rpc (#2973)
Also clarify method description a bit
This commit is contained in:
parent
4739daddc8
commit
bfcfb70d8c
@ -838,7 +838,7 @@ UniValue getmerkleblocks(const JSONRPCRequest& request)
|
|||||||
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
|
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"getmerkleblocks \"filter\" \"hash\" ( count )\n"
|
"getmerkleblocks \"filter\" \"hash\" ( count )\n"
|
||||||
"\nReturns an array of items with information about <count> merkleblocks starting from <hash> which match <filter>.\n"
|
"\nReturns an array of hex-encoded merkleblocks for <count> blocks starting from <hash> which match <filter>.\n"
|
||||||
"\nArguments:\n"
|
"\nArguments:\n"
|
||||||
"1. \"filter\" (string, required) The hex encoded bloom filter\n"
|
"1. \"filter\" (string, required) The hex encoded bloom filter\n"
|
||||||
"2. \"hash\" (string, required) The block hash\n"
|
"2. \"hash\" (string, required) The block hash\n"
|
||||||
@ -899,16 +899,25 @@ UniValue getmerkleblocks(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
for (; pblockindex; pblockindex = chainActive.Next(pblockindex))
|
for (; pblockindex; pblockindex = chainActive.Next(pblockindex))
|
||||||
{
|
{
|
||||||
|
if (--nCount < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) {
|
if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) {
|
||||||
// this shouldn't happen, we already checked pruning case earlier
|
// this shouldn't happen, we already checked pruning case earlier
|
||||||
throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk");
|
throw JSONRPCError(RPC_MISC_ERROR, "Block not found on disk");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CMerkleBlock merkleblock(block, filter);
|
||||||
|
if (merkleblock.vMatchedTxn.empty()) {
|
||||||
|
// ignore blocks that do not match the filter
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
CDataStream ssMerkleBlock(SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ssMerkleBlock(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
ssMerkleBlock << CMerkleBlock(block, filter);
|
ssMerkleBlock << merkleblock;
|
||||||
std::string strHex = HexStr(ssMerkleBlock);
|
std::string strHex = HexStr(ssMerkleBlock);
|
||||||
arrMerkleBlocks.push_back(strHex);
|
arrMerkleBlocks.push_back(strHex);
|
||||||
if (--nCount <= 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return arrMerkleBlocks;
|
return arrMerkleBlocks;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user