Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.cpp
Show First 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | std::string CRPCTable::help(Config &config, const std::string &strCommand, | ||||
if (strRet == "") { | if (strRet == "") { | ||||
strRet = strprintf("help: unknown command: %s\n", strCommand); | strRet = strprintf("help: unknown command: %s\n", strCommand); | ||||
} | } | ||||
strRet = strRet.substr(0, strRet.size() - 1); | strRet = strRet.substr(0, strRet.size() - 1); | ||||
return strRet; | return strRet; | ||||
} | } | ||||
static UniValue help(Config &config, const JSONRPCRequest &jsonRequest) { | static RPCHelpMan help() { | ||||
if (jsonRequest.fHelp || jsonRequest.params.size() > 1) { | return RPCHelpMan{ | ||||
throw std::runtime_error(RPCHelpMan{ | |||||
"help", | "help", | ||||
"List all commands, or get help for a specified command.\n", | "List all commands, or get help for a specified command.\n", | ||||
{ | { | ||||
{"command", RPCArg::Type::STR, /* default */ "all commands", | {"command", RPCArg::Type::STR, /* default */ "all commands", | ||||
"The command to get help on"}, | "The command to get help on"}, | ||||
}, | }, | ||||
RPCResult{RPCResult::Type::STR, "", "The help text"}, | RPCResult{RPCResult::Type::STR, "", "The help text"}, | ||||
RPCExamples{""}, | RPCExamples{""}, | ||||
} | [&](const RPCHelpMan &self, Config &config, | ||||
.ToString()); | const JSONRPCRequest &jsonRequest) -> UniValue { | ||||
} | |||||
std::string strCommand; | std::string strCommand; | ||||
if (jsonRequest.params.size() > 0) { | if (jsonRequest.params.size() > 0) { | ||||
strCommand = jsonRequest.params[0].get_str(); | strCommand = jsonRequest.params[0].get_str(); | ||||
} | } | ||||
return tableRPC.help(config, strCommand, jsonRequest); | return tableRPC.help(config, strCommand, jsonRequest); | ||||
}, | |||||
}; | |||||
} | } | ||||
static UniValue stop(const Config &config, const JSONRPCRequest &jsonRequest) { | static RPCHelpMan stop() { | ||||
static const std::string RESULT{PACKAGE_NAME " stopping"}; | static const std::string RESULT{PACKAGE_NAME " stopping"}; | ||||
// Accept the deprecated and ignored 'detach' boolean argument | return RPCHelpMan{ | ||||
// Also accept the hidden 'wait' integer argument (milliseconds) | |||||
// For instance, 'stop 1000' makes the call wait 1 second before returning | |||||
// to the client (intended for testing) | |||||
if (jsonRequest.fHelp || jsonRequest.params.size() > 1) { | |||||
throw std::runtime_error(RPCHelpMan{ | |||||
"stop", | "stop", | ||||
// Also accept the hidden 'wait' integer argument (milliseconds) | |||||
// For instance, 'stop 1000' makes the call wait 1 second before | |||||
// returning to the client (intended for testing) | |||||
"\nRequest a graceful shutdown of " PACKAGE_NAME ".", | "\nRequest a graceful shutdown of " PACKAGE_NAME ".", | ||||
{ | |||||
{"wait", | |||||
RPCArg::Type::NUM, | |||||
RPCArg::Optional::OMITTED_NAMED_ARG, | |||||
"how long to wait in ms", | |||||
"", | |||||
{}, | {}, | ||||
/* hidden */ true}, | |||||
}, | |||||
RPCResult{RPCResult::Type::STR, "", | RPCResult{RPCResult::Type::STR, "", | ||||
"A string with the content '" + RESULT + "'"}, | "A string with the content '" + RESULT + "'"}, | ||||
RPCExamples{""}, | RPCExamples{""}, | ||||
} | [&](const RPCHelpMan &self, Config &config, | ||||
.ToString()); | const JSONRPCRequest &jsonRequest) -> UniValue { | ||||
} | // Event loop will exit after current HTTP requests have been | ||||
// handled, so this reply will get back to the client. | |||||
// Event loop will exit after current HTTP requests have been handled, so | |||||
// this reply will get back to the client. | |||||
StartShutdown(); | StartShutdown(); | ||||
if (jsonRequest.params[0].isNum()) { | if (jsonRequest.params[0].isNum()) { | ||||
UninterruptibleSleep( | UninterruptibleSleep( | ||||
std::chrono::milliseconds{jsonRequest.params[0].get_int()}); | std::chrono::milliseconds{jsonRequest.params[0].get_int()}); | ||||
} | } | ||||
return RESULT; | return RESULT; | ||||
}, | |||||
}; | |||||
} | } | ||||
static UniValue uptime(const Config &config, const JSONRPCRequest &request) { | static RPCHelpMan uptime() { | ||||
RPCHelpMan{ | return RPCHelpMan{ | ||||
"uptime", | "uptime", | ||||
"Returns the total uptime of the server.\n", | "Returns the total uptime of the server.\n", | ||||
{}, | {}, | ||||
RPCResult{RPCResult::Type::NUM, "", | RPCResult{RPCResult::Type::NUM, "", | ||||
"The number of seconds that the server has been running"}, | "The number of seconds that the server has been running"}, | ||||
RPCExamples{HelpExampleCli("uptime", "") + | RPCExamples{HelpExampleCli("uptime", "") + | ||||
HelpExampleRpc("uptime", "")}, | HelpExampleRpc("uptime", "")}, | ||||
} | [&](const RPCHelpMan &self, Config &config, | ||||
.Check(request); | const JSONRPCRequest &request) -> UniValue { | ||||
return GetTime() - GetStartupTime(); | return GetTime() - GetStartupTime(); | ||||
}}; | |||||
} | } | ||||
static UniValue getrpcinfo(const Config &config, | static RPCHelpMan getrpcinfo() { | ||||
const JSONRPCRequest &request) { | return RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"getrpcinfo", | "getrpcinfo", | ||||
"Returns details of the RPC server.\n", | "Returns details of the RPC server.\n", | ||||
{}, | {}, | ||||
RPCResult{RPCResult::Type::OBJ, | RPCResult{RPCResult::Type::OBJ, | ||||
"", | "", | ||||
"", | "", | ||||
{ | { | ||||
{RPCResult::Type::ARR, | {RPCResult::Type::ARR, | ||||
Show All 10 Lines | return RPCHelpMan{ | ||||
"The running time in microseconds"}, | "The running time in microseconds"}, | ||||
}}, | }}, | ||||
}}, | }}, | ||||
{RPCResult::Type::STR, "logpath", | {RPCResult::Type::STR, "logpath", | ||||
"The complete file path to the debug log"}, | "The complete file path to the debug log"}, | ||||
}}, | }}, | ||||
RPCExamples{HelpExampleCli("getrpcinfo", "") + | RPCExamples{HelpExampleCli("getrpcinfo", "") + | ||||
HelpExampleRpc("getrpcinfo", "")}, | HelpExampleRpc("getrpcinfo", "")}, | ||||
} | |||||
.Check(request); | |||||
[&](const RPCHelpMan &self, Config &config, | |||||
const JSONRPCRequest &request) -> UniValue { | |||||
LOCK(g_rpc_server_info.mutex); | LOCK(g_rpc_server_info.mutex); | ||||
UniValue active_commands(UniValue::VARR); | UniValue active_commands(UniValue::VARR); | ||||
for (const RPCCommandExecutionInfo &info : | for (const RPCCommandExecutionInfo &info : | ||||
g_rpc_server_info.active_commands) { | g_rpc_server_info.active_commands) { | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
entry.pushKV("method", info.method); | entry.pushKV("method", info.method); | ||||
entry.pushKV("duration", GetTimeMicros() - info.start); | entry.pushKV("duration", GetTimeMicros() - info.start); | ||||
active_commands.push_back(entry); | active_commands.push_back(entry); | ||||
} | } | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.pushKV("active_commands", active_commands); | result.pushKV("active_commands", active_commands); | ||||
const std::string path = LogInstance().m_file_path.string(); | const std::string path = LogInstance().m_file_path.string(); | ||||
UniValue log_path(UniValue::VSTR, path); | UniValue log_path(UniValue::VSTR, path); | ||||
result.pushKV("logpath", log_path); | result.pushKV("logpath", log_path); | ||||
return result; | return result; | ||||
}}; | |||||
} | } | ||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand vRPCCommands[] = { | static const CRPCCommand vRPCCommands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
/* Overall control/query calls */ | /* Overall control/query calls */ | ||||
{ "control", "getrpcinfo", getrpcinfo, {} }, | { "control", "getrpcinfo", getrpcinfo, {} }, | ||||
▲ Show 20 Lines • Show All 276 Lines • Show Last 20 Lines |