Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.cpp
Show First 20 Lines • Show All 277 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(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"help", | "help", | ||||
"\nList all commands, or get help for a specified command.\n", | "\nList all commands, or get help for a specified command.\n", | ||||
{ | { | ||||
{"command", RPCArg::Type::STR, /* opt */ true, | {"command", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", "The command to get help on"}, | /* default_val */ "", "The command to get help on"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"\"text\" (string) The help text\n"}, | ||||
"\nResult:\n" | RPCExamples{""}, | ||||
"\"text\" (string) The help text\n"); | } | ||||
.ToString()); | |||||
} | } | ||||
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( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"stop", "\nStop Bitcoin server.", {}}.ToString()); | "stop", | ||||
"\nStop Bitcoin server.", | |||||
{}, | |||||
RPCResults{}, | |||||
RPCExamples{""}, | |||||
} | |||||
.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( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | "uptime", | ||||
"uptime", "\nReturns the total uptime of the server.\n", {}} | "\nReturns the total uptime of the server.\n", | ||||
.ToString() + | {}, | ||||
"\nResult:\n" | RPCResult{"ttt (numeric) The number of seconds that the " | ||||
"ttt (numeric) The number of seconds " | "server has been running\n"}, | ||||
"that the server has been running\n" | RPCExamples{HelpExampleCli("uptime", "") + | ||||
"\nExamples:\n" + | HelpExampleRpc("uptime", "")}, | ||||
HelpExampleCli("uptime", "") + HelpExampleRpc("uptime", "")); | } | ||||
.ToString()); | |||||
} | } | ||||
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(RPCHelpMan{ | throw std::runtime_error(RPCHelpMan{ | ||||
"getrpcinfo", | "getrpcinfo", | ||||
"\nReturns details of the RPC server.\n", | "\nReturns details of the RPC server.\n", | ||||
{}}.ToString()); | {}, | ||||
RPCResults{}, | |||||
RPCExamples{""}, | |||||
} | |||||
.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 281 Lines • Show Last 20 Lines |