5 #ifndef BITCOIN_RPC_UTIL_H 6 #define BITCOIN_RPC_UTIL_H 25 #include <initializer_list> 29 #include <type_traits> 86 const std::map<std::string, UniValueType>& typesExpected,
87 bool fAllowNull =
false,
88 bool fStrict =
false);
108 using RPCArgList = std::vector<std::pair<std::string, UniValue>>;
201 using Fallback = std::variant<Optional, DefaultHint, Default>;
214 std::string description,
229 std::string description,
230 std::vector<RPCArg> inner,
260 std::string
ToString(
bool oneline)
const;
303 std::string description,
304 std::vector<RPCResult> inner = {})
305 :
m_type{std::move(type)},
321 std::string description,
322 std::vector<RPCResult> inner = {})
323 :
RPCResult{std::move(cond), type, std::move(
m_key_name),
false, std::move(description), std::move(inner)} {}
329 std::string description,
330 std::vector<RPCResult> inner = {},
331 bool skip_type_check =
false)
332 :
m_type{std::move(type)},
346 std::string description,
347 std::vector<RPCResult> inner = {},
348 bool skip_type_check =
false)
349 :
RPCResult{type, std::move(
m_key_name),
false, std::move(description), std::move(inner), skip_type_check} {}
388 std::string examples)
399 using RPCMethodImpl = std::function<UniValue(const RPCHelpMan&, const JSONRPCRequest&)>;
417 template <
typename R>
421 if constexpr (std::is_integral_v<R> || std::is_floating_point_v<R>) {
423 return ArgValue<R>(i);
426 return ArgValue<const R&>(i);
429 template <
typename R>
433 if constexpr (std::is_integral_v<R> || std::is_floating_point_v<R>) {
435 return ArgValue<std::optional<R>>(i);
438 return ArgValue<const R*>(i);
447 std::vector<std::pair<std::string, bool>>
GetArgNames()
const;
458 template <
typename R>
471 #endif // BITCOIN_RPC_UTIL_H UniValue DescribeAddress(const CTxDestination &dest)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
UniValueType(UniValue::VType _type)
static const std::string sighash
CAmount AmountFromValue(const UniValue &value, int decimals=8)
Validate and return a CAmount from a UniValue number or string.
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
const std::vector< RPCResult > m_inner
Only used for arrays or dicts.
std::vector< std::string > type_str
Should be empty unless it is supposed to override the auto-generated type strings. Vector length is either 0 or 2, m_opts.type_str.at(0) will override the type of the value in a key-value pair, m_opts.type_str.at(1) will override the type in the argument description.
RPCArg(std::string name, Type type, Fallback fallback, std::string description, std::vector< RPCArg > inner, RPCArgOptions opts={})
const Fallback m_fallback
ServiceFlags
nServices flags
void CheckInnerDoc() const
std::string ToDescriptionString() const
Return the description string.
uint256 ParseHashO(const UniValue &o, std::string strKey)
const RPCArgOptions m_opts
auto Arg(size_t i) const
Helper to get a request argument.
std::vector< CScript > EvalDescriptorStringOrObject(const UniValue &scanobject, FlatSigningProvider &provider, const bool expand_priv=false)
Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range ...
RPCResult(Type type, std::string m_key_name, bool optional, std::string description, std::vector< RPCResult > inner={}, bool skip_type_check=false)
Keeps track of RPCArgs by transforming them into sections for the purpose of serializing everything t...
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency...
bool also_positional
If set allows a named-parameter field in an OBJ_NAMED_PARAM options object to have the same name as a...
CPubKey AddrToPubKey(const FillableSigningProvider &keystore, const std::string &addr_in)
bool hidden
For testing only.
R ArgValue(size_t i) const
CPubKey HexToPubKey(const std::string &hex_in)
std::string GetAllOutputTypes()
Gets all existing output types formatted for RPC help sections.
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
static constexpr bool DEFAULT_RPC_DOC_CHECK
void ToSections(Sections §ions, OuterType outer_type=OuterType::NONE, const int current_indent=0) const
Append the sections of the result.
RPCArg(std::string name, Type type, Fallback fallback, std::string description, RPCArgOptions opts={})
#define CHECK_NONFATAL(condition)
Identity function.
Special type that behaves almost exactly like OBJ, defining an options object with a list of pre-defi...
int ParseSighashString(const UniValue &sighash)
Parse a sighash string representation and raise an RPC error if it is invalid.
const std::string m_key_name
Only used for dicts.
std::string ToDescriptionString() const
RPCResult(std::string cond, Type type, std::string m_key_name, std::string description, std::vector< RPCResult > inner={})
std::vector< std::pair< std::string, bool > > GetArgNames() const
Return list of arguments and whether they are named-only.
const RPCExamples m_examples
const RPCMethodImpl m_fun
bool IsValidNumArgs(size_t num_args) const
If the supplied number of args is neither too small nor too high.
UniValue GetArgMap() const
Return the named args that need to be converted from string to another JSON type. ...
std::string ToStringObj() const
Return the type string of the result when it is in an object (dict).
std::string ToString() const
const bool m_skip_type_check
const std::vector< RPCArg > m_inner
Only used for arrays or dicts.
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
const std::string m_description
int64_t CAmount
Amount in satoshis (Can be negative)
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull=false, bool fStrict=false)
std::string oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
void PushWarnings(const UniValue &warnings, UniValue &obj)
Push warning messages to an RPC "warnings" field as a JSON array of strings.
Special type that is a STR with only hex chars.
std::string GetName() const
Return the name, throws when there are aliases.
Special string with only hex chars.
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FillableSigningProvider &keystore, CScript &script_out)
Special array that has a fixed number of entries.
RPCResults(std::initializer_list< RPCResult > results)
An encapsulated public key.
Fillable signing provider that keeps keys in an address->secret map.
const std::string m_names
The name of the arg (can be empty for inner args, can contain multiple aliases separated by | for nam...
RPCResult(Type type, std::string m_key_name, std::string description, std::vector< RPCResult > inner={}, bool skip_type_check=false)
Special type where the user must set the keys e.g. to define multiple addresses; as opposed to e...
Special type to disable type checks (for testing only)
UniValue GetServicesNames(ServiceFlags services)
Returns, given services flags, a list of humanly readable (known) network services.
std::function< UniValue(const RPCHelpMan &, const JSONRPCRequest &)> RPCMethodImpl
unsigned int ParseConfirmTarget(const UniValue &value, unsigned int max_target)
Parse a confirm target option and raise an RPC error if it is invalid.
const std::vector< RPCResult > m_results
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
std::string DefaultHint
Hint for default value.
std::string GetFirstName() const
Return the first of all aliases.
const std::vector< RPCArg > m_args
const std::string m_description
Special numeric to denote unix epoch time.
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string="")
const std::string m_examples
const JSONRPCRequest * m_req
std::vector< std::pair< std::string, UniValue > > RPCArgList
const RPCResults m_results
Special type that is a NUM or [NUM,NUM].
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
std::variant< Optional, DefaultHint, Default > Fallback
OuterType
Serializing JSON objects depends on the outer type.
RPCHelpMan(std::string name, std::string description, std::vector< RPCArg > args, RPCResults results, RPCExamples examples)
Optional argument for which the default value is omitted from help text for one of two reasons: ...
Special string to represent a floating point amount.
Serialized script, used inside transaction inputs and outputs.
std::string HelpExampleRpcNamed(const std::string &methodname, const RPCArgList &args)
const std::string m_description
Special type representing a floating point amount (can be either NUM or STR)
std::string HelpExampleCliNamed(const std::string &methodname, const RPCArgList &args)
RPCResults(RPCResult result)
UniValue MatchesType(const UniValue &request) const
Check whether the request JSON type matches.
auto MaybeArg(size_t i) const
UniValue MatchesType(const UniValue &result) const
Check whether the result JSON type matches.
RPCExamples(std::string examples)
std::string ToDescriptionString(bool is_named_arg) const
Return the description string, including the argument type and whether the argument is required...
RPCErrorCode
Bitcoin RPC error codes.
Special dictionary with keys that are not literals.
UniValue HandleRequest(const JSONRPCRequest &request) const
std::string ToString(bool oneline) const
Return the type string of the argument.
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
RPCResult(std::string cond, Type type, std::string m_key_name, bool optional, std::string description, std::vector< RPCResult > inner={})
Special type to denote elision (...)
std::string ToDescriptionString() const
Return the description string, including the result type.
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
std::string ToStringObj(bool oneline) const
Return the type string of the argument when it is in an object (dict).