6#include <bitcoin-build-config.h>
36#include <unordered_map>
37#include <unordered_set>
64 std::list<RPCCommandExecutionInfo>::iterator
it;
82 std::vector<std::pair<std::string, const CRPCCommand*> >
vCommands;
86 vCommands.emplace_back(entry.second.front()->category + entry.first, entry.second.front());
94 std::string strMethod =
pcmd->name;
97 jreq.strMethod = strMethod;
107 if (
strHelp.find(
'\n') != std::string::npos)
110 if (category !=
pcmd->category)
112 if (!category.empty())
114 category =
pcmd->category;
131 "List all commands, or get help for a specified command.\n",
145 auto command{
self.MaybeArg<std::string_view>(
"command")};
146 if (
command ==
"dump_all_command_conversions") {
187 "Returns the total uptime of the server.\n",
207 "Returns details of the RPC server.\n",
232 entry.
pushKV(
"method", info.method);
256 for (
const auto& [key, value] : entries) {
275 std::unordered_set<std::string>
seen;
276 for (
const auto&
item : inner) {
294 std::unordered_set<std::string>
seen;
295 for (
const auto&
item : inner) {
362 schema =
MakeObject({{
"type",
"string"}, {
"pattern",
"^([0-9a-fA-F]{2})*$"}});
403 for (
const auto& inner : arg.m_inner) {
406 if (!inner.m_description.empty())
prop.
pushKV(
"description", inner.m_description);
407 if (inner.m_opts.placeholder)
prop.pushKV(
"x-bitcoin-placeholder",
true);
408 if (inner.m_opts.also_positional)
prop.pushKV(
"x-bitcoin-also-positional",
true);
410 if (!inner.IsOptional())
required.push_back(inner.GetFirstName());
412 schema.pushKV(
"type",
"object");
414 schema.pushKV(
"additionalProperties",
false);
419 schema.pushKV(
"type",
"object");
422 if (!arg.
m_inner[0].m_description.empty()) {
426 schema.pushKV(
"additionalProperties",
true);
461 return MakeObject({{
"type",
"number"}, {
"x-bitcoin-unit",
"amount"}});
463 return MakeObject({{
"type",
"string"}, {
"pattern",
"^([0-9a-fA-F]{2})*$"}});
469 schema.pushKV(
"x-bitcoin-unit",
"unix-time");
485 for (
const auto& inner : result.m_inner) {
491 schema.pushKV(
"additionalItems",
false);
499 for (
const auto& inner : result.m_inner) {
500 if (inner.m_key_name.empty())
continue;
502 if (!inner.m_description.empty())
prop.
pushKV(
"description", inner.m_description);
504 if (!inner.m_optional)
required.push_back(inner.m_key_name);
509 schema.pushKV(
"additionalProperties",
false);
556 {
RPCResult::Type::BOOL,
"x-bitcoin-placeholder",
true,
"Whether the parameter is retained only for compatibility."},
557 {
RPCResult::Type::BOOL,
"x-bitcoin-also-positional",
true,
"Whether the parameter can also be passed positionally."},
563 "\"x-bitcoin-unit\" property: \"amount\" which denotes a Bitcoin amount in BTC."},
568 {.skip_type_check =
true}};
575 "Returns an OpenRPC document for currently available RPC commands.\n",
596 "Returns an OpenRPC schema as a description of this service.\n",
638 auto new_end = std::remove(it->second.begin(), it->second.end(),
pcmd);
639 if (it->second.end() !=
new_end) {
640 it->second.erase(
new_end, it->second.end());
641 if (it->second.empty()) {
731 }
catch (
const std::exception&
e) {
753 std::unordered_map<std::string, const UniValue*>
argsIn;
754 for (
size_t i=0; i<
keys.size(); ++i) {
787 if (options.exists(
fr->first)) {
790 options.pushKVEnd(
fr->first, *
fr->second);
796 if (!options.empty() ||
fr !=
argsIn.end()) {
797 for (
int i = 0; i <
hole; ++i) {
814 if (!options.empty()) {
817 out.params.push_back(*
fr->second);
820 if (!options.empty()) {
821 out.params.push_back(std::move(options));
837 for (
size_t i{out.params.size()}; i <
named_args.size(); ++i) {
891 }
catch (
const std::exception&
e) {
908 if (
cmds.empty())
continue;
921 for (
const auto& arg :
helpman.GetArgs()) {
928 std::vector<std::string>
names{SplitString(arg.
m_names,
'|')};
929 if (
names.size() > 1) {
932 param.pushKV(
"x-bitcoin-aliases", std::move(
aliases));
937 params.push_back(std::move(param));
944 }
else if (
results.size() > 1) {
946 for (
const auto& r :
results) {
949 if (!r.m_cond.empty())
schema.
pushKV(
"description", r.m_cond);
954 }
else if (
one_of.size() > 1) {
962 method.pushKV(
"params", std::move(params));
964 result.pushKV(
"name",
"result");
966 method.pushKV(
"result", std::move(result));
967 method.pushKV(
"x-bitcoin-category",
cmd->category);
968 methods.push_back(std::move(method));
976 info.pushKV(
"version", version);
977 info.pushKV(
"description",
"Autogenerated from " CLIENT_NAME " RPC metadata.");
980 doc.pushKV(
"openrpc",
"1.4.1");
981 doc.pushKV(
"info", std::move(info));
982 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)
@ 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.