Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.cpp
Show First 20 Lines • Show All 399 Lines • ▼ Show 20 Lines | void Push(const RPCArg &arg, const size_t current_indent = 5, | ||||
for (const auto &arg_inner : arg.m_inner) { | for (const auto &arg_inner : arg.m_inner) { | ||||
Push(arg_inner, current_indent + 2, OuterType::ARR); | Push(arg_inner, current_indent + 2, OuterType::ARR); | ||||
} | } | ||||
PushSection({indent_next + "...", ""}); | PushSection({indent_next + "...", ""}); | ||||
PushSection( | PushSection( | ||||
{indent + "]" + (outer_type != OuterType::NONE ? "," : ""), | {indent + "]" + (outer_type != OuterType::NONE ? "," : ""), | ||||
""}); | ""}); | ||||
break; | break; | ||||
} | } // no default case, so the compiler can warn about missing cases | ||||
// no default case, so the compiler can warn about missing cases | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Concatenate all sections with proper padding | * Concatenate all sections with proper padding | ||||
*/ | */ | ||||
std::string ToString() const { | std::string ToString() const { | ||||
std::string ret; | std::string ret; | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | |||||
std::string RPCHelpMan::ToString() const { | std::string RPCHelpMan::ToString() const { | ||||
std::string ret; | 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) { | ||||
if (arg.m_hidden) { | |||||
continue; | |||||
} | |||||
const bool optional = arg.IsOptional(); | const bool optional = arg.IsOptional(); | ||||
ret += " "; | ret += " "; | ||||
if (optional) { | if (optional) { | ||||
if (!was_optional) { | if (!was_optional) { | ||||
ret += "( "; | ret += "( "; | ||||
} | } | ||||
was_optional = true; | was_optional = true; | ||||
} else { | } else { | ||||
Show All 11 Lines | std::string RPCHelpMan::ToString() const { | ||||
// Description | // Description | ||||
ret += m_description; | ret += m_description; | ||||
// Arguments | // Arguments | ||||
Sections sections; | Sections sections; | ||||
for (size_t i{0}; i < m_args.size(); ++i) { | for (size_t i{0}; i < m_args.size(); ++i) { | ||||
const auto &arg = m_args.at(i); | const auto &arg = m_args.at(i); | ||||
if (arg.m_hidden) { | |||||
continue; | |||||
} | |||||
if (i == 0) { | if (i == 0) { | ||||
ret += "\nArguments:\n"; | ret += "\nArguments:\n"; | ||||
} | } | ||||
// Push named argument name and description | // Push named argument name and description | ||||
sections.m_sections.emplace_back(::ToString(i + 1) + ". " + | sections.m_sections.emplace_back(::ToString(i + 1) + ". " + | ||||
arg.GetFirstName(), | arg.GetFirstName(), | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | if (m_type_str.size() != 0) { | ||||
case Type::OBJ: | case Type::OBJ: | ||||
case Type::OBJ_USER_KEYS: { | case Type::OBJ_USER_KEYS: { | ||||
ret += "json object"; | ret += "json object"; | ||||
break; | break; | ||||
} | } | ||||
case Type::ARR: { | case Type::ARR: { | ||||
ret += "json array"; | ret += "json array"; | ||||
break; | break; | ||||
} | } // no default case, so the compiler can warn about missing cases | ||||
// no default case, so the compiler can warn about missing cases | |||||
} | } | ||||
} | } | ||||
if (m_fallback.which() == 1) { | if (m_fallback.which() == 1) { | ||||
ret += ", optional, default=" + boost::get<std::string>(m_fallback); | ret += ", optional, default=" + boost::get<std::string>(m_fallback); | ||||
} else { | } else { | ||||
switch (boost::get<RPCArg::Optional>(m_fallback)) { | switch (boost::get<RPCArg::Optional>(m_fallback)) { | ||||
case RPCArg::Optional::OMITTED: { | case RPCArg::Optional::OMITTED: { | ||||
// nothing to do. Element is treated as if not present and has | // nothing to do. Element is treated as if not present and has | ||||
// no default value | // no default value | ||||
break; | break; | ||||
} | } | ||||
case RPCArg::Optional::OMITTED_NAMED_ARG: { | case RPCArg::Optional::OMITTED_NAMED_ARG: { | ||||
ret += ", optional"; // Default value is "null" | ret += ", optional"; // Default value is "null" | ||||
break; | break; | ||||
} | } | ||||
case RPCArg::Optional::NO: { | case RPCArg::Optional::NO: { | ||||
ret += ", required"; | ret += ", required"; | ||||
break; | break; | ||||
} | } // no default case, so the compiler can warn about missing cases | ||||
// no default case, so the compiler can warn about missing cases | |||||
} | } | ||||
} | } | ||||
ret += ")"; | ret += ")"; | ||||
ret += m_description.empty() ? "" : " " + m_description; | ret += m_description.empty() ? "" : " " + m_description; | ||||
return ret; | return ret; | ||||
} | } | ||||
void RPCResult::ToSections(Sections §ions, const OuterType outer_type, | void RPCResult::ToSections(Sections §ions, const OuterType outer_type, | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | switch (m_type) { | ||||
// continuation | // continuation | ||||
sections.PushSection({indent_next + "...", ""}); | sections.PushSection({indent_next + "...", ""}); | ||||
} else { | } else { | ||||
// Remove final comma, which would be invalid JSON | // Remove final comma, which would be invalid JSON | ||||
sections.m_sections.back().m_left.pop_back(); | sections.m_sections.back().m_left.pop_back(); | ||||
} | } | ||||
sections.PushSection({indent + "}" + maybe_separator, ""}); | sections.PushSection({indent + "}" + maybe_separator, ""}); | ||||
return; | return; | ||||
} // no default case, so the compiler can warn about missing cases | |||||
} | } | ||||
// no default case, so the compiler can warn about missing cases | |||||
} | |||||
CHECK_NONFATAL(false); | CHECK_NONFATAL(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 += GetFirstName(); | res += GetFirstName(); | ||||
if (oneline) { | if (oneline) { | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | switch (m_type) { | ||||
} | } | ||||
} | } | ||||
case Type::ARR: { | case Type::ARR: { | ||||
std::string res; | std::string res; | ||||
for (const auto &i : m_inner) { | for (const auto &i : m_inner) { | ||||
res += i.ToString(oneline) + ","; | res += i.ToString(oneline) + ","; | ||||
} | } | ||||
return "[" + res + "...]"; | return "[" + res + "...]"; | ||||
} | } // no default case, so the compiler can warn about missing cases | ||||
// no default case, so the compiler can warn about missing cases | |||||
} | } | ||||
CHECK_NONFATAL(false); | CHECK_NONFATAL(false); | ||||
} | } | ||||
static std::pair<int64_t, int64_t> ParseRange(const UniValue &value) { | static std::pair<int64_t, int64_t> ParseRange(const UniValue &value) { | ||||
if (value.isNum()) { | if (value.isNum()) { | ||||
return {0, value.get_int64()}; | return {0, value.get_int64()}; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |