5 #ifndef BITCOIN_RPC_UTIL_H
6 #define BITCOIN_RPC_UTIL_H
69 const std::map<std::string, UniValueType>& typesExpected,
70 bool fAllowNull =
false,
71 bool fStrict =
false);
91 using RPCArgList = std::vector<std::pair<std::string, UniValue>>;
165 using Fallback = std::variant<Optional, DefaultHint, Default>;
178 std::string description,
193 std::string description,
194 std::vector<RPCArg> inner,
224 std::string
ToString(
bool oneline)
const;
267 std::string description,
268 std::vector<RPCResult> inner = {})
269 :
m_type{std::move(type)},
285 std::string description,
286 std::vector<RPCResult> inner = {})
287 :
RPCResult{std::move(cond), type, std::move(
m_key_name),
false, std::move(description), std::move(inner)} {}
293 std::string description,
294 std::vector<RPCResult> inner = {},
295 bool skip_type_check =
false)
296 :
m_type{std::move(type)},
310 std::string description,
311 std::vector<RPCResult> inner = {},
312 bool skip_type_check =
false)
313 :
RPCResult{type, std::move(
m_key_name),
false, std::move(description), std::move(inner), skip_type_check} {}
346 std::string ToDescriptionString()
const;
352 std::string examples)
int64_t CAmount
Amount in satoshis (Can be negative)
#define CHECK_NONFATAL(condition)
Identity function.
An encapsulated public key.
Serialized script, used inside transaction inputs and outputs.
Fillable signing provider that keeps keys in an address->secret map.
std::function< UniValue(const RPCHelpMan &, const JSONRPCRequest &)> RPCMethodImpl
const RPCExamples m_examples
std::vector< std::string > GetArgNames() const
RPCHelpMan(std::string name, std::string description, std::vector< RPCArg > args, RPCResults results, RPCExamples 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.
const RPCMethodImpl m_fun
const RPCResults m_results
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.
UniValue HandleRequest(const JSONRPCRequest &request) const
ServiceFlags
nServices flags
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::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
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
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
OuterType
Serializing JSON objects depends on the outer type.
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 ...
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
CAmount AmountFromValue(const UniValue &value, int decimals=8)
Validate and return a CAmount from a UniValue number or string.
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)
std::string GetAllOutputTypes()
Gets all existing output types formatted for RPC help sections.
CPubKey HexToPubKey(const std::string &hex_in)
uint256 ParseHashO(const UniValue &o, std::string strKey)
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
unsigned int ParseConfirmTarget(const UniValue &value, unsigned int max_target)
Parse a confirm target option and raise an RPC error if it is invalid.
std::string HelpExampleCliNamed(const std::string &methodname, const RPCArgList &args)
CPubKey AddrToPubKey(const FillableSigningProvider &keystore, const std::string &addr_in)
UniValue DescribeAddress(const CTxDestination &dest)
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > 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. 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)
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
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....
std::string oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
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.
RPCResult(Type type, std::string m_key_name, bool optional, std::string description, std::vector< RPCResult > inner={}, bool skip_type_check=false)
RPCResult(Type type, std::string m_key_name, std::string description, std::vector< RPCResult > inner={}, bool skip_type_check=false)
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(std::string cond, Type type, std::string m_key_name, std::string description, std::vector< RPCResult > inner={})
RPCResult(std::string cond, Type type, std::string m_key_name, bool optional, std::string description, std::vector< RPCResult > inner={})
const std::string m_key_name
Only used for dicts.
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)