aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/util.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2018-10-23 15:22:28 -0400
committerMarcoFalke <falke.marco@gmail.com>2018-11-12 11:11:17 -0500
commitfa483e13b387f244c1c72d4dbd709e669335618e (patch)
treeb488e095c893d0f7da0eb5e2744750e7a1e99dcc /src/rpc/util.h
parentfa0d36f712c50cce82b275e5f5dbb8ed9601a443 (diff)
downloadbitcoin-fa483e13b387f244c1c72d4dbd709e669335618e.tar.xz
rpc: Add RPCHelpMan for machine-generated help
Diffstat (limited to 'src/rpc/util.h')
-rw-r--r--src/rpc/util.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/rpc/util.h b/src/rpc/util.h
index e21b5ba22a..55ae2fa363 100644
--- a/src/rpc/util.h
+++ b/src/rpc/util.h
@@ -30,4 +30,53 @@ CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey
UniValue DescribeAddress(const CTxDestination& dest);
+struct RPCArg {
+ enum class Type {
+ OBJ,
+ ARR,
+ STR,
+ NUM,
+ BOOL,
+ OBJ_USER_KEYS, //!< Special type where the user must set the keys e.g. to define multiple addresses; as opposed to e.g. an options object where the keys are predefined
+ AMOUNT, //!< Special type representing a floating point amount (can be either NUM or STR)
+ STR_HEX, //!< Special type that is a STR with only hex chars
+ };
+ const std::string m_name; //!< The name of the arg (can be empty for inner args)
+ const Type m_type;
+ const std::vector<RPCArg> m_inner; //!< Only used for arrays or dicts
+ const bool m_optional;
+
+ RPCArg(const std::string& name, const Type& type, const bool optional)
+ : m_name{name}, m_type{type}, m_optional{optional}
+ {
+ assert(type != Type::ARR && type != Type::OBJ);
+ }
+
+ RPCArg(const std::string& name, const Type& type, const std::vector<RPCArg>& inner, const bool optional)
+ : m_name{name}, m_type{type}, m_inner{inner}, m_optional{optional}
+ {
+ assert(type == Type::ARR || type == Type::OBJ);
+ }
+
+ std::string ToString() const;
+
+private:
+ std::string ToStringObj() const;
+};
+
+class RPCHelpMan
+{
+public:
+ RPCHelpMan(const std::string& name, const std::vector<RPCArg>& args)
+ : m_name{name}, m_args{args}
+ {
+ }
+
+ std::string ToString() const;
+
+private:
+ const std::string m_name;
+ const std::vector<RPCArg> m_args;
+};
+
#endif // BITCOIN_RPC_UTIL_H