diff options
Diffstat (limited to 'src/rpc/util.h')
-rw-r--r-- | src/rpc/util.h | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/rpc/util.h b/src/rpc/util.h index d34c9cfdbb..1c9ddcdf44 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -5,6 +5,7 @@ #ifndef BITCOIN_RPC_UTIL_H #define BITCOIN_RPC_UTIL_H +#include <node/transaction.h> #include <pubkey.h> #include <script/standard.h> #include <univalue.h> @@ -12,6 +13,8 @@ #include <string> #include <vector> +#include <boost/variant.hpp> + class CKeyStore; class CPubKey; class CScript; @@ -31,6 +34,9 @@ UniValue DescribeAddress(const CTxDestination& dest); //! Parse a confirm target option and raise an RPC error if it is invalid. unsigned int ParseConfirmTarget(const UniValue& value); +RPCErrorCode RPCErrorFromTransactionError(TransactionError terr); +UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_string = ""); + struct RPCArg { enum class Type { OBJ, @@ -42,11 +48,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 +77,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 +94,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 +102,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 +123,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 { |