MCPcopy Create free account
hub / github.com/ElementsProject/elements / getblockfilter

Function getblockfilter

src/rpc/blockchain.cpp:2867–2944  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2865}
2866
2867static RPCHelpMan getblockfilter()
2868{
2869 return RPCHelpMan{"getblockfilter",
2870 "\nRetrieve a BIP 157 content filter for a particular block.\n",
2871 {
2872 {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hash of the block"},
2873 {"filtertype", RPCArg::Type::STR, RPCArg::Default{"basic"}, "The type name of the filter"},
2874 },
2875 RPCResult{
2876 RPCResult::Type::OBJ, "", "",
2877 {
2878 {RPCResult::Type::STR_HEX, "filter", "the hex-encoded filter data"},
2879 {RPCResult::Type::STR_HEX, "header", "the hex-encoded filter header"},
2880 }},
2881 RPCExamples{
2882 HelpExampleCli("getblockfilter", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" \"basic\"") +
2883 HelpExampleRpc("getblockfilter", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\", \"basic\"")
2884 },
2885 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
2886{
2887 uint256 block_hash = ParseHashV(request.params[0], "blockhash");
2888 std::string filtertype_name = "basic";
2889 if (!request.params[1].isNull()) {
2890 filtertype_name = request.params[1].get_str();
2891 }
2892
2893 BlockFilterType filtertype;
2894 if (!BlockFilterTypeByName(filtertype_name, filtertype)) {
2895 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unknown filtertype");
2896 }
2897
2898 BlockFilterIndex* index = GetBlockFilterIndex(filtertype);
2899 if (!index) {
2900 throw JSONRPCError(RPC_MISC_ERROR, "Index is not enabled for filtertype " + filtertype_name);
2901 }
2902
2903 const CBlockIndex* block_index;
2904 bool block_was_connected;
2905 {
2906 ChainstateManager& chainman = EnsureAnyChainman(request.context);
2907 LOCK(cs_main);
2908 block_index = chainman.m_blockman.LookupBlockIndex(block_hash);
2909 if (!block_index) {
2910 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2911 }
2912 block_was_connected = block_index->IsValid(BLOCK_VALID_SCRIPTS);
2913 }
2914
2915 bool index_ready = index->BlockUntilSyncedToCurrentChain();
2916
2917 BlockFilter filter;
2918 uint256 filter_header;
2919 if (!index->LookupFilter(block_index, filter) ||
2920 !index->LookupFilterHeader(block_index, filter_header)) {
2921 int err_code;
2922 std::string errmsg = "Filter not found.";
2923
2924 if (!block_was_connected) {

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
ParseHashVFunction · 0.85
BlockFilterTypeByNameFunction · 0.85
JSONRPCErrorFunction · 0.85
GetBlockFilterIndexFunction · 0.85
LookupBlockIndexMethod · 0.80
LookupFilterMethod · 0.80
LookupFilterHeaderMethod · 0.80
HexStrFunction · 0.50
isNullMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected