From de06e3164b8fcc220a2a435749b77611b59f46d1 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 10 Dec 2018 10:26:27 -0500 Subject: [PATCH] Merge #14885: rpc: Assert named arguments are unique in RPCHelpMan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit e09a5875ca rpc: Assert named arguments are unique in RPCHelpMan (João Barbosa) Pull request description: Prevents an obvious mistake. Tree-SHA512: 32c24a1934b17ab6f0d5cd31bdf0388e93ee5156ccc1b4f78eb9fd7f1d4b27a4b978b594ff11812bc9f20987c9fc36bf4497ddaedf18cf6bcbea19c050571334 --- src/rpc/util.cpp | 10 ++++++++++ src/rpc/util.h | 5 +---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index b5cae5773d..b014394e8e 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -219,6 +219,16 @@ struct Sections { } }; +RPCHelpMan::RPCHelpMan(const std::string& name, const std::string& description, const std::vector& args) + : m_name{name}, m_description{description}, m_args{args} +{ + std::set named_args; + for (const auto& arg : m_args) { + // Should have unique named arguments + assert(named_args.insert(arg.m_name).second); + } +} + std::string RPCHelpMan::ToString() const { std::string ret; diff --git a/src/rpc/util.h b/src/rpc/util.h index fb70e55c5b..8b76ee8bba 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -119,10 +119,7 @@ struct RPCArg { class RPCHelpMan { public: - RPCHelpMan(const std::string& name, const std::string& description, const std::vector& args) - : m_name{name}, m_description{description}, m_args{args} - { - } + RPCHelpMan(const std::string& name, const std::string& description, const std::vector& args); std::string ToString() const;