aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/util.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2019-02-12 18:42:50 -0500
committerMarcoFalke <falke.marco@gmail.com>2019-02-12 18:43:06 -0500
commit0d1160e42185983b398cbc2e2be379002f4a62e9 (patch)
tree926f90ace6f781bab590a462d9fe37ce361dec25 /src/rpc/util.h
parent029d28a7aa5619973eb59fe445b9a4186c0c2a58 (diff)
parentfa0ad4e7ce8f4c19fe58bf06747bf8c62600581c (diff)
Merge #14918: RPCHelpMan: Check default values are given at compile-time
fa0ad4e7ce RPCHelpMan: Check default values are given at compile-time (MarcoFalke) Pull request description: Remove the run time assertions on the default values and ensure that the correct default type and value is provided at compile time. Tree-SHA512: 80df2f3fab4379b500c773c27da63f22786c58be5963fe99744746320e43627a5d433eedf8b32209158df7805ebdce65ed4d242c829c4fe6e5d13deb4799ed42
Diffstat (limited to 'src/rpc/util.h')
-rw-r--r--src/rpc/util.h38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/rpc/util.h b/src/rpc/util.h
index d34c9cfdbb..d895e99c7e 100644
--- a/src/rpc/util.h
+++ b/src/rpc/util.h
@@ -12,6 +12,8 @@
#include <string>
#include <vector>
+#include <boost/variant.hpp>
+
class CKeyStore;
class CPubKey;
class CScript;
@@ -42,11 +44,28 @@ struct RPCArg {
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
};
+
+ enum class Optional {
+ /** Required arg */
+ NO,
+ /**
+ * Optinal arg that is a named argument and has a default value of
+ * `null`. When possible, the default value should be specified.
+ */
+ OMITTED_NAMED_ARG,
+ /**
+ * Optional argument with default value omitted because they are
+ * implicitly clear. That is, elements in an array or object may not
+ * exist by default.
+ * When possible, the default value should be specified.
+ */
+ OMITTED,
+ };
+ using Fallback = boost::variant<Optional, /* default value for optional args */ std::string>;
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;
- const std::string m_default_value; //!< Only used for optional args
+ const Fallback m_fallback;
const std::string m_description;
const std::string m_oneline_description; //!< Should be empty unless it is supposed to override the auto-generated summary line
const std::vector<std::string> m_type_str; //!< Should be empty unless it is supposed to override the auto-generated type strings. Vector length is either 0 or 2, m_type_str.at(0) will override the type of the value in a key-value pair, m_type_str.at(1) will override the type in the argument description.
@@ -54,15 +73,13 @@ struct RPCArg {
RPCArg(
const std::string& name,
const Type& type,
- const bool opt,
- const std::string& default_val,
+ const Fallback& fallback,
const std::string& description,
const std::string& oneline_description = "",
const std::vector<std::string>& type_str = {})
: m_name{name},
m_type{type},
- m_optional{opt},
- m_default_value{default_val},
+ m_fallback{fallback},
m_description{description},
m_oneline_description{oneline_description},
m_type_str{type_str}
@@ -73,8 +90,7 @@ struct RPCArg {
RPCArg(
const std::string& name,
const Type& type,
- const bool opt,
- const std::string& default_val,
+ const Fallback& fallback,
const std::string& description,
const std::vector<RPCArg>& inner,
const std::string& oneline_description = "",
@@ -82,8 +98,7 @@ struct RPCArg {
: m_name{name},
m_type{type},
m_inner{inner},
- m_optional{opt},
- m_default_value{default_val},
+ m_fallback{fallback},
m_description{description},
m_oneline_description{oneline_description},
m_type_str{type_str}
@@ -104,9 +119,8 @@ struct RPCArg {
/**
* Return the description string, including the argument type and whether
* the argument is required.
- * implicitly_required is set for arguments in an array, which are neither optional nor required.
*/
- std::string ToDescriptionString(bool implicitly_required = false) const;
+ std::string ToDescriptionString() const;
};
struct RPCResult {