Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/misc.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <httpserver.h> | #include <httpserver.h> | ||||
#include <index/blockfilterindex.h> | |||||
#include <index/txindex.h> | |||||
#include <interfaces/chain.h> | #include <interfaces/chain.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <logging.h> | #include <logging.h> | ||||
#include <node/context.h> | #include <node/context.h> | ||||
#include <outputtype.h> | #include <outputtype.h> | ||||
#include <rpc/blockchain.h> | #include <rpc/blockchain.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
▲ Show 20 Lines • Show All 799 Lines • ▼ Show 20 Lines | return RPCHelpMan{ | ||||
res.pushKV("ticker", currency.ticker); | res.pushKV("ticker", currency.ticker); | ||||
res.pushKV("satoshisperunit", currency.baseunit / SATOSHI); | res.pushKV("satoshisperunit", currency.baseunit / SATOSHI); | ||||
res.pushKV("decimals", currency.decimals); | res.pushKV("decimals", currency.decimals); | ||||
return res; | return res; | ||||
}, | }, | ||||
}; | }; | ||||
} | } | ||||
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", | |||||
"\nReturns 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{ | |||||
RPCResult::Type::OBJ, | |||||
"", | |||||
"", | |||||
{ | |||||
{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, Config &config, | |||||
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)); | |||||
} | |||||
ForEachBlockFilterIndex([&result, &index_name]( | |||||
const BlockFilterIndex &index) { | |||||
result.pushKVs(SummaryToJSON(index.GetSummary(), index_name)); | |||||
}); | |||||
return result; | |||||
}, | |||||
}; | |||||
} | |||||
void RegisterMiscRPCCommands(CRPCTable &t) { | void RegisterMiscRPCCommands(CRPCTable &t) { | ||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand commands[] = { | static const CRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "control", "getmemoryinfo", getmemoryinfo, {"mode"} }, | { "control", "getmemoryinfo", getmemoryinfo, {"mode"} }, | ||||
{ "control", "logging", logging, {"include", "exclude"} }, | { "control", "logging", logging, {"include", "exclude"} }, | ||||
{ "util", "validateaddress", validateaddress, {"address"} }, | { "util", "validateaddress", validateaddress, {"address"} }, | ||||
{ "util", "createmultisig", createmultisig, {"nrequired","keys"} }, | { "util", "createmultisig", createmultisig, {"nrequired","keys"} }, | ||||
{ "util", "deriveaddresses", deriveaddresses, {"descriptor", "range"} }, | { "util", "deriveaddresses", deriveaddresses, {"descriptor", "range"} }, | ||||
{ "util", "getdescriptorinfo", getdescriptorinfo, {"descriptor"} }, | { "util", "getdescriptorinfo", getdescriptorinfo, {"descriptor"} }, | ||||
{ "util", "verifymessage", verifymessage, {"address","signature","message"} }, | { "util", "verifymessage", verifymessage, {"address","signature","message"} }, | ||||
{ "util", "signmessagewithprivkey", signmessagewithprivkey, {"privkey","message"} }, | { "util", "signmessagewithprivkey", signmessagewithprivkey, {"privkey","message"} }, | ||||
{ "util", "getcurrencyinfo", getcurrencyinfo, {} }, | { "util", "getcurrencyinfo", getcurrencyinfo, {} }, | ||||
{ "util", "getindexinfo", getindexinfo, {"index_name"} }, | |||||
/* Not shown in help */ | /* Not shown in help */ | ||||
{ "hidden", "setmocktime", setmocktime, {"timestamp"}}, | { "hidden", "setmocktime", setmocktime, {"timestamp"}}, | ||||
{ "hidden", "mockscheduler", mockscheduler, {"delta_time"}}, | { "hidden", "mockscheduler", mockscheduler, {"delta_time"}}, | ||||
{ "hidden", "echo", echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | { "hidden", "echo", echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | ||||
{ "hidden", "echojson", echojson, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | { "hidden", "echojson", echojson, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | ||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
for (const auto &c : commands) { | for (const auto &c : commands) { | ||||
t.appendCommand(c.name, &c); | t.appendCommand(c.name, &c); | ||||
} | } | ||||
} | } |