diff --git a/src/rpc/util.h b/src/rpc/util.h --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -118,6 +118,16 @@ */ UniValue GetServicesNames(ServiceFlags services); +/** + * Serializing JSON objects depends on the outer type. Only arrays and + * dictionaries can be nested in json. The top-level outer type is "NONE". + */ +enum class OuterType { + ARR, + OBJ, + NONE, // Only set on first recursion +}; + struct RPCArg { enum class Type { OBJ, @@ -176,23 +186,28 @@ //! override the type in the argument description. const std::vector m_type_str; - RPCArg(const std::string &name, const Type &type, const Fallback &fallback, - const std::string &description, - const std::string &oneline_description = "", - const std::vector &type_str = {}) - : m_name{name}, m_type{type}, m_fallback{fallback}, - m_description{description}, - m_oneline_description{oneline_description}, m_type_str{type_str} { + RPCArg(const std::string name, const Type type, const Fallback fallback, + const std::string description, + const std::string oneline_description = "", + const std::vector type_str = {}) + : m_name{std::move(name)}, m_type{std::move(type)}, + m_fallback{std::move(fallback)}, m_description{std::move( + description)}, + m_oneline_description{std::move(oneline_description)}, + m_type_str{std::move(type_str)} { CHECK_NONFATAL(type != Type::ARR && type != Type::OBJ); } - RPCArg(const std::string &name, const Type &type, const Fallback &fallback, - const std::string &description, const std::vector &inner, - const std::string &oneline_description = "", - const std::vector &type_str = {}) - : m_name{name}, m_type{type}, m_inner{inner}, m_fallback{fallback}, - m_description{description}, - m_oneline_description{oneline_description}, m_type_str{type_str} { + RPCArg(const std::string name, const Type type, const Fallback fallback, + const std::string description, const std::vector inner, + const std::string oneline_description = "", + const std::vector type_str = {}) + : m_name{std::move(name)}, m_type{std::move(type)}, m_inner{std::move( + inner)}, + m_fallback{std::move(fallback)}, m_description{std::move( + description)}, + m_oneline_description{std::move(oneline_description)}, + m_type_str{std::move(type_str)} { CHECK_NONFATAL(type == Type::ARR || type == Type::OBJ); } diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -315,23 +315,11 @@ m_sections.push_back(s); } - /** - * Serializing RPCArgs depends on the outer type. Only arrays and - * dictionaries can be nested in json. The top-level outer type is "named - * arguments", a mix between a dictionary and arrays. - */ - enum class OuterType { - ARR, - OBJ, - // Only set on first recursion - NAMED_ARG, - }; - /** * Recursive helper to translate an RPCArg into sections */ void Push(const RPCArg &arg, const size_t current_indent = 5, - const OuterType outer_type = OuterType::NAMED_ARG) { + const OuterType outer_type = OuterType::NONE) { const auto indent = std::string(current_indent, ' '); const auto indent_next = std::string(current_indent + 2, ' '); // Dictionary keys must have a name @@ -345,7 +333,7 @@ case RPCArg::Type::RANGE: case RPCArg::Type::BOOL: { // Nothing more to do for non-recursive types on first recursion - if (outer_type == OuterType::NAMED_ARG) { + if (outer_type == OuterType::NONE) { return; } auto left = indent; @@ -361,7 +349,7 @@ } case RPCArg::Type::OBJ: case RPCArg::Type::OBJ_USER_KEYS: { - const auto right = outer_type == OuterType::NAMED_ARG + const auto right = outer_type == OuterType::NONE ? "" : arg.ToDescriptionString(); PushSection({indent + @@ -375,8 +363,7 @@ PushSection({indent_next + "...", ""}); } PushSection( - {indent + "}" + - (outer_type != OuterType::NAMED_ARG ? "," : ""), + {indent + "}" + (outer_type != OuterType::NONE ? "," : ""), ""}); break; } @@ -384,7 +371,7 @@ auto left = indent; left += push_name ? "\"" + arg.m_name + "\": " : ""; left += "["; - const auto right = outer_type == OuterType::NAMED_ARG + const auto right = outer_type == OuterType::NONE ? "" : arg.ToDescriptionString(); PushSection({left, right}); @@ -393,8 +380,7 @@ } PushSection({indent_next + "...", ""}); PushSection( - {indent + "]" + - (outer_type != OuterType::NAMED_ARG ? "," : ""), + {indent + "]" + (outer_type != OuterType::NONE ? "," : ""), ""}); break; }