From fa8ec00061567e56333bb69c5623919d45a9a92d Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 17 Apr 2020 13:28:29 -0400 Subject: rpc: Check that left section is not multiline --- src/rpc/util.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/rpc/util.cpp') diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 54ea352a72..d476feb962 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -381,6 +381,9 @@ struct Sections { std::string ret; const size_t pad = m_max_pad + 4; for (const auto& s : m_sections) { + // The left part of a section is assumed to be a single line, usually it is the name of the JSON struct or a + // brace like {, }, [, or ] + CHECK_NONFATAL(s.m_left.find('\n') == std::string::npos); if (s.m_right.empty()) { ret += s.m_left; ret += "\n"; -- cgit v1.2.3 From faaeb2b0b347b40ce456a951eec5e820587e5b02 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 26 Jun 2020 12:16:22 -0400 Subject: rpc: Add CRPCCommand constructor which takes RPCHelpMan This allows the constructor to ask the rpc manager for the name of the rpc method or the rpc argument names instead of having it manually passed in. --- src/rpc/util.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/rpc/util.cpp') diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index d476feb962..fbd51784a7 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -418,7 +418,11 @@ struct Sections { }; RPCHelpMan::RPCHelpMan(std::string name, std::string description, std::vector args, RPCResults results, RPCExamples examples) + : RPCHelpMan{std::move(name), std::move(description), std::move(args), std::move(results), std::move(examples), nullptr} {} + +RPCHelpMan::RPCHelpMan(std::string name, std::string description, std::vector args, RPCResults results, RPCExamples examples, RPCMethodImpl fun) : m_name{std::move(name)}, + m_fun{std::move(fun)}, m_description{std::move(description)}, m_args{std::move(args)}, m_results{std::move(results)}, @@ -467,6 +471,16 @@ bool RPCHelpMan::IsValidNumArgs(size_t num_args) const } return num_required_args <= num_args && num_args <= m_args.size(); } + +std::vector RPCHelpMan::GetArgNames() const +{ + std::vector ret; + for (const auto& arg : m_args) { + ret.emplace_back(arg.m_names); + } + return ret; +} + std::string RPCHelpMan::ToString() const { std::string ret; -- cgit v1.2.3 From aaaaad562790cd4dce1568ae193f5393aacacedf Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 3 Jul 2020 10:10:26 -0400 Subject: rpc: Add option to hide RPCArg Also, update switch statments to our style guide --- src/rpc/util.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'src/rpc/util.cpp') diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index fbd51784a7..2076c9e64c 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -368,9 +368,7 @@ struct Sections { PushSection({indent + "]" + (outer_type != OuterType::NONE ? "," : ""), ""}); break; } - - // no default case, so the compiler can warn about missing cases - } + } // no default case, so the compiler can warn about missing cases } /** @@ -489,6 +487,7 @@ std::string RPCHelpMan::ToString() const ret += m_name; bool was_optional{false}; for (const auto& arg : m_args) { + if (arg.m_hidden) continue; const bool optional = arg.IsOptional(); ret += " "; if (optional) { @@ -510,6 +509,7 @@ std::string RPCHelpMan::ToString() const Sections sections; for (size_t i{0}; i < m_args.size(); ++i) { const auto& arg = m_args.at(i); + if (arg.m_hidden) continue; if (i == 0) ret += "\nArguments:\n"; @@ -589,9 +589,7 @@ std::string RPCArg::ToDescriptionString() const ret += "json array"; 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) { ret += ", optional, default=" + boost::get(m_fallback); @@ -609,9 +607,7 @@ std::string RPCArg::ToDescriptionString() const ret += ", required"; 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 += m_description.empty() ? "" : " " + m_description; @@ -706,10 +702,7 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const sections.PushSection({indent + "}" + maybe_separator, ""}); 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); } @@ -746,9 +739,7 @@ std::string RPCArg::ToStringObj(const bool oneline) const case Type::OBJ_USER_KEYS: // Currently unused, so avoid writing dead code CHECK_NONFATAL(false); - - // 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); } @@ -783,9 +774,7 @@ std::string RPCArg::ToString(const bool oneline) const } 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); } -- cgit v1.2.3