5#ifndef BITCOIN_RPC_UTIL_H
6#define BITCOIN_RPC_UTIL_H
70using RPCArgList = std::vector<std::pair<std::string, UniValue>>;
72 const std::string &args);
76 const std::string &args);
85 const std::vector<CPubKey> &pubkeys,
198 using Fallback = std::variant<Optional, DefaultHint, Default>;
221 std::string description, std::vector<RPCArg> inner,
289 std::string description, std::vector<RPCResult> inner = {})
299 std::string description, std::vector<RPCResult> inner = {})
305 std::string description, std::vector<RPCResult> inner = {},
306 bool skip_type_check =
false)
315 std::vector<RPCResult> inner = {},
bool skip_type_check =
false)
350 std::string ToDescriptionString()
const;
383 std::vector<std::pair<std::string, bool>>
GetArgNames()
const;
#define CHECK_NONFATAL(condition)
Identity function.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
An encapsulated public key.
Serialized script, used inside transaction inputs and outputs.
Fillable signing provider that keeps keys in an address->secret map.
const RPCExamples m_examples
const std::string m_description
bool IsValidNumArgs(size_t num_args) const
If the supplied number of args is neither too small nor too high.
std::function< UniValue(const RPCHelpMan &, const Config &config, const JSONRPCRequest &)> RPCMethodImpl
const RPCMethodImpl m_fun
const RPCResults m_results
UniValue HandleRequest(const Config &config, const JSONRPCRequest &request) const
const std::vector< RPCArg > m_args
std::string ToString() const
UniValue GetArgMap() const
Return the named args that need to be converted from string to another JSON type.
std::vector< std::pair< std::string, bool > > GetArgNames() const
Return list of arguments and whether they are named-only.
Implement std::hash so RCUPtr can be used as a key for maps or sets.
ServiceFlags
nServices flags.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
RPCErrorCode
Bitcoin RPC error codes.
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::vector< std::pair< std::string, UniValue > > RPCArgList
UniValue GetServicesNames(ServiceFlags services)
Returns, given services flags, a list of humanly readable (known) network services.
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FillableSigningProvider &keystore, CScript &script_out)
std::string HelpExampleRpcNamed(const std::string &methodname, const RPCArgList &args)
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string="")
static constexpr bool DEFAULT_RPC_DOC_CHECK
Amount AmountFromValue(const UniValue &value)
std::vector< uint8_t > ParseHexV(const UniValue &v, std::string strName)
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
const std::string EXAMPLE_ADDRESS
Example CashAddr address used in multiple RPCExamples.
OuterType
Serializing JSON objects depends on the outer type.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
std::vector< CScript > EvalDescriptorStringOrObject(const UniValue &scanobject, FlatSigningProvider &provider)
Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range ...
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull=false, bool fStrict=false)
Check for expected keys/value types in an Object.
std::string GetAllOutputTypes()
CPubKey HexToPubKey(const std::string &hex_in)
CPubKey AddrToPubKey(const CChainParams &chainparams, const FillableSigningProvider &keystore, const std::string &addr_in)
uint256 ParseHashO(const UniValue &o, std::string strKey)
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded values (throws error if not hex).
std::string HelpExampleCliNamed(const std::string &methodname, const RPCArgList &args)
UniValue DescribeAddress(const CTxDestination &dest)
std::vector< uint8_t > ParseHexO(const UniValue &o, std::string strKey)
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
@ RANGE
Special type that is a NUM or [NUM,NUM].
@ OBJ_USER_KEYS
Special type where the user must set the keys e.g.
@ 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
std::string ToString(bool oneline) const
Return the type string of the argument.
RPCArg(std::string name, Type type, Fallback fallback, std::string description, RPCArgOptions opts={})
UniValue MatchesType(const UniValue &request) const
Check whether the request JSON type matches.
const std::string m_description
std::string DefaultHint
Hint for default value.
std::variant< Optional, DefaultHint, Default > Fallback
std::string ToDescriptionString(bool is_named_arg) const
Return the description string, including the argument type and whether the argument is required.
RPCArg(std::string name, Type type, Fallback fallback, std::string description, std::vector< RPCArg > inner, RPCArgOptions opts={})
std::string GetName() const
Return the name, throws when there are aliases.
std::string GetFirstName() const
Return the first of all aliases.
std::string ToStringObj(bool oneline) const
Return the type string of the argument when it is in an object (dict).
@ OMITTED
The arg is optional 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.
std::string oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
bool also_positional
If set allows a named-parameter field in an OBJ_NAMED_PARAM options object to have the same name as a...
std::string ToDescriptionString() const
RPCExamples(std::string examples)
const std::string m_examples
const std::string m_description
void ToSections(Sections §ions, OuterType outer_type=OuterType::NONE, const int current_indent=0) const
Append the sections of the result.
@ ELISION
Special type to denote elision (...)
@ NUM_TIME
Special numeric to denote unix epoch time.
@ ANY
Special type to disable type checks (for testing only)
@ 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.
UniValue MatchesType(const UniValue &result) const
Check whether the result JSON type matches.
std::string ToDescriptionString() const
Return the description string, including the result type.
std::string ToStringObj() const
Return the type string of the result when it is in an object (dict).
void CheckInnerDoc() const
RPCResult(Type type, std::string key_name, std::string description, std::vector< RPCResult > inner={}, bool skip_type_check=false)
RPCResult(std::string cond, Type type, std::string key_name, std::string description, std::vector< RPCResult > inner={})
const std::string m_key_name
Only used for dicts.
RPCResult(std::string cond, Type type, std::string key_name, bool optional, std::string description, std::vector< RPCResult > inner={})
RPCResult(Type type, std::string key_name, bool optional, std::string description, std::vector< RPCResult > inner={}, bool skip_type_check=false)
const bool m_skip_type_check
RPCResults(RPCResult result)
const std::vector< RPCResult > m_results
RPCResults(std::initializer_list< RPCResult > results)
Keeps track of RPCArgs by transforming them into sections for the purpose of serializing everything t...
Wrapper for UniValue::VType, which includes typeAny: used to denote don't care type.
UniValueType(UniValue::VType _type)