aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc/util.h')
-rw-r--r--src/rpc/util.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/rpc/util.h b/src/rpc/util.h
index c7d2c4dad6..4c3322b879 100644
--- a/src/rpc/util.h
+++ b/src/rpc/util.h
@@ -9,6 +9,7 @@
#include <outputtype.h>
#include <pubkey.h>
#include <rpc/protocol.h>
+#include <rpc/request.h>
#include <script/script.h>
#include <script/sign.h>
#include <script/standard.h>
@@ -226,7 +227,7 @@ struct RPCResults {
struct RPCExamples {
const std::string m_examples;
- RPCExamples(
+ explicit RPCExamples(
std::string examples)
: m_examples(std::move(examples))
{
@@ -242,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;