aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/util.h
diff options
context:
space:
mode:
authorKarl-Johan Alm <karljohan-alm@garage.co.jp>2019-06-20 02:39:52 +0900
committerKarl-Johan Alm <karljohan-alm@garage.co.jp>2019-07-08 09:53:52 +0900
commitc7a9fc234f3ce400ce78b9b434d2d210b2646c50 (patch)
tree9f9f489e483824d141074f8e811fc2fdef5049d8 /src/rpc/util.h
parent5c5e32bbe3dfa790dd8bb421fbd6301ae10b09f5 (diff)
Make the RPCHelpMan aware of JSONRPCRequest and add Check() helper
Diffstat (limited to 'src/rpc/util.h')
-rw-r--r--src/rpc/util.h9
1 files changed, 9 insertions, 0 deletions
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;