Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.h
Show First 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | struct RPCExamples { | ||||
std::string ToDescriptionString() const; | std::string ToDescriptionString() const; | ||||
}; | }; | ||||
class RPCHelpMan { | class RPCHelpMan { | ||||
public: | public: | ||||
RPCHelpMan(std::string name, std::string description, | RPCHelpMan(std::string name, std::string description, | ||||
std::vector<RPCArg> args, RPCResults results, | std::vector<RPCArg> args, RPCResults results, | ||||
RPCExamples examples); | RPCExamples examples); | ||||
using RPCMethodImpl = std::function<UniValue( | |||||
const RPCHelpMan &, Config &config, const JSONRPCRequest &)>; | |||||
RPCHelpMan(std::string name, std::string description, | |||||
std::vector<RPCArg> args, RPCResults results, | |||||
RPCExamples examples, RPCMethodImpl fun); | |||||
std::string ToString() const; | std::string ToString() const; | ||||
UniValue HandleRequest(Config &config, const JSONRPCRequest &request) { | |||||
return m_fun(*this, config, request); | |||||
} | |||||
/** If the supplied number of args is neither too small nor too high */ | /** If the supplied number of args is neither too small nor too high */ | ||||
bool IsValidNumArgs(size_t num_args) const; | bool IsValidNumArgs(size_t num_args) const; | ||||
/** | /** | ||||
* Check if the given request is valid according to this command or if | * Check if the given request is valid according to this command or if | ||||
* the user is asking for help information, and throw help when appropriate. | * the user is asking for help information, and throw help when appropriate. | ||||
*/ | */ | ||||
inline void Check(const JSONRPCRequest &request) const { | inline void Check(const JSONRPCRequest &request) const { | ||||
if (request.fHelp || !IsValidNumArgs(request.params.size())) { | if (request.fHelp || !IsValidNumArgs(request.params.size())) { | ||||
throw std::runtime_error(ToString()); | throw std::runtime_error(ToString()); | ||||
} | } | ||||
} | } | ||||
private: | std::vector<std::string> GetArgNames() const; | ||||
const std::string m_name; | const std::string m_name; | ||||
private: | |||||
const RPCMethodImpl m_fun; | |||||
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 RPCResults m_results; | ||||
const RPCExamples m_examples; | const RPCExamples m_examples; | ||||
}; | }; | ||||
#endif // BITCOIN_RPC_UTIL_H | #endif // BITCOIN_RPC_UTIL_H |