Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.cpp
Show First 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | std::string CRPCTable::help(Config &config, const std::string &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 UniValue help(Config &config, const JSONRPCRequest &jsonRequest) { | ||||
if (jsonRequest.fHelp || jsonRequest.params.size() > 1) { | if (jsonRequest.fHelp || jsonRequest.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"help ( \"command\" )\n" | RPCHelpMan{ | ||||
"\nList all commands, or get help for a specified command.\n" | "help", | ||||
"\nList all commands, or get help for a specified command.\n", | |||||
{ | |||||
{"command", RPCArg::Type::STR, true}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"command\" (string, optional) The command to get help on\n" | "1. \"command\" (string, optional) The command to get help on\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"text\" (string) The help text\n"); | "\"text\" (string) The help text\n"); | ||||
} | } | ||||
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 UniValue stop(const Config &config, const JSONRPCRequest &jsonRequest) { | ||||
// Accept the deprecated and ignored 'detach' boolean argument | // Accept the deprecated and ignored 'detach' boolean argument | ||||
// Also accept the hidden 'wait' integer argument (milliseconds) | // Also accept the hidden 'wait' integer argument (milliseconds) | ||||
// For instance, 'stop 1000' makes the call wait 1 second before returning | // For instance, 'stop 1000' makes the call wait 1 second before returning | ||||
// to the client (intended for testing) | // to the client (intended for testing) | ||||
if (jsonRequest.fHelp || jsonRequest.params.size() > 1) { | if (jsonRequest.fHelp || jsonRequest.params.size() > 1) { | ||||
throw std::runtime_error("stop\n" | throw std::runtime_error( | ||||
"\nStop Bitcoin server."); | RPCHelpMan{"stop", "\nStop Bitcoin server.", {}}.ToString()); | ||||
} | } | ||||
// Event loop will exit after current HTTP requests have been handled, so | // Event loop will exit after current HTTP requests have been handled, so | ||||
// this reply will get back to the client. | // this reply will get back to the client. | ||||
StartShutdown(); | StartShutdown(); | ||||
if (jsonRequest.params[0].isNum()) { | if (jsonRequest.params[0].isNum()) { | ||||
MilliSleep(jsonRequest.params[0].get_int()); | MilliSleep(jsonRequest.params[0].get_int()); | ||||
} | } | ||||
return "Bitcoin server stopping"; | return "Bitcoin server stopping"; | ||||
} | } | ||||
static UniValue uptime(const Config &config, | static UniValue uptime(const Config &config, | ||||
const JSONRPCRequest &jsonRequest) { | const JSONRPCRequest &jsonRequest) { | ||||
if (jsonRequest.fHelp || jsonRequest.params.size() > 0) { | if (jsonRequest.fHelp || jsonRequest.params.size() > 0) { | ||||
throw std::runtime_error("uptime\n" | throw std::runtime_error( | ||||
"\nReturns the total uptime of the server.\n" | RPCHelpMan{ | ||||
"uptime", "\nReturns the total uptime of the server.\n", {}} | |||||
.ToString() + | |||||
"\nResult:\n" | "\nResult:\n" | ||||
"ttt (numeric) The number of seconds " | "ttt (numeric) The number of seconds " | ||||
"that the server has been running\n" | "that the server has been running\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("uptime", "") + | HelpExampleCli("uptime", "") + HelpExampleRpc("uptime", "")); | ||||
HelpExampleRpc("uptime", "")); | |||||
} | } | ||||
return GetTime() - GetStartupTime(); | return GetTime() - GetStartupTime(); | ||||
} | } | ||||
static UniValue getrpcinfo(const Config &config, | static UniValue getrpcinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 0) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error("getrpcinfo\n" | throw std::runtime_error(RPCHelpMan{ | ||||
"\nReturns details of the RPC server.\n"); | "getrpcinfo", | ||||
"\nReturns details of the RPC server.\n", | |||||
{}}.ToString()); | |||||
} | } | ||||
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); | ||||
▲ Show 20 Lines • Show All 284 Lines • Show Last 20 Lines |