5 #ifndef BITCOIN_RPC_UTIL_H 6 #define BITCOIN_RPC_UTIL_H 24 #include <initializer_list> 28 #include <string_view> 29 #include <type_traits> 94 const std::map<std::string, UniValueType>& typesExpected,
95 bool fAllowNull =
false,
96 bool fStrict =
false);
105 std::vector<unsigned char>
ParseHexO(
const UniValue& o, std::string_view strKey);
132 using RPCArgList = std::vector<std::pair<std::string, UniValue>>;
223 using Fallback = std::variant<Optional, DefaultHint, Default>;
236 std::string description,
251 std::string description,
252 std::vector<RPCArg> inner,
282 std::string
ToString(
bool oneline)
const;
326 std::string description,
327 std::vector<RPCResult> inner = {})
328 :
m_type{std::move(type)},
344 std::string description,
345 std::vector<RPCResult> inner = {})
346 :
RPCResult{std::move(cond), type, std::move(
m_key_name),
false, std::move(description), std::move(inner)} {}
352 std::string description,
353 std::vector<RPCResult> inner = {},
354 bool skip_type_check =
false)
355 :
m_type{std::move(type)},
369 std::string description,
370 std::vector<RPCResult> inner = {},
371 bool skip_type_check =
false)
372 :
RPCResult{type, std::move(
m_key_name),
false, std::move(description), std::move(inner), skip_type_check} {}
411 std::string examples)
422 using RPCMethodImpl = std::function<UniValue(const RPCHelpMan&, const JSONRPCRequest&)>;
443 template <
typename R>
444 auto Arg(std::string_view key)
const 448 if constexpr (std::is_trivially_copyable_v<R>) {
450 return ArgValue<R>(i);
453 return ArgValue<const R&>(i);
475 template <
typename R>
480 if constexpr (std::is_trivially_copyable_v<R>) {
482 return ArgValue<std::optional<R>>(i);
485 return ArgValue<const R*>(i);
494 std::vector<std::pair<std::string, bool>>
GetArgNames()
const;
505 template <
typename R>
532 #endif // BITCOIN_RPC_UTIL_H UniValue DescribeAddress(const CTxDestination &dest)
char const * json() noexcept
Template to generate JSON data.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
UniValueType(UniValue::VType _type)
size_t GetParamIndex(std::string_view key) const
Return positional index of a parameter using its name as key.
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string_view strKey)
CAmount AmountFromValue(const UniValue &value, int decimals=8)
Validate and return a CAmount from a UniValue number or string.
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
UniValue JSONRPCTransactionError(node::TransactionError terr, const std::string &err_string="")
void CheckInnerDoc() const
std::string ToDescriptionString() const
Return the description string.
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
const RPCArgOptions m_opts
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...
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
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...
const std::string m_key_name
Only used for dicts.
std::string ToDescriptionString() const
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string_view name)
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. ...
void ToSections(Sections §ions, OuterType outer_type=OuterType::NONE, int current_indent=0) const
Append the sections of the result.
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
std::optional< int > ParseSighashString(const UniValue &sighash)
Parse a sighash string representation and raise an RPC error if it is invalid.
const std::vector< RPCArg > m_inner
Only used for arrays or dicts.
RPCErrorCode RPCErrorFromTransactionError(node::TransactionError terr)
std::vector< CScript > EvalDescriptorStringOrObject(const UniValue &scanobject, FlatSigningProvider &provider, bool expand_priv=false)
Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range ...
const std::string m_description
CFeeRate ParseFeeRate(const UniValue &json)
Parse a json number or string, denoting BTC/kvB, into a CFeeRate (sat/kvB).
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.
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)
std::vector< RPCResult > ScriptPubKeyDoc()
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)
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.
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< 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)
HelpResult(const std::string &msg)
Optional argument for which the default value is omitted from help text for one of two reasons: ...
UniValue JSONRPCPSBTError(common::PSBTError err)
auto Arg(std::string_view key) const
Helper to get a required or default-valued request argument.
CTxDestination AddAndGetMultisigDestination(int required, const std::vector< CPubKey > &pubkeys, OutputType type, FlatSigningProvider &keystore, CScript &script_out)
Special string to represent a floating point amount.
auto MaybeArg(std::string_view key) const
Helper to get an optional request argument.
The block chain is a tree shaped structure starting with the genesis block at the root...
Serialized script, used inside transaction inputs and outputs.
std::string HelpExampleRpcNamed(const std::string &methodname, const RPCArgList &args)
const std::string m_description
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Special type representing a floating point amount (can be either NUM or STR)
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac...
uint256 GetTarget(const CBlockIndex &blockindex, uint256 pow_limit)
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.
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={})
int ParseVerbosity(const UniValue &arg, int default_verbosity, bool allow_bool)
Parses verbosity from provided UniValue.
Special type to denote elision (...)
std::string ToDescriptionString() const
Return the description string, including the result type.
std::string ToStringObj(bool oneline) const
Return the type string of the argument when it is in an object (dict).