5 #ifndef BITCOIN_RPC_UTIL_H
6 #define BITCOIN_RPC_UTIL_H
57 const std::list<UniValueType> &typesExpected,
58 bool fAllowNull =
false);
70 const std::map<std::string, UniValueType> &typesExpected,
71 bool fAllowNull =
false,
bool fStrict =
false);
83 using RPCArgList = std::vector<std::pair<std::string, UniValue>>;
85 const std::string &args);
89 const std::string &args);
96 const std::string &addr_in);
98 const std::vector<CPubKey> &pubkeys,
108 const std::string &err_string =
"");
199 const std::string description,
200 const std::string oneline_description =
"",
201 const std::vector<std::string> type_str = {},
202 const bool hidden =
false)
212 const std::string description,
const std::vector<RPCArg> inner,
213 const std::string oneline_description =
"",
214 const std::vector<std::string> type_str = {})
236 std::string
ToString(
bool oneline)
const;
275 const std::string key_name,
const bool optional,
276 const std::string description,
277 const std::vector<RPCResult> inner = {})
288 const std::string key_name,
const std::string description,
289 const std::vector<RPCResult> inner = {})
290 :
RPCResult{cond, type, key_name,
false, description, inner} {}
293 const std::string description,
294 const std::vector<RPCResult> inner = {})
304 const std::string description,
305 const std::vector<RPCResult> inner = {})
306 :
RPCResult{type, key_name,
false, description, inner} {}
310 const int current_indent = 0)
const;
324 RPCResults(std::initializer_list<RPCResult> results) : m_results{results} {}
329 std::string ToDescriptionString()
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
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.
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.
Implement std::hash so RCUPtr can be used as a key for maps or sets.
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< uint8_t > 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)
void RPCTypeCheckArgument(const UniValue &value, const UniValueType &typeExpected)
Type-check one argument; throws JSONRPCError if wrong type given.
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string="")
Amount AmountFromValue(const UniValue &value)
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull=false)
Type-check arguments; throws JSONRPCError if wrong type given.
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
std::vector< uint8_t > ParseHexO(const UniValue &o, std::string strKey)
const std::string EXAMPLE_ADDRESS
Example CashAddr address used in multiple RPCExamples.
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)
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::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)
const std::vector< RPCArg > m_inner
Only used for arrays or dicts.
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(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 std::string m_description
std::variant< Optional, DefaultHint, Default > Fallback
const std::vector< std::string > m_type_str
Should be empty unless it is supposed to override the auto-generated type strings.
std::string GetName() const
Return the name, throws when there are aliases.
std::string GetFirstName() const
Return the first of all aliases.
const std::string m_oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
std::string ToStringObj(bool oneline) const
Return the type string of the argument when it is in an object (dict).
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={})
std::string ToDescriptionString() const
Return the description string, including the argument type and whether the argument is required.
@ OMITTED_NAMED_ARG
Optional arg that is a named argument and has a default value of null.
@ OMITTED
Optional argument with default value omitted because they are implicitly clear.
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.
RPCResult(const Type type, const std::string key_name, const bool optional, const std::string description, const std::vector< RPCResult > inner={})
@ 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.
@ OBJ_EMPTY
Special type to allow empty OBJ.
const std::vector< RPCResult > m_inner
Only used for arrays or dicts.
RPCResult(const Type type, const std::string key_name, const std::string description, const std::vector< RPCResult > inner={})
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).
RPCResult(const std::string cond, const Type type, const std::string key_name, const bool optional, const std::string description, const std::vector< RPCResult > inner={})
RPCResult(const std::string cond, const Type type, const std::string key_name, const std::string description, const std::vector< RPCResult > inner={})
const std::string m_key_name
Only used for dicts.
bool MatchesType(const UniValue &result) const
Check whether the result JSON type matches.
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)