5 #ifndef BITCOIN_RPC_UTIL_H 6 #define BITCOIN_RPC_UTIL_H 70 const std::list<UniValueType>& typesExpected,
bool fAllowNull=
false);
81 const std::map<std::string, UniValueType>& typesExpected,
82 bool fAllowNull =
false,
83 bool fStrict =
false);
103 using RPCArgList = std::vector<std::pair<std::string, UniValue>>;
182 const std::string
name,
185 const std::string description,
186 const std::string oneline_description =
"",
187 const std::vector<std::string> type_str = {},
188 const bool hidden =
false)
201 const std::string
name,
204 const std::string description,
205 const std::vector<RPCArg> inner,
206 const std::string oneline_description =
"",
207 const std::vector<std::string> type_str = {})
232 std::string
ToString(
bool oneline)
const;
271 const std::string cond,
275 const std::string description,
276 const std::vector<RPCResult> inner = {})
277 :
m_type{std::move(type)},
290 const std::string cond,
293 const std::string description,
294 const std::vector<RPCResult> inner = {})
301 const std::string description,
302 const std::vector<RPCResult> inner = {},
303 bool skip_type_check =
false)
304 :
m_type{std::move(type)},
318 const std::string description,
319 const std::vector<RPCResult> inner = {},
320 bool skip_type_check =
false)
358 std::string examples)
369 using RPCMethodImpl = std::function<UniValue(const RPCHelpMan&, const JSONRPCRequest&)>;
390 #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)
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull=false)
Type-check arguments; throws JSONRPCError if wrong type given.
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< CScript > EvalDescriptorStringOrObject(const UniValue &scanobject, FlatSigningProvider &provider)
Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range ...
const Fallback m_fallback
ServiceFlags
nServices flags
std::vector< std::string > GetArgNames() const
void CheckInnerDoc() const
std::string ToDescriptionString() const
Return the description string.
uint256 ParseHashO(const UniValue &o, std::string strKey)
Keeps track of RPCArgs by transforming them into sections for the purpose of serializing everything t...
const std::string m_oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
RPCResult(const Type type, const std::string m_key_name, const bool optional, const std::string description, const std::vector< RPCResult > inner={}, bool skip_type_check=false)
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency...
CPubKey AddrToPubKey(const FillableSigningProvider &keystore, const std::string &addr_in)
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.
#define CHECK_NONFATAL(condition)
Identity function.
const std::string m_key_name
Only used for dicts.
std::string ToDescriptionString() const
const RPCExamples m_examples
RPCArg(const std::string name, const Type type, const Fallback fallback, const std::string description, const std::string oneline_description="", const std::vector< std::string > type_str={}, const bool hidden=false)
const RPCMethodImpl m_fun
RPCResult(const std::string cond, const Type type, const std::string m_key_name, const bool optional, const std::string description, const std::vector< RPCResult > inner={})
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.
void RPCTypeCheckArgument(const UniValue &value, const UniValueType &typeExpected)
Type-check one argument; throws JSONRPCError if wrong type given.
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)
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...
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)
bool MatchesType(const UniValue &result) const
Check whether the result JSON type matches.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
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
Optional arg that is a named argument and has a default value of null.
std::vector< std::pair< std::string, UniValue > > RPCArgList
const std::vector< std::string > m_type_str
Should be empty unless it is supposed to override the auto-generated type strings. Vector length is either 0 or 2, m_type_str.at(0) will override the type of the value in a key-value pair, m_type_str.at(1) will override the type in the argument description.
const RPCResults m_results
Special type that is a NUM or [NUM,NUM].
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 with default value omitted because they are implicitly clear.
std::string ToDescriptionString() const
Return the description string, including the argument type and whether the argument is required...
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)
RPCResult(const std::string cond, const Type type, const std::string m_key_name, const std::string description, const std::vector< RPCResult > inner={})
RPCResult(const Type type, const std::string m_key_name, const std::string description, const std::vector< RPCResult > inner={}, bool skip_type_check=false)
RPCArg(const std::string name, const Type type, const Fallback fallback, const std::string description, const std::vector< RPCArg > inner, const std::string oneline_description="", const std::vector< std::string > type_str={})
RPCExamples(std::string examples)
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.
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).