2013-12-13 16:01:22 +01:00
// Copyright (c) 2010 Satoshi Nakamoto
2021-12-30 19:36:57 +02:00
// Copyright (c) 2009-2021 The Bitcoin Core developers
2014-11-20 10:19:29 +08:00
// Distributed under the MIT software license, see the accompanying
2013-12-13 16:01:22 +01:00
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2022-05-03 08:30:16 +02:00
# include <chainparams.h>
2017-11-10 13:57:53 +13:00
# include <httpserver.h>
2020-07-31 14:01:31 +02:00
# include <index/blockfilterindex.h>
2020-08-22 18:31:34 +02:00
# include <index/coinstatsindex.h>
2020-07-31 14:01:31 +02:00
# include <index/txindex.h>
2017-12-05 15:57:12 -05:00
# include <interfaces/chain.h>
2020-11-24 13:59:33 -05:00
# include <interfaces/echo.h>
# include <interfaces/init.h>
# include <interfaces/ipc.h>
2020-02-12 11:12:20 -08:00
# include <node/context.h>
2017-11-10 13:57:53 +13:00
# include <rpc/server.h>
2021-04-21 16:39:40 +02:00
# include <rpc/server_util.h>
2017-09-29 00:21:28 -04:00
# include <rpc/util.h>
2020-02-12 11:12:20 -08:00
# include <scheduler.h>
2022-04-28 10:58:23 +02:00
# include <univalue.h>
2019-09-23 14:45:51 -04:00
# include <util/check.h>
2021-10-01 13:53:59 +00:00
# include <util/syscall_sandbox.h>
2019-09-23 14:45:51 -04:00
# include <util/system.h>
2013-12-13 16:01:22 +01:00
# include <stdint.h>
2017-03-20 10:09:01 +01:00
# ifdef HAVE_MALLOC_INFO
# include <malloc.h>
# endif
2013-12-13 16:01:22 +01:00
2021-11-12 10:06:00 -05:00
using node : : NodeContext ;
2020-07-15 21:26:22 +02:00
static RPCHelpMan setmocktime ( )
2014-11-12 18:59:41 -05:00
{
2020-07-15 21:26:22 +02:00
return RPCHelpMan { " setmocktime " ,
2021-02-01 14:57:34 +00:00
" \n Set the local time to given timestamp (-regtest only) \n " ,
{
{ " timestamp " , RPCArg : : Type : : NUM , RPCArg : : Optional : : NO , UNIX_EPOCH_TIME + " \n "
" Pass 0 to go back to using the system time. " } ,
} ,
RPCResult { RPCResult : : Type : : NONE , " " , " " } ,
RPCExamples { " " } ,
2020-07-15 21:26:22 +02:00
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
2020-03-04 14:01:31 -08:00
if ( ! Params ( ) . IsMockableChain ( ) ) {
throw std : : runtime_error ( " setmocktime is for regression testing (-regtest mode) only " ) ;
}
2014-11-12 18:59:41 -05:00
2017-01-19 13:01:18 -05:00
// For now, don't change mocktime if we're in the middle of validation, as
// this could have an effect on mempool time-based eviction, as well as
// IsCurrentForFeeEstimation() and IsInitialBlockDownload().
// TODO: figure out the right way to synchronize around mocktime, and
2017-02-06 15:16:18 +01:00
// ensure all call sites of GetTime() are accessing this safely.
2016-04-16 19:13:12 -04:00
LOCK ( cs_main ) ;
2014-10-19 04:46:17 -04:00
2017-06-06 21:15:28 +02:00
RPCTypeCheck ( request . params , { UniValue : : VNUM } ) ;
2021-02-01 14:57:34 +00:00
const int64_t time { request . params [ 0 ] . get_int64 ( ) } ;
if ( time < 0 ) {
2022-02-17 12:54:39 +01:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , strprintf ( " Mocktime cannot be negative: %s. " , time ) ) ;
2021-02-01 14:57:34 +00:00
}
2017-12-05 15:57:12 -05:00
SetMockTime ( time ) ;
2020-12-01 00:36:36 +01:00
auto node_context = util : : AnyPtr < NodeContext > ( request . context ) ;
if ( node_context ) {
for ( const auto & chain_client : node_context - > chain_clients ) {
2017-12-05 15:57:12 -05:00
chain_client - > setMockTime ( time ) ;
}
}
2014-11-12 18:59:41 -05:00
2015-05-10 13:35:44 +02:00
return NullUniValue ;
2020-07-15 21:26:22 +02:00
} ,
} ;
2014-11-12 18:59:41 -05:00
}
2016-03-29 19:43:02 +02:00
2021-10-01 13:53:59 +00:00
# if defined(USE_SYSCALL_SANDBOX)
static RPCHelpMan invokedisallowedsyscall ( )
{
return RPCHelpMan {
" invokedisallowedsyscall " ,
" \n Invoke a disallowed syscall to trigger a syscall sandbox violation. Used for testing purposes. \n " ,
{ } ,
RPCResult { RPCResult : : Type : : NONE , " " , " " } ,
RPCExamples {
HelpExampleCli ( " invokedisallowedsyscall " , " " ) + HelpExampleRpc ( " invokedisallowedsyscall " , " " ) } ,
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue {
if ( ! Params ( ) . IsTestChain ( ) ) {
throw std : : runtime_error ( " invokedisallowedsyscall is used for testing only. " ) ;
}
TestDisallowedSandboxCall ( ) ;
return NullUniValue ;
} ,
} ;
}
# endif // USE_SYSCALL_SANDBOX
2020-07-15 21:26:22 +02:00
static RPCHelpMan mockscheduler ( )
2020-02-12 11:12:20 -08:00
{
2020-07-15 21:26:22 +02:00
return RPCHelpMan { " mockscheduler " ,
2020-02-12 11:12:20 -08:00
" \n Bump the scheduler into the future (-regtest only) \n " ,
{
{ " delta_time " , RPCArg : : Type : : NUM , RPCArg : : Optional : : NO , " Number of seconds to forward the scheduler into the future. " } ,
} ,
2020-03-13 14:40:53 -04:00
RPCResult { RPCResult : : Type : : NONE , " " , " " } ,
2020-02-12 11:12:20 -08:00
RPCExamples { " " } ,
2020-07-15 21:26:22 +02:00
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
2020-02-12 11:12:20 -08:00
if ( ! Params ( ) . IsMockableChain ( ) ) {
throw std : : runtime_error ( " mockscheduler is for regression testing (-regtest mode) only " ) ;
}
// check params are valid values
RPCTypeCheck ( request . params , { UniValue : : VNUM } ) ;
int64_t delta_seconds = request . params [ 0 ] . get_int64 ( ) ;
2021-05-14 12:52:15 +02:00
if ( delta_seconds < = 0 | | delta_seconds > 3600 ) {
2020-02-12 11:12:20 -08:00
throw std : : runtime_error ( " delta_time must be between 1 and 3600 seconds (1 hr) " ) ;
}
2022-04-09 02:14:02 +02:00
auto node_context = CHECK_NONFATAL ( util : : AnyPtr < NodeContext > ( request . context ) ) ;
2020-02-12 11:12:20 -08:00
// protect against null pointer dereference
2020-12-01 00:36:36 +01:00
CHECK_NONFATAL ( node_context - > scheduler ) ;
node_context - > scheduler - > MockForward ( std : : chrono : : seconds ( delta_seconds ) ) ;
2020-02-12 11:12:20 -08:00
return NullUniValue ;
2020-07-15 21:26:22 +02:00
} ,
} ;
2020-02-12 11:12:20 -08:00
}
2016-09-18 10:22:30 +02:00
static UniValue RPCLockedMemoryInfo ( )
{
LockedPool : : Stats stats = LockedPoolManager : : Instance ( ) . stats ( ) ;
UniValue obj ( UniValue : : VOBJ ) ;
2017-09-22 20:04:07 +02:00
obj . pushKV ( " used " , uint64_t ( stats . used ) ) ;
obj . pushKV ( " free " , uint64_t ( stats . free ) ) ;
obj . pushKV ( " total " , uint64_t ( stats . total ) ) ;
obj . pushKV ( " locked " , uint64_t ( stats . locked ) ) ;
obj . pushKV ( " chunks_used " , uint64_t ( stats . chunks_used ) ) ;
obj . pushKV ( " chunks_free " , uint64_t ( stats . chunks_free ) ) ;
2016-09-18 10:22:30 +02:00
return obj ;
}
2017-03-20 10:09:01 +01:00
# ifdef HAVE_MALLOC_INFO
static std : : string RPCMallocInfo ( )
{
char * ptr = nullptr ;
size_t size = 0 ;
FILE * f = open_memstream ( & ptr , & size ) ;
if ( f ) {
malloc_info ( 0 , f ) ;
fclose ( f ) ;
if ( ptr ) {
std : : string rv ( ptr , size ) ;
free ( ptr ) ;
return rv ;
}
}
return " " ;
}
# endif
2020-07-15 21:26:22 +02:00
static RPCHelpMan getmemoryinfo ( )
2016-09-18 10:22:30 +02:00
{
/* Please, avoid using the word "pool" here in the RPC interface or help,
* as users will undoubtedly confuse it with the other " memory pool "
*/
2020-07-15 21:26:22 +02:00
return RPCHelpMan { " getmemoryinfo " ,
2018-10-20 08:19:44 -04:00
" Returns an object containing information about memory usage. \n " ,
{
2021-04-14 15:01:00 +01:00
{ " mode " , RPCArg : : Type : : STR , RPCArg : : Default { " stats " } , " determines what kind of information is returned. \n "
2018-11-23 11:21:38 -05:00
" - \" stats \" returns general statistics about memory usage in the daemon. \n "
" - \" mallocinfo \" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+). " } ,
2018-12-21 12:29:36 -05:00
} ,
{
RPCResult { " mode \" stats \" " ,
2020-01-10 00:00:57 +07:00
RPCResult : : Type : : OBJ , " " , " " ,
{
{ RPCResult : : Type : : OBJ , " locked " , " Information about locked memory manager " ,
{
{ RPCResult : : Type : : NUM , " used " , " Number of bytes used " } ,
{ RPCResult : : Type : : NUM , " free " , " Number of bytes available in current arenas " } ,
{ RPCResult : : Type : : NUM , " total " , " Total number of bytes managed " } ,
{ RPCResult : : Type : : NUM , " locked " , " Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk. " } ,
{ RPCResult : : Type : : NUM , " chunks_used " , " Number allocated chunks " } ,
{ RPCResult : : Type : : NUM , " chunks_free " , " Number unused chunks " } ,
} } ,
}
2018-12-21 12:29:36 -05:00
} ,
RPCResult { " mode \" mallocinfo \" " ,
2020-01-10 00:00:57 +07:00
RPCResult : : Type : : STR , " " , " \" <malloc version= \" 1 \" >... \" "
2018-12-21 12:29:36 -05:00
} ,
} ,
RPCExamples {
HelpExampleCli ( " getmemoryinfo " , " " )
2016-09-18 10:22:30 +02:00
+ HelpExampleRpc ( " getmemoryinfo " , " " )
2018-12-21 12:29:36 -05:00
} ,
2020-07-15 21:26:22 +02:00
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
2017-08-14 19:38:18 -04:00
std : : string mode = request . params [ 0 ] . isNull ( ) ? " stats " : request . params [ 0 ] . get_str ( ) ;
2017-03-20 10:09:01 +01:00
if ( mode = = " stats " ) {
UniValue obj ( UniValue : : VOBJ ) ;
2017-09-22 20:04:07 +02:00
obj . pushKV ( " locked " , RPCLockedMemoryInfo ( ) ) ;
2017-03-20 10:09:01 +01:00
return obj ;
} else if ( mode = = " mallocinfo " ) {
# ifdef HAVE_MALLOC_INFO
return RPCMallocInfo ( ) ;
# else
2021-12-01 19:18:26 +08:00
throw JSONRPCError ( RPC_INVALID_PARAMETER , " mallocinfo mode not available " ) ;
2017-03-20 10:09:01 +01:00
# endif
} else {
throw JSONRPCError ( RPC_INVALID_PARAMETER , " unknown mode " + mode ) ;
}
2020-07-15 21:26:22 +02:00
} ,
} ;
2016-09-18 10:22:30 +02:00
}
2018-05-02 17:14:48 +02:00
static void EnableOrDisableLogCategories ( UniValue cats , bool enable ) {
2017-04-03 13:39:11 -04:00
cats = cats . get_array ( ) ;
for ( unsigned int i = 0 ; i < cats . size ( ) ; + + i ) {
std : : string cat = cats [ i ] . get_str ( ) ;
2018-04-11 14:06:35 -07:00
bool success ;
2018-04-11 13:02:01 -07:00
if ( enable ) {
2019-01-25 15:54:49 -05:00
success = LogInstance ( ) . EnableCategory ( cat ) ;
2018-04-11 13:02:01 -07:00
} else {
2019-01-25 15:54:49 -05:00
success = LogInstance ( ) . DisableCategory ( cat ) ;
2018-04-11 14:06:35 -07:00
}
if ( ! success ) {
throw JSONRPCError ( RPC_INVALID_PARAMETER , " unknown logging category " + cat ) ;
2017-08-29 20:32:16 +09:00
}
2017-04-03 13:39:11 -04:00
}
}
2020-07-15 21:26:22 +02:00
static RPCHelpMan logging ( )
2017-04-03 13:39:11 -04:00
{
2020-07-15 21:26:22 +02:00
return RPCHelpMan { " logging " ,
2017-04-03 13:39:11 -04:00
" Gets and sets the logging configuration. \n "
2017-08-29 20:32:16 +09:00
" When called without an argument, returns the list of categories with status that are currently being debug logged or not. \n "
" When called with arguments, adds or removes categories from debug logging and return the lists above. \n "
" The arguments are evaluated in order \" include \" , \" exclude \" . \n "
" If an item is both included and excluded, it will thus end up being excluded. \n "
2020-04-16 11:12:14 -04:00
" The valid logging categories are: " + LogInstance ( ) . LogCategoriesString ( ) + " \n "
2017-08-29 20:32:16 +09:00
" In addition, the following are available as category names with special meanings: \n "
" - \" all \" , \" 1 \" : represent all logging categories. \n "
" - \" none \" , \" 0 \" : even if other logging categories are specified, ignore all of them. \n "
2018-10-20 08:19:44 -04:00
,
{
2020-03-05 10:36:27 +00:00
{ " include " , RPCArg : : Type : : ARR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " The categories to add to debug logging " ,
2018-11-23 11:21:38 -05:00
{
2018-12-10 16:56:51 -05:00
{ " include_category " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED , " the valid logging category " } ,
2018-11-23 11:21:38 -05:00
} } ,
2020-03-05 10:36:27 +00:00
{ " exclude " , RPCArg : : Type : : ARR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " The categories to remove from debug logging " ,
2018-11-23 11:21:38 -05:00
{
2018-12-10 16:56:51 -05:00
{ " exclude_category " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED , " the valid logging category " } ,
2018-11-23 11:21:38 -05:00
} } ,
2018-12-21 12:29:36 -05:00
} ,
RPCResult {
2020-01-10 00:00:57 +07:00
RPCResult : : Type : : OBJ_DYN , " " , " keys are the logging categories, and values indicates its status " ,
{
{ RPCResult : : Type : : BOOL , " category " , " if being debug logged or not. false:inactive, true:active " } ,
}
2018-12-21 12:29:36 -05:00
} ,
RPCExamples {
HelpExampleCli ( " logging " , " \" [ \\ \" all \\ \" ] \" \" [ \\ \" http \\ \" ] \" " )
2019-01-27 22:47:55 +08:00
+ HelpExampleRpc ( " logging " , " [ \" all \" ], [ \" libevent \" ] " )
2018-12-21 12:29:36 -05:00
} ,
2020-07-15 21:26:22 +02:00
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
2019-01-25 15:54:49 -05:00
uint32_t original_log_categories = LogInstance ( ) . GetCategoryMask ( ) ;
2017-08-14 19:38:18 -04:00
if ( request . params [ 0 ] . isArray ( ) ) {
2018-04-11 13:02:01 -07:00
EnableOrDisableLogCategories ( request . params [ 0 ] , true ) ;
2017-04-03 13:39:11 -04:00
}
2017-08-14 19:38:18 -04:00
if ( request . params [ 1 ] . isArray ( ) ) {
2018-04-11 13:02:01 -07:00
EnableOrDisableLogCategories ( request . params [ 1 ] , false ) ;
2017-04-03 13:39:11 -04:00
}
2019-01-25 15:54:49 -05:00
uint32_t updated_log_categories = LogInstance ( ) . GetCategoryMask ( ) ;
2018-04-11 13:02:01 -07:00
uint32_t changed_log_categories = original_log_categories ^ updated_log_categories ;
2017-04-03 13:39:11 -04:00
2017-04-10 10:34:23 -04:00
// Update libevent logging if BCLog::LIBEVENT has changed.
2018-04-11 13:02:01 -07:00
if ( changed_log_categories & BCLog : : LIBEVENT ) {
2022-04-02 19:26:46 +02:00
UpdateHTTPServerLogging ( LogInstance ( ) . WillLogCategory ( BCLog : : LIBEVENT ) ) ;
2017-04-10 10:34:23 -04:00
}
2017-04-03 13:39:11 -04:00
UniValue result ( UniValue : : VOBJ ) ;
2020-04-16 11:12:14 -04:00
for ( const auto & logCatActive : LogInstance ( ) . LogCategoriesList ( ) ) {
2017-04-03 13:39:11 -04:00
result . pushKV ( logCatActive . category , logCatActive . active ) ;
}
return result ;
2020-07-15 21:26:22 +02:00
} ,
} ;
2017-04-03 13:39:11 -04:00
}
2020-07-15 21:26:22 +02:00
static RPCHelpMan echo ( const std : : string & name )
2016-09-25 20:55:24 +02:00
{
2020-07-15 21:26:22 +02:00
return RPCHelpMan { name ,
2018-10-20 08:19:44 -04:00
" \n Simply echo back the input arguments. This command is for testing. \n "
2020-07-15 22:10:45 +02:00
" \n It will return an internal bug report when arg9='trigger_internal_bug' is passed. \n "
2018-11-15 12:19:41 -05:00
" \n The difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in "
2018-10-20 08:19:44 -04:00
" bitcoin-cli and the GUI. There is no server-side difference. " ,
2020-07-15 22:10:45 +02:00
{
{ " arg0 " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " " } ,
{ " arg1 " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " " } ,
{ " arg2 " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " " } ,
{ " arg3 " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " " } ,
{ " arg4 " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " " } ,
{ " arg5 " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " " } ,
{ " arg6 " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " " } ,
{ " arg7 " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " " } ,
{ " arg8 " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " " } ,
{ " arg9 " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " " } ,
} ,
2020-11-23 10:41:27 +01:00
RPCResult { RPCResult : : Type : : ANY , " " , " Returns whatever was passed in " } ,
2018-12-21 12:29:36 -05:00
RPCExamples { " " } ,
2020-07-15 21:26:22 +02:00
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
2020-07-15 22:10:45 +02:00
if ( request . params [ 9 ] . isStr ( ) ) {
CHECK_NONFATAL ( request . params [ 9 ] . get_str ( ) ! = " trigger_internal_bug " ) ;
}
2019-09-23 14:45:51 -04:00
2016-09-25 20:55:24 +02:00
return request . params ;
2020-07-15 21:26:22 +02:00
} ,
} ;
2016-09-25 20:55:24 +02:00
}
2020-07-15 21:26:22 +02:00
static RPCHelpMan echo ( ) { return echo ( " echo " ) ; }
static RPCHelpMan echojson ( ) { return echo ( " echojson " ) ; }
2020-11-24 13:59:33 -05:00
static RPCHelpMan echoipc ( )
{
return RPCHelpMan {
" echoipc " ,
" \n Echo back the input argument, passing it through a spawned process in a multiprocess build. \n "
" This command is for testing. \n " ,
{ { " arg " , RPCArg : : Type : : STR , RPCArg : : Optional : : NO , " The string to echo " , } } ,
RPCResult { RPCResult : : Type : : STR , " echo " , " The echoed string. " } ,
RPCExamples { HelpExampleCli ( " echo " , " \" Hello world \" " ) +
HelpExampleRpc ( " echo " , " \" Hello world \" " ) } ,
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue {
2017-12-05 15:57:12 -05:00
interfaces : : Init & local_init = * EnsureAnyNodeContext ( request . context ) . init ;
2020-11-24 13:59:33 -05:00
std : : unique_ptr < interfaces : : Echo > echo ;
2017-12-05 15:57:12 -05:00
if ( interfaces : : Ipc * ipc = local_init . ipc ( ) ) {
2020-11-24 13:59:33 -05:00
// Spawn a new bitcoin-node process and call makeEcho to get a
// client pointer to a interfaces::Echo instance running in
// that process. This is just for testing. A slightly more
// realistic test spawning a different executable instead of
// the same executable would add a new bitcoin-echo executable,
// and spawn bitcoin-echo below instead of bitcoin-node. But
// using bitcoin-node avoids the need to build and install a
// new executable just for this one test.
auto init = ipc - > spawnProcess ( " bitcoin-node " ) ;
echo = init - > makeEcho ( ) ;
ipc - > addCleanup ( * echo , [ init = init . release ( ) ] { delete init ; } ) ;
} else {
// IPC support is not available because this is a bitcoind
// process not a bitcoind-node process, so just create a local
// interfaces::Echo object and return it so the `echoipc` RPC
// method will work, and the python test calling `echoipc`
// can expect the same result.
2017-12-05 15:57:12 -05:00
echo = local_init . makeEcho ( ) ;
2020-11-24 13:59:33 -05:00
}
return echo - > echo ( request . params [ 0 ] . get_str ( ) ) ;
} ,
} ;
}
2020-07-31 14:01:31 +02:00
static UniValue SummaryToJSON ( const IndexSummary & & summary , std : : string index_name )
{
UniValue ret_summary ( UniValue : : VOBJ ) ;
if ( ! index_name . empty ( ) & & index_name ! = summary . name ) return ret_summary ;
UniValue entry ( UniValue : : VOBJ ) ;
entry . pushKV ( " synced " , summary . synced ) ;
entry . pushKV ( " best_block_height " , summary . best_block_height ) ;
ret_summary . pushKV ( summary . name , entry ) ;
return ret_summary ;
}
static RPCHelpMan getindexinfo ( )
{
return RPCHelpMan { " getindexinfo " ,
" \n Returns the status of one or all available indices currently running in the node. \n " ,
{
{ " index_name " , RPCArg : : Type : : STR , RPCArg : : Optional : : OMITTED_NAMED_ARG , " Filter results for an index with a specific name. " } ,
} ,
RPCResult {
2021-08-25 19:55:15 +02:00
RPCResult : : Type : : OBJ_DYN , " " , " " , {
2020-07-31 14:01:31 +02:00
{
RPCResult : : Type : : OBJ , " name " , " The name of the index " ,
{
{ RPCResult : : Type : : BOOL , " synced " , " Whether the index is synced or not " } ,
{ RPCResult : : Type : : NUM , " best_block_height " , " The block height to which the index is synced " } ,
}
} ,
} ,
} ,
RPCExamples {
HelpExampleCli ( " getindexinfo " , " " )
+ HelpExampleRpc ( " getindexinfo " , " " )
+ HelpExampleCli ( " getindexinfo " , " txindex " )
+ HelpExampleRpc ( " getindexinfo " , " txindex " )
} ,
[ & ] ( const RPCHelpMan & self , const JSONRPCRequest & request ) - > UniValue
{
UniValue result ( UniValue : : VOBJ ) ;
const std : : string index_name = request . params [ 0 ] . isNull ( ) ? " " : request . params [ 0 ] . get_str ( ) ;
if ( g_txindex ) {
result . pushKVs ( SummaryToJSON ( g_txindex - > GetSummary ( ) , index_name ) ) ;
}
2020-08-22 18:31:34 +02:00
if ( g_coin_stats_index ) {
result . pushKVs ( SummaryToJSON ( g_coin_stats_index - > GetSummary ( ) , index_name ) ) ;
}
2020-07-31 14:01:31 +02:00
ForEachBlockFilterIndex ( [ & result , & index_name ] ( const BlockFilterIndex & index ) {
result . pushKVs ( SummaryToJSON ( index . GetSummary ( ) , index_name ) ) ;
} ) ;
return result ;
} ,
} ;
}
2022-04-24 16:44:35 +02:00
void RegisterMiscRPCCommands ( CRPCTable & t )
2020-04-06 00:21:33 +08:00
{
2022-04-24 16:44:35 +02:00
static const CRPCCommand commands [ ] {
{ " control " , & getmemoryinfo } ,
{ " control " , & logging } ,
{ " util " , & getindexinfo } ,
{ " hidden " , & setmocktime } ,
{ " hidden " , & mockscheduler } ,
{ " hidden " , & echo } ,
{ " hidden " , & echojson } ,
{ " hidden " , & echoipc } ,
2021-10-01 13:53:59 +00:00
# if defined(USE_SYSCALL_SANDBOX)
2022-04-24 16:44:35 +02:00
{ " hidden " , & invokedisallowedsyscall } ,
2021-10-01 13:53:59 +00:00
# endif // USE_SYSCALL_SANDBOX
2022-04-24 16:44:35 +02:00
} ;
2020-07-15 21:29:41 +02:00
for ( const auto & c : commands ) {
t . appendCommand ( c . name , & c ) ;
}
2016-03-29 19:43:02 +02:00
}