Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.cpp
Show First 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | std::string ToString() const { | ||||
} | } | ||||
ret += right; | ret += right; | ||||
ret += "\n"; | ret += "\n"; | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
}; | }; | ||||
// Remove once PR14796 backport is completed | |||||
std::string RPCHelpMan::ToString() const { | std::string RPCHelpMan::ToString() const { | ||||
std::string ret; | std::string ret; | ||||
ret += m_name; | |||||
bool is_optional{false}; | |||||
for (const auto &arg : m_args) { | |||||
ret += " "; | |||||
if (arg.m_optional) { | |||||
if (!is_optional) { | |||||
ret += "( "; | |||||
} | |||||
is_optional = true; | |||||
} else { | |||||
// Currently we still support unnamed arguments, so any argument | |||||
// following an optional argument must also be optional If support | |||||
// for positional arguments is deprecated in the future, remove this | |||||
// line | |||||
assert(!is_optional); | |||||
} | |||||
ret += arg.ToString(); | |||||
} | |||||
if (is_optional) { | |||||
ret += " )"; | |||||
} | |||||
ret += "\n"; | |||||
ret += m_description; | |||||
return ret; | |||||
} | |||||
// Rename to ToString() once PR14796 is completed | |||||
std::string RPCHelpMan::ToStringWithArgs() const { | |||||
std::string ret; | |||||
// Oneline summary | // Oneline summary | ||||
ret += m_name; | ret += m_name; | ||||
bool was_optional{false}; | bool was_optional{false}; | ||||
for (const auto &arg : m_args) { | for (const auto &arg : m_args) { | ||||
ret += " "; | ret += " "; | ||||
if (arg.m_optional) { | if (arg.m_optional) { | ||||
if (!was_optional) { | if (!was_optional) { | ||||
ret += "( "; | ret += "( "; | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | if (!implicitly_required) { | ||||
assert(m_default_value.empty()); | assert(m_default_value.empty()); | ||||
} | } | ||||
} | } | ||||
ret += ")"; | ret += ")"; | ||||
ret += m_description.empty() ? "" : " " + m_description; | ret += m_description.empty() ? "" : " " + m_description; | ||||
return ret; | return ret; | ||||
} | } | ||||
// Remove once PR14796 backport is completed | |||||
std::string RPCArg::ToStringObj() const { | |||||
std::string res = "\"" + m_name + "\":"; | |||||
switch (m_type) { | |||||
case Type::STR: | |||||
return res + "\"str\""; | |||||
case Type::STR_HEX: | |||||
return res + "\"hex\""; | |||||
case Type::NUM: | |||||
return res + "n"; | |||||
case Type::AMOUNT: | |||||
return res + "amount"; | |||||
case Type::BOOL: | |||||
return res + "bool"; | |||||
case Type::ARR: | |||||
res += "["; | |||||
for (const auto &i : m_inner) { | |||||
res += i.ToString() + ","; | |||||
} | |||||
return res + "...]"; | |||||
case Type::OBJ: | |||||
case Type::OBJ_USER_KEYS: | |||||
// Currently unused, so avoid writing dead code | |||||
assert(false); | |||||
// no default case, so the compiler can warn about missing cases | |||||
} | |||||
assert(false); | |||||
} | |||||
std::string RPCArg::ToStringObj(const bool oneline) const { | std::string RPCArg::ToStringObj(const bool oneline) const { | ||||
std::string res; | std::string res; | ||||
res += "\""; | res += "\""; | ||||
res += m_name; | res += m_name; | ||||
if (oneline) { | if (oneline) { | ||||
res += "\":"; | res += "\":"; | ||||
} else { | } else { | ||||
res += "\": "; | res += "\": "; | ||||
Show All 20 Lines | switch (m_type) { | ||||
// Currently unused, so avoid writing dead code | // Currently unused, so avoid writing dead code | ||||
assert(false); | assert(false); | ||||
// no default case, so the compiler can warn about missing cases | // no default case, so the compiler can warn about missing cases | ||||
} | } | ||||
assert(false); | assert(false); | ||||
} | } | ||||
// Remove once PR14796 backport is completed | |||||
std::string RPCArg::ToString() const { | |||||
if (!m_oneline_description.empty()) { | |||||
return m_oneline_description; | |||||
} | |||||
switch (m_type) { | |||||
case Type::STR_HEX: | |||||
case Type::STR: { | |||||
return "\"" + m_name + "\""; | |||||
} | |||||
case Type::NUM: | |||||
case Type::AMOUNT: | |||||
case Type::BOOL: { | |||||
return m_name; | |||||
} | |||||
case Type::OBJ: | |||||
case Type::OBJ_USER_KEYS: { | |||||
std::string res; | |||||
for (size_t i = 0; i < m_inner.size();) { | |||||
res += m_inner[i].ToStringObj(); | |||||
if (++i < m_inner.size()) { | |||||
res += ","; | |||||
} | |||||
} | |||||
if (m_type == Type::OBJ) { | |||||
return "{" + res + "}"; | |||||
} else { | |||||
return "{" + res + ",...}"; | |||||
} | |||||
} | |||||
case Type::ARR: { | |||||
std::string res; | |||||
for (const auto &i : m_inner) { | |||||
res += i.ToString() + ","; | |||||
} | |||||
return "[" + res + "...]"; | |||||
} | |||||
// no default case, so the compiler can warn about missing cases | |||||
} | |||||
assert(false); | |||||
} | |||||
std::string RPCArg::ToString(const bool oneline) const { | std::string RPCArg::ToString(const bool oneline) const { | ||||
if (oneline && !m_oneline_description.empty()) { | if (oneline && !m_oneline_description.empty()) { | ||||
return m_oneline_description; | return m_oneline_description; | ||||
} | } | ||||
switch (m_type) { | switch (m_type) { | ||||
case Type::STR_HEX: | case Type::STR_HEX: | ||||
case Type::STR: { | case Type::STR: { | ||||
Show All 34 Lines |