4
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
6
6
#include < httpserver.h>
7
+ #include < index/blockfilterindex.h>
8
+ #include < index/txindex.h>
7
9
#include < interfaces/chain.h>
8
10
#include < key_io.h>
9
11
#include < node/context.h>
@@ -636,6 +638,60 @@ static RPCHelpMan echo(const std::string& name)
636
638
static RPCHelpMan echo () { return echo (" echo" ); }
637
639
static RPCHelpMan echojson () { return echo (" echojson" ); }
638
640
641
+ static UniValue SummaryToJSON (const IndexSummary&& summary, std::string index_name)
642
+ {
643
+ UniValue ret_summary (UniValue::VOBJ);
644
+ if (!index_name.empty () && index_name != summary.name ) return ret_summary;
645
+
646
+ UniValue entry (UniValue::VOBJ);
647
+ entry.pushKV (" synced" , summary.synced );
648
+ entry.pushKV (" best_block_height" , summary.best_block_height );
649
+ ret_summary.pushKV (summary.name , entry);
650
+ return ret_summary;
651
+ }
652
+
653
+ static RPCHelpMan getindexinfo ()
654
+ {
655
+ return RPCHelpMan{" getindexinfo" ,
656
+ " \n Returns the status of one or all available indices currently running in the node.\n " ,
657
+ {
658
+ {" index_name" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " Filter results for an index with a specific name." },
659
+ },
660
+ RPCResult{
661
+ RPCResult::Type::OBJ, " " , " " , {
662
+ {
663
+ RPCResult::Type::OBJ, " name" , " The name of the index" ,
664
+ {
665
+ {RPCResult::Type::BOOL, " synced" , " Whether the index is synced or not" },
666
+ {RPCResult::Type::NUM, " best_block_height" , " The block height to which the index is synced" },
667
+ }
668
+ },
669
+ },
670
+ },
671
+ RPCExamples{
672
+ HelpExampleCli (" getindexinfo" , " " )
673
+ + HelpExampleRpc (" getindexinfo" , " " )
674
+ + HelpExampleCli (" getindexinfo" , " txindex" )
675
+ + HelpExampleRpc (" getindexinfo" , " txindex" )
676
+ },
677
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
678
+ {
679
+ UniValue result (UniValue::VOBJ);
680
+ const std::string index_name = request.params [0 ].isNull () ? " " : request.params [0 ].get_str ();
681
+
682
+ if (g_txindex) {
683
+ result.pushKVs (SummaryToJSON (g_txindex->GetSummary (), index_name));
684
+ }
685
+
686
+ ForEachBlockFilterIndex ([&result, &index_name](const BlockFilterIndex& index) {
687
+ result.pushKVs (SummaryToJSON (index.GetSummary (), index_name));
688
+ });
689
+
690
+ return result;
691
+ },
692
+ };
693
+ }
694
+
639
695
void RegisterMiscRPCCommands (CRPCTable &t)
640
696
{
641
697
// clang-format off
@@ -650,6 +706,7 @@ static const CRPCCommand commands[] =
650
706
{ " util" , " getdescriptorinfo" , &getdescriptorinfo, {" descriptor" } },
651
707
{ " util" , " verifymessage" , &verifymessage, {" address" ," signature" ," message" } },
652
708
{ " util" , " signmessagewithprivkey" , &signmessagewithprivkey, {" privkey" ," message" } },
709
+ { " util" , " getindexinfo" , &getindexinfo, {" index_name" } },
653
710
654
711
/* Not shown in help */
655
712
{ " hidden" , " setmocktime" , &setmocktime, {" timestamp" }},
0 commit comments