5 #ifndef BITCOIN_RPC_UTIL_H 6 #define BITCOIN_RPC_UTIL_H 24 #include <initializer_list> 28 #include <string_view> 29 #include <type_traits> 90 const std::map<std::string, UniValueType>& typesExpected,
91 bool fAllowNull =
false,
92 bool fStrict =
false);
101 std::vector<unsigned char>
ParseHexO(
const UniValue& o, std::string_view strKey);
117 using RPCArgList = std::vector<std::pair<std::string, UniValue>>;
209 using Fallback = std::variant<Optional, DefaultHint, Default>;
222 std::string description,
237 std::string description,
238 std::vector<RPCArg> inner,
268 std::string
ToString(
bool oneline)
const;
312 std::string description,
313 std::vector<RPCResult> inner = {})
314 :
m_type{std::move(type)},
330 std::string description,
331 std::vector<RPCResult> inner = {})
332 :
RPCResult{std::move(cond), type, std::move(
m_key_name),
false, std::move(description), std::move(inner)} {}
338 std::string description,
339 std::vector<RPCResult> inner = {},
340 bool skip_type_check =
false)
341 :
m_type{std::move(type)},
355 std::string description,
356 std::vector<RPCResult> inner = {},
357 bool skip_type_check =
false)
358 :
RPCResult{type, std::move(
m_key_name),
false, std::move(description), std::move(inner), skip_type_check} {}
397 std::string examples)
408 using RPCMethodImpl = std::function<UniValue(const RPCHelpMan&, const JSONRPCRequest&)>;
429 template <
typename R>
430 auto Arg(std::string_view key)
const 434 if constexpr (std::is_integral_v<R> || std::is_floating_point_v<R>) {
436 return ArgValue<R>(i);
439 return ArgValue<const R&>(i);
461 template <
typename R>
466 if constexpr (std::is_integral_v<R> || std::is_floating_point_v<R>) {
468 return ArgValue<std::optional<R>>(i);
471 return ArgValue<const R*>(i);
480 std::vector<std::pair<std::string, bool>>
GetArgNames()
const;
491 template <
typename R>
506 #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)
static const std::string sighash
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
std::vector< CScript > EvalDescriptorStringOrObject(const UniValue &scanobject, FlatSigningProvider &provider, const bool expand_priv=false)
Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range ...
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...
CPubKey AddrToPubKey(const FillableSigningProvider &keystore, const std::string &addr_in)
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
void ToSections(Sections §ions, OuterType outer_type=OuterType::NONE, const int current_indent=0) const
Append the sections of the result.
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...
int ParseSighashString(const UniValue &sighash)
Parse a sighash string representation and raise an RPC error if it is invalid.
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. ...
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.
RPCErrorCode RPCErrorFromTransactionError(node::TransactionError terr)
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)
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FlatSigningProvider &keystore, CScript &script_out)
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)
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)
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.
Special string to represent a floating point amount.
auto MaybeArg(std::string_view key) const
Helper to get an optional request argument.
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 kilovirtualbyte: CAmount / kvB.
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={})
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).