Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.h
Show All 19 Lines | |||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
class CChainParams; | class CChainParams; | ||||
class FillableSigningProvider; | class FillableSigningProvider; | ||||
class CPubKey; | class CPubKey; | ||||
class CScript; | class CScript; | ||||
class UniValue; | struct Sections; | ||||
/** | /** | ||||
* String used to describe UNIX epoch time in documentation, factored out to a | * String used to describe UNIX epoch time in documentation, factored out to a | ||||
* constant for consistency. | * constant for consistency. | ||||
*/ | */ | ||||
extern const std::string UNIX_EPOCH_TIME; | extern const std::string UNIX_EPOCH_TIME; | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | struct RPCArg { | ||||
/** | /** | ||||
* Return the description string, including the argument type and whether | * Return the description string, including the argument type and whether | ||||
* the argument is required. | * the argument is required. | ||||
*/ | */ | ||||
std::string ToDescriptionString() const; | std::string ToDescriptionString() const; | ||||
}; | }; | ||||
struct RPCResult { | struct RPCResult { | ||||
enum class Type { | |||||
OBJ, | |||||
ARR, | |||||
STR, | |||||
NUM, | |||||
BOOL, | |||||
NONE, | |||||
STR_AMOUNT, //!< Special string to represent a floating point amount | |||||
STR_HEX, //!< Special string with only hex chars | |||||
OBJ_DYN, //!< Special dictionary with keys that are not literals | |||||
ARR_FIXED, //!< Special array that has a fixed number of entries | |||||
NUM_TIME, //!< Special numeric to denote unix epoch time | |||||
ELISION, //!< Special type to denote elision (...) | |||||
}; | |||||
const Type m_type; | |||||
const std::string m_key_name; //!< Only used for dicts | |||||
const std::vector<RPCResult> m_inner; //!< Only used for arrays or dicts | |||||
const bool m_optional; | |||||
const std::string m_description; | |||||
const std::string m_cond; | const std::string m_cond; | ||||
const std::string m_result; | |||||
explicit RPCResult(std::string result) | RPCResult(const std::string cond, const Type type, | ||||
: m_cond{}, m_result{std::move(result)} { | const std::string key_name, const bool optional, | ||||
CHECK_NONFATAL(!m_result.empty()); | const std::string description, | ||||
const std::vector<RPCResult> inner = {}) | |||||
: m_type{std::move(type)}, m_key_name{std::move(key_name)}, | |||||
m_inner{std::move(inner)}, m_optional{optional}, | |||||
m_description{std::move(description)}, m_cond{std::move(cond)} { | |||||
CHECK_NONFATAL(!m_cond.empty()); | |||||
const bool inner_needed{type == Type::ARR || type == Type::ARR_FIXED || | |||||
type == Type::OBJ || type == Type::OBJ_DYN}; | |||||
CHECK_NONFATAL(inner_needed != inner.empty()); | |||||
} | } | ||||
RPCResult(std::string cond, std::string result) | RPCResult(const std::string cond, const Type type, | ||||
: m_cond{std::move(cond)}, m_result{std::move(result)} { | const std::string key_name, const std::string description, | ||||
CHECK_NONFATAL(!m_cond.empty()); | const std::vector<RPCResult> inner = {}) | ||||
CHECK_NONFATAL(!m_result.empty()); | : RPCResult{cond, type, key_name, false, description, inner} {} | ||||
RPCResult(const Type type, const std::string key_name, const bool optional, | |||||
const std::string description, | |||||
const std::vector<RPCResult> inner = {}) | |||||
: m_type{std::move(type)}, m_key_name{std::move(key_name)}, | |||||
m_inner{std::move(inner)}, m_optional{optional}, | |||||
m_description{std::move(description)}, m_cond{} { | |||||
const bool inner_needed{type == Type::ARR || type == Type::ARR_FIXED || | |||||
type == Type::OBJ || type == Type::OBJ_DYN}; | |||||
CHECK_NONFATAL(inner_needed != inner.empty()); | |||||
} | } | ||||
RPCResult(const Type type, const std::string key_name, | |||||
const std::string description, | |||||
const std::vector<RPCResult> inner = {}) | |||||
: RPCResult{type, key_name, false, description, inner} {} | |||||
/** Append the sections of the result. */ | |||||
void ToSections(Sections §ions, OuterType outer_type = OuterType::NONE, | |||||
const int current_indent = 0) const; | |||||
/** Return the type string of the result when it is in an object (dict). */ | |||||
std::string ToStringObj() const; | |||||
/** Return the description string, including the result type. */ | |||||
std::string ToDescriptionString() const; | |||||
}; | }; | ||||
struct RPCResults { | struct RPCResults { | ||||
const std::vector<RPCResult> m_results; | const std::vector<RPCResult> m_results; | ||||
RPCResults() : m_results{} {} | RPCResults() : m_results{} {} | ||||
RPCResults(RPCResult result) : m_results{{result}} {} | RPCResults(RPCResult result) : m_results{{result}} {} | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |