mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-19 13:27:35 +02:00
Merge e4beef611a into merged_master (Bitcoin PR #14121)
This commit is contained in:
commit
52b8a8ee48
18 changed files with 1240 additions and 22 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <amount.h>
|
||||
#include <base58.h>
|
||||
#include <blockfilter.h>
|
||||
#include <chain.h>
|
||||
#include <chainparams.h>
|
||||
#include <checkpoints.h>
|
||||
|
|
@ -14,6 +15,7 @@
|
|||
#include <consensus/validation.h>
|
||||
#include <core_io.h>
|
||||
#include <hash.h>
|
||||
#include <index/blockfilterindex.h>
|
||||
#include <index/txindex.h>
|
||||
#include <key_io.h>
|
||||
#include <policy/feerate.h>
|
||||
|
|
@ -2452,6 +2454,85 @@ UniValue getsidechaininfo(const JSONRPCRequest& request)
|
|||
// END ELEMENTS
|
||||
//
|
||||
|
||||
static UniValue getblockfilter(const JSONRPCRequest& request)
|
||||
{
|
||||
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
|
||||
throw std::runtime_error(
|
||||
RPCHelpMan{"getblockfilter",
|
||||
"\nRetrieve a BIP 157 content filter for a particular block.\n",
|
||||
{
|
||||
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hash of the block"},
|
||||
{"filtertype", RPCArg::Type::STR, /*default*/ "basic", "The type name of the filter"},
|
||||
},
|
||||
RPCResult{
|
||||
"{\n"
|
||||
" \"filter\" : (string) the hex-encoded filter data\n"
|
||||
" \"header\" : (string) the hex-encoded filter header\n"
|
||||
"}\n"
|
||||
},
|
||||
RPCExamples{
|
||||
HelpExampleCli("getblockfilter", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" \"basic\"")
|
||||
}
|
||||
}.ToString()
|
||||
);
|
||||
}
|
||||
|
||||
uint256 block_hash = ParseHashV(request.params[0], "blockhash");
|
||||
std::string filtertype_name = "basic";
|
||||
if (!request.params[1].isNull()) {
|
||||
filtertype_name = request.params[1].get_str();
|
||||
}
|
||||
|
||||
BlockFilterType filtertype;
|
||||
if (!BlockFilterTypeByName(filtertype_name, filtertype)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unknown filtertype");
|
||||
}
|
||||
|
||||
BlockFilterIndex* index = GetBlockFilterIndex(filtertype);
|
||||
if (!index) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Index is not enabled for filtertype " + filtertype_name);
|
||||
}
|
||||
|
||||
const CBlockIndex* block_index;
|
||||
bool block_was_connected;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
block_index = LookupBlockIndex(block_hash);
|
||||
if (!block_index) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||
}
|
||||
block_was_connected = block_index->IsValid(BLOCK_VALID_SCRIPTS);
|
||||
}
|
||||
|
||||
bool index_ready = index->BlockUntilSyncedToCurrentChain();
|
||||
|
||||
BlockFilter filter;
|
||||
uint256 filter_header;
|
||||
if (!index->LookupFilter(block_index, filter) ||
|
||||
!index->LookupFilterHeader(block_index, filter_header)) {
|
||||
int err_code;
|
||||
std::string errmsg = "Filter not found.";
|
||||
|
||||
if (!block_was_connected) {
|
||||
err_code = RPC_INVALID_ADDRESS_OR_KEY;
|
||||
errmsg += " Block was not connected to active chain.";
|
||||
} else if (!index_ready) {
|
||||
err_code = RPC_MISC_ERROR;
|
||||
errmsg += " Block filters are still in the process of being indexed.";
|
||||
} else {
|
||||
err_code = RPC_INTERNAL_ERROR;
|
||||
errmsg += " This error is unexpected and indicates index corruption.";
|
||||
}
|
||||
|
||||
throw JSONRPCError(err_code, errmsg);
|
||||
}
|
||||
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
ret.pushKV("filter", HexStr(filter.GetEncodedFilter()));
|
||||
ret.pushKV("header", filter_header.GetHex());
|
||||
return ret;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
|
||||
static const CRPCCommand commands[] =
|
||||
|
|
@ -2480,6 +2561,7 @@ static const CRPCCommand commands[] =
|
|||
|
||||
{ "blockchain", "preciousblock", &preciousblock, {"blockhash"} },
|
||||
{ "blockchain", "scantxoutset", &scantxoutset, {"action", "scanobjects"} },
|
||||
{ "blockchain", "getblockfilter", &getblockfilter, {"blockhash", "filtertype"} },
|
||||
|
||||
// ELEMENTS:
|
||||
{ "blockchain", "getsidechaininfo", &getsidechaininfo, {} },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue