Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.h
Show First 20 Lines • Show All 101 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. | ||||
* implicitly_required is set for arguments in an array, which are neither | * implicitly_required is set for arguments in an array, which are neither | ||||
* optional nor required. | * optional nor required. | ||||
*/ | */ | ||||
std::string ToDescriptionString(bool implicitly_required = false) const; | std::string ToDescriptionString(bool implicitly_required = false) const; | ||||
}; | }; | ||||
struct RPCResult { | |||||
const std::string m_cond; | |||||
const std::string m_result; | |||||
explicit RPCResult(std::string result) | |||||
: m_cond{}, m_result{std::move(result)} { | |||||
assert(!m_result.empty()); | |||||
} | |||||
RPCResult(std::string cond, std::string result) | |||||
: m_cond{std::move(cond)}, m_result{std::move(result)} { | |||||
assert(!m_cond.empty()); | |||||
assert(!m_result.empty()); | |||||
} | |||||
}; | |||||
struct RPCResults { | |||||
const std::vector<RPCResult> m_results; | |||||
RPCResults() : m_results{} {} | |||||
RPCResults(RPCResult result) : m_results{{result}} {} | |||||
RPCResults(std::initializer_list<RPCResult> results) : m_results{results} {} | |||||
/** | |||||
* Return the description string. | |||||
*/ | |||||
std::string ToDescriptionString() const; | |||||
}; | |||||
struct RPCExamples { | |||||
const std::string m_examples; | |||||
RPCExamples(std::string examples) : m_examples(std::move(examples)) {} | |||||
std::string ToDescriptionString() const; | |||||
}; | |||||
class RPCHelpMan { | class RPCHelpMan { | ||||
public: | public: | ||||
RPCHelpMan(const std::string &name, const std::string &description, | RPCHelpMan(std::string name, std::string description, | ||||
const std::vector<RPCArg> &args) | std::vector<RPCArg> args, RPCResults results, | ||||
: m_name{name}, m_description{description}, m_args{args} {} | RPCExamples examples); | ||||
std::string ToString() const; | std::string ToString() const; | ||||
private: | private: | ||||
const std::string m_name; | const std::string m_name; | ||||
const std::string m_description; | const std::string m_description; | ||||
const std::vector<RPCArg> m_args; | const std::vector<RPCArg> m_args; | ||||
const RPCResults m_results; | |||||
const RPCExamples m_examples; | |||||
}; | }; | ||||
#endif // BITCOIN_RPC_UTIL_H | #endif // BITCOIN_RPC_UTIL_H |