From 6d0ab07e817725369df699791b9c5b2fae204990 Mon Sep 17 00:00:00 2001 From: stickies-v Date: Tue, 15 Nov 2022 15:56:19 +0000 Subject: [PATCH] refactor: use convenience fn to auto parse non-string parameters Minimizes code duplication and improves function naming by having a single (overloaded) convenience function that both checks if the parameter is a non-string parameter and automatically parses the value if so. --- src/rpc/client.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index ea094976bf8..55026d6b564 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -225,11 +225,16 @@ private: public: CRPCConvertTable(); - bool convert(const std::string& method, int idx) { - return (members.count(std::make_pair(method, idx)) > 0); + /** Return arg_value as UniValue, and first parse it if it is a non-string parameter */ + UniValue ArgToUniValue(const std::string& arg_value, const std::string& method, int param_idx) + { + return members.count(std::make_pair(method, param_idx)) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value; } - bool convert(const std::string& method, const std::string& name) { - return (membersByName.count(std::make_pair(method, name)) > 0); + + /** Return arg_value as UniValue, and first parse it if it is a non-string parameter */ + UniValue ArgToUniValue(const std::string& arg_value, const std::string& method, const std::string& param_name) + { + return membersByName.count(std::make_pair(method, param_name)) > 0 ? ParseNonRFCJSONValue(arg_value) : arg_value; } }; @@ -261,14 +266,7 @@ UniValue RPCConvertValues(const std::string &strMethod, const std::vector