From c7a9fc234f3ce400ce78b9b434d2d210b2646c50 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Thu, 20 Jun 2019 02:39:52 +0900 Subject: Make the RPCHelpMan aware of JSONRPCRequest and add Check() helper --- src/rpc/util.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/rpc/util.h') diff --git a/src/rpc/util.h b/src/rpc/util.h index 29bd629fea..07c4c4e3ab 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -243,6 +243,15 @@ public: std::string ToString() const; /** If the supplied number of args is neither too small nor too high */ bool IsValidNumArgs(size_t num_args) const; + /** + * 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. + */ + inline void Check(const JSONRPCRequest& request) const { + if (request.fHelp || !IsValidNumArgs(request.params.size())) { + throw std::runtime_error(ToString()); + } + } private: const std::string m_name; -- cgit v1.2.3