diff options
Diffstat (limited to 'src/rpc/util.cpp')
-rw-r--r-- | src/rpc/util.cpp | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 4275cc09a8..ee7f3ca0dc 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -4,10 +4,12 @@ #include <key_io.h> #include <keystore.h> +#include <policy/fees.h> #include <rpc/protocol.h> #include <rpc/util.h> #include <tinyformat.h> #include <util/strencodings.h> +#include <validation.h> InitInterfaces* g_rpc_interfaces = nullptr; @@ -129,6 +131,16 @@ UniValue DescribeAddress(const CTxDestination& dest) return boost::apply_visitor(DescribeAddressVisitor(), dest); } +unsigned int ParseConfirmTarget(const UniValue& value) +{ + int target = value.get_int(); + unsigned int max_target = ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE); + if (target < 1 || (unsigned int)target > max_target) { + throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u - %u", 1, max_target)); + } + return (unsigned int)target; +} + struct Section { Section(const std::string& left, const std::string& right) : m_left{left}, m_right{right} {} @@ -170,12 +182,12 @@ struct Sections { left += outer_type == OuterType::OBJ ? arg.ToStringObj(/* oneline */ false) : arg.ToString(/* oneline */ false); } left += ","; - PushSection({left, arg.ToDescriptionString(/* implicitly_required */ outer_type == OuterType::ARR)}); + PushSection({left, arg.ToDescriptionString()}); break; } case RPCArg::Type::OBJ: case RPCArg::Type::OBJ_USER_KEYS: { - const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString(/* implicitly_required */ outer_type == OuterType::ARR); + const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString(); PushSection({indent + "{", right}); for (const auto& arg_inner : arg.m_inner) { Push(arg_inner, current_indent + 2, OuterType::OBJ); @@ -190,7 +202,7 @@ struct Sections { auto left = indent; left += outer_type == OuterType::OBJ ? "\"" + arg.m_name + "\": " : ""; left += "["; - const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString(/* implicitly_required */ outer_type == OuterType::ARR); + const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString(); PushSection({left, right}); for (const auto& arg_inner : arg.m_inner) { Push(arg_inner, current_indent + 2, OuterType::ARR); @@ -283,8 +295,14 @@ std::string RPCHelpMan::ToString() const ret += m_name; bool was_optional{false}; for (const auto& arg : m_args) { + bool optional; + if (arg.m_fallback.which() == 1) { + optional = true; + } else { + optional = RPCArg::Optional::NO != boost::get<RPCArg::Optional>(arg.m_fallback); + } ret += " "; - if (arg.m_optional) { + if (optional) { if (!was_optional) ret += "( "; was_optional = true; } else { @@ -324,7 +342,7 @@ std::string RPCHelpMan::ToString() const return ret; } -std::string RPCArg::ToDescriptionString(const bool implicitly_required) const +std::string RPCArg::ToDescriptionString() const { std::string ret; ret += "("; @@ -362,19 +380,24 @@ std::string RPCArg::ToDescriptionString(const bool implicitly_required) const // no default case, so the compiler can warn about missing cases } } - if (!implicitly_required) { - ret += ", "; - if (m_optional) { - ret += "optional"; - if (!m_default_value.empty()) { - ret += ", default=" + m_default_value; - } else { - // TODO enable this assert, when all optional parameters have their default value documented - //assert(false); - } - } else { - ret += "required"; - assert(m_default_value.empty()); // Default value is ignored, and must not be present + if (m_fallback.which() == 1) { + ret += ", optional, default=" + boost::get<std::string>(m_fallback); + } else { + switch (boost::get<RPCArg::Optional>(m_fallback)) { + case RPCArg::Optional::OMITTED: { + // nothing to do. Element is treated as if not present and has no default value + break; + } + case RPCArg::Optional::OMITTED_NAMED_ARG: { + ret += ", optional"; // Default value is "null" + break; + } + case RPCArg::Optional::NO: { + ret += ", required"; + break; + } + + // no default case, so the compiler can warn about missing cases } } ret += ")"; |