5 #ifndef BITCOIN_RPC_UTIL_H
6 #define BITCOIN_RPC_UTIL_H
24 #include <boost/variant.hpp>
57 const std::list<UniValueType>& typesExpected,
bool fAllowNull=
false);
68 const std::map<std::string, UniValueType>& typesExpected,
69 bool fAllowNull =
false,
70 bool fStrict =
false);
78 extern std::vector<unsigned char>
ParseHexV(
const UniValue& v, std::string strName);
79 extern std::vector<unsigned char>
ParseHexO(
const UniValue& o, std::string strKey);
84 extern std::string
HelpExampleCli(
const std::string& methodname,
const std::string& args);
85 extern std::string
HelpExampleRpc(
const std::string& methodname,
const std::string& args);
158 const std::string
name,
161 const std::string description,
162 const std::string oneline_description =
"",
163 const std::vector<std::string> type_str = {},
164 const bool hidden =
false)
165 : m_names{std::move(name)},
166 m_type{std::move(type)},
168 m_fallback{std::move(fallback)},
169 m_description{std::move(description)},
170 m_oneline_description{std::move(oneline_description)},
171 m_type_str{std::move(type_str)}
177 const std::string name,
180 const std::string description,
181 const std::vector<RPCArg> inner,
182 const std::string oneline_description =
"",
183 const std::vector<std::string> type_str = {})
184 : m_names{std::move(name)},
185 m_type{std::move(type)},
187 m_inner{std::move(inner)},
188 m_fallback{std::move(fallback)},
189 m_description{std::move(description)},
190 m_oneline_description{std::move(oneline_description)},
191 m_type_str{std::move(type_str)}
208 std::string
ToString(
bool oneline)
const;
245 const std::string cond,
247 const std::string m_key_name,
249 const std::string description,
250 const std::vector<RPCResult> inner = {})
251 : m_type{std::move(type)},
252 m_key_name{std::move(m_key_name)},
253 m_inner{std::move(inner)},
254 m_optional{optional},
255 m_description{std::move(description)},
256 m_cond{std::move(cond)}
264 const std::string cond,
266 const std::string m_key_name,
267 const std::string description,
268 const std::vector<RPCResult> inner = {})
273 const std::string m_key_name,
275 const std::string description,
276 const std::vector<RPCResult> inner = {})
277 : m_type{std::move(type)},
278 m_key_name{std::move(m_key_name)},
279 m_inner{std::move(inner)},
280 m_optional{optional},
281 m_description{std::move(description)},
290 const std::string m_key_name,
291 const std::string description,
292 const std::vector<RPCResult> inner = {})
307 : m_results{{result}}
311 RPCResults(std::initializer_list<RPCResult> results)
319 std::string ToDescriptionString()
const;
325 std::string examples)
326 : m_examples(
std::move(examples))
336 using RPCMethodImpl = std::function<UniValue(const RPCHelpMan&, const JSONRPCRequest&)>;
343 return m_fun(*
this, request);
353 throw std::runtime_error(
ToString());
369 #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.
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
uint256 ParseHashO(const UniValue &o, std::string strKey)
RPCResult(const Type type, const std::string m_key_name, const bool optional, const std::string description, const std::vector< RPCResult > inner={})
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.
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)
std::string ToStringObj() const
Return the type string of the result when it is in an object (dict).
CPubKey HexToPubKey(const std::string &hex_in)
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
UniValue HandleRequest(const JSONRPCRequest &request)
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
CAmount AmountFromValue(const UniValue &value)
const std::string m_key_name
Only used for dicts.
RPCResult(const Type type, const std::string m_key_name, const std::string description, const std::vector< RPCResult > inner={})
const RPCExamples m_examples
boost::variant< Optional, std::string > Fallback
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={})
std::string ToDescriptionString() const
const std::vector< RPCArg > m_inner
Only used for arrays or dicts.
std::string ToDescriptionString() const
Return the description string, including the result type.
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.
Special string with only hex chars.
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FillableSigningProvider &keystore, CScript &script_out)
std::string ToDescriptionString() const
Return the description string, including the argument type and whether the argument is required...
std::vector< std::string > GetArgNames() const
std::string GetName() const
Return the name, throws when there are aliases.
Special array that has a fixed number of entries.
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...
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)
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.
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::string ToStringObj(bool oneline) const
Return the type string of the argument when it is in an object (dict).
OuterType
Serializing JSON objects depends on the outer type.
RPCHelpMan(std::string name, std::string description, std::vector< RPCArg > args, RPCResults results, RPCExamples examples)
bool IsValidNumArgs(size_t num_args) const
If the supplied number of args is neither too small nor too high.
Optional argument with default value omitted because they are implicitly clear.
Special string to represent a floating point amount.
Serialized script, used inside transaction inputs and outputs.
void ToSections(Sections §ions, OuterType outer_type=OuterType::NONE, const int current_indent=0) const
Append the sections of the result.
void Check(const JSONRPCRequest &request) const
Check if the given request is valid according to this command or if the user is asking for help infor...
const std::string m_description
Special type representing a floating point amount (can be either NUM or STR)
CoinStatsHashType ParseHashType(const UniValue ¶m, const CoinStatsHashType default_type)
std::string ToString(bool oneline) const
Return the type string of the argument.
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={})
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)
std::string ToString() const
RPCErrorCode
Bitcoin RPC error codes.
Special dictionary with keys that are not literals.
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
std::string GetFirstName() const
Return the first of all aliases.
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::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)