6#include <bitcoin-build-config.h>
36#include <unordered_map>
37#include <unordered_set>
65 std::list<RPCCommandExecutionInfo>::iterator
it;
83 std::vector<std::pair<std::string, const CRPCCommand*> >
vCommands;
87 vCommands.emplace_back(entry.second.front()->category + entry.first, entry.second.front());
95 std::string strMethod =
pcmd->name;
98 jreq.strMethod = strMethod;
108 if (
strHelp.find(
'\n') != std::string::npos)
111 if (category !=
pcmd->category)
113 if (!category.empty())
115 category =
pcmd->category;
132 "List all commands, or get help for a specified command.\n",
146 auto command{
self.MaybeArg<std::string_view>(
"command")};
147 if (
command ==
"dump_all_command_conversions") {
188 "Returns the total uptime of the server.\n",
208 "Returns details of the RPC server.\n",
233 entry.
pushKV(
"method", info.method);
257 for (
const auto& [key, value] : entries) {
276 std::unordered_set<std::string>
seen;
277 for (
const auto&
item : inner) {
295 std::unordered_set<std::string>
seen;
296 for (
const auto&
item : inner) {
363 schema =
MakeObject({{
"type",
"string"}, {
"pattern",
"^([0-9a-fA-F]{2})*$"}});
404 for (
const auto& inner : arg.m_inner) {
407 if (!inner.m_description.empty())
prop.
pushKV(
"description", inner.m_description);
408 if (inner.m_opts.placeholder)
prop.pushKV(
"x-bitcoin-placeholder",
true);
409 if (inner.m_opts.also_positional)
prop.pushKV(
"x-bitcoin-also-positional",
true);
411 if (!inner.IsOptional())
required.push_back(inner.GetFirstName());
413 schema.pushKV(
"type",
"object");
415 schema.pushKV(
"additionalProperties",
false);
420 schema.pushKV(
"type",
"object");
423 if (!arg.
m_inner[0].m_description.empty()) {
427 schema.pushKV(
"additionalProperties",
true);
462 return MakeObject({{
"type",
"number"}, {
"x-bitcoin-unit",
"amount"}});
464 return MakeObject({{
"type",
"string"}, {
"pattern",
"^([0-9a-fA-F]{2})*$"}});
470 schema.pushKV(
"x-bitcoin-unit",
"unix-time");
486 for (
const auto& inner : result.m_inner) {
492 schema.pushKV(
"additionalItems",
false);
500 for (
const auto& inner : result.m_inner) {
501 if (inner.m_key_name.empty())
continue;
503 if (!inner.m_description.empty())
prop.
pushKV(
"description", inner.m_description);
505 if (!inner.m_optional)
required.push_back(inner.m_key_name);
510 schema.pushKV(
"additionalProperties",
false);
557 {
RPCResult::Type::BOOL,
"x-bitcoin-placeholder",
true,
"Whether the parameter is retained only for compatibility."},
558 {
RPCResult::Type::BOOL,
"x-bitcoin-also-positional",
true,
"Whether the parameter can also be passed positionally."},
564 "\"x-bitcoin-unit\" property: \"amount\" which denotes a Bitcoin amount in BTC."},
569 {.skip_type_check =
true}};
576 "Returns an OpenRPC document for currently available RPC commands.\n",
597 "Returns an OpenRPC schema as a description of this service.\n",
639 if (std::erase(it->second,
pcmd)) {
640 if (it->second.empty()) {
730 }
catch (
const std::exception&
e) {
752 std::unordered_map<std::string, const UniValue*>
argsIn;
753 for (
size_t i=0; i<
keys.size(); ++i) {
786 if (options.exists(
fr->first)) {
789 options.pushKVEnd(
fr->first, *
fr->second);
795 if (!options.empty() ||
fr !=
argsIn.end()) {
796 for (
int i = 0; i <
hole; ++i) {
813 if (!options.empty()) {
816 out.params.push_back(*
fr->second);
819 if (!options.empty()) {
820 out.params.push_back(std::move(options));
836 for (
size_t i{out.params.size()}; i <
named_args.size(); ++i) {
890 }
catch (
const std::exception&
e) {
907 if (
cmds.empty())
continue;
920 for (
const auto& arg :
helpman.GetArgs()) {
927 std::vector<std::string>
names{SplitString(arg.
m_names,
'|')};
928 if (
names.size() > 1) {
931 param.pushKV(
"x-bitcoin-aliases", std::move(
aliases));
936 params.push_back(std::move(param));
943 }
else if (
results.size() > 1) {
945 for (
const auto& r :
results) {
948 if (!r.m_cond.empty())
schema.
pushKV(
"description", r.m_cond);
953 }
else if (
one_of.size() > 1) {
961 method.pushKV(
"params", std::move(params));
963 result.pushKV(
"name",
"result");
965 method.pushKV(
"result", std::move(result));
966 method.pushKV(
"x-bitcoin-category",
cmd->category);
967 methods.push_back(std::move(method));
975 info.pushKV(
"version", version);
976 info.pushKV(
"description",
"Autogenerated from " CLIENT_NAME " RPC metadata.");
979 doc.pushKV(
"openrpc",
"1.4.1");
980 doc.pushKV(
"info", std::move(info));
981 doc.pushKV(
"methods", std::move(
methods));
#define CHECK_NONFATAL(condition)
Identity function.
#define NONFATAL_UNREACHABLE()
NONFATAL_UNREACHABLE() is a macro that is used to mark unreachable code.
std::vector< std::string > GetArgs(const std::string &strArg) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return a vector of strings of the given argument.
std::map< std::string, std::vector< const CRPCCommand * > > mapCommands
bool removeCommand(const std::string &name, const CRPCCommand *pcmd)
std::string help(std::string_view name, const JSONRPCRequest &helpreq) const
std::vector< std::string > listCommands() const
Returns a list of registered commands.
UniValue buildOpenRPCDoc(bool include_hidden=false) const
Return a complete OpenRPC 1.4.1 document for registered commands.
UniValue execute(const JSONRPCRequest &request) const
Execute a method.
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
UniValue dumpArgMap(const JSONRPCRequest &request) const
Return all named arguments that need to be converted by the client from string to another JSON type.
Different type to mark Mutex at global scope.
enum JSONRPCRequest::Mode mode
void push_back(UniValue val)
const std::vector< UniValue > & getValues() const
const std::vector< std::string > & getKeys() const
void pushKV(std::string key, UniValue val)
SteadyClock::duration GetUptime()
Monotonic uptime (not affected by system time changes).
#define LogDebug(category,...)
BCLog::Logger & LogInstance()
std::vector< std::string > SplitString(std::string_view str, char sep)
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
UniValue JSONRPCError(int code, const std::string &message)
UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional< UniValue > id, JSONRPCVersion jsonrpc_version)
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
@ RPC_MISC_ERROR
General application defined errors.
@ RPC_TYPE_ERROR
Unexpected type was passed as parameter.
@ RPC_CLIENT_NOT_CONNECTED
P2P client errors.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_IN_WARMUP
Client still warming up.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
static const CRPCCommand vRPCCommands[]
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
bool IsDeprecatedRPCEnabled(const std::string &method)
void SetRPCWarmupFinished()
static bool ExecuteCommands(const std::vector< const CRPCCommand * > &commands, const JSONRPCRequest &request, UniValue &result)
static RPCResult OpenRPCDocResult()
bool RPCIsInWarmup(std::string *outStatus)
static bool ExecuteCommand(const CRPCCommand &command, const JSONRPCRequest &request, UniValue &result, bool last_handler)
static std::atomic< bool > g_rpc_running
static JSONRPCRequest transformNamedArguments(const JSONRPCRequest &in, const std::vector< std::pair< std::string, bool > > &argNames)
Process named arguments into a vector of positional arguments, based on the passed-in specification f...
bool IsRPCRunning()
Query whether RPC is running.
void SetRPCWarmupStarting()
static RPCMethod getrpcinfo()
UniValue JSONRPCExec(const JSONRPCRequest &jreq, bool catch_errors)
static RPCMethod getopenrpcinfo()
static GlobalMutex g_rpc_warmup_mutex
static RPCMethod uptime()
static RPCServerInfo g_rpc_server_info
static RPCMethod rpc_discover()
static const CRPCCommand vRPCCommands[]
void SetRPCWarmupStatus(const std::string &newStatus)
Set the RPC warmup status.
void RpcInterruptionPoint()
Throw JSONRPCError if RPC is not running.
bool IsRPCRunning()
Query whether RPC is running.
NodeContext & EnsureAnyNodeContext(const std::any &context)
Utilities for converting data from/to strings.
@ RANGE
Special type that is a NUM or [NUM,NUM].
@ OBJ_USER_KEYS
Special type where the user must set the keys e.g. to define multiple addresses; as opposed to e....
@ STR_HEX
Special type that is a STR with only hex chars.
@ AMOUNT
Special type representing a floating point amount (can be either NUM or STR)
@ OBJ_NAMED_PARAMS
Special type that behaves almost exactly like OBJ, defining an options object with a list of pre-defi...
const std::vector< RPCArg > m_inner
Only used for arrays or dicts.
const RPCArgOptions m_opts
const std::string m_names
The name of the arg (can be empty for inner args, can contain multiple aliases separated by | for nam...
const Fallback m_fallback
const std::string m_description
std::string DefaultHint
Hint for default value.
std::string GetFirstName() const
Return the first of all aliases.
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
bool hidden
For testing only.
std::vector< std::string > type_str
Should be empty unless it is supposed to override the auto-generated type strings....
bool also_positional
If set allows a named-parameter field in an OBJ_NAMED_PARAM options object to have the same name as a...
bool placeholder
If set, the argument is retained only for compatibility and should generally be omitted.
RPCCommandExecution(const std::string &method)
std::list< RPCCommandExecutionInfo >::iterator it
SteadyClock::time_point start
@ NUM_TIME
Special numeric to denote unix epoch time.
@ ANY
Special type to disable type checks.
@ ARR_FIXED
Special array that has a fixed number of entries.
@ OBJ_DYN
Special dictionary with keys that are not literals.
@ STR_HEX
Special string with only hex chars.
@ STR_AMOUNT
Special string to represent a floating point amount.
const std::vector< RPCResult > m_inner
Only used for arrays or dicts.
const RPCResultOptions m_opts
const std::string m_key_name
Only used for dicts.
HelpElision print_elision
std::list< RPCCommandExecutionInfo > active_commands GUARDED_BY(mutex)
Overloaded helper for std::visit.
std::vector< uint16_t > keys
consteval auto _(util::TranslatedLiteral str)
const UniValue NullUniValue
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
void UninterruptibleSleep(const std::chrono::microseconds &n)
constexpr int64_t TicksSeconds(Duration d)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.