From 5d5a90e819d23a302f9bec6b995a3116ead6ae94 Mon Sep 17 00:00:00 2001 From: Ivan Metlushko Date: Wed, 3 Mar 2021 09:32:14 +0100 Subject: rpc: Add HelpExampleRpcNamed --- src/rpc/util.cpp | 11 +++++++++++ src/rpc/util.h | 3 +++ 2 files changed, 14 insertions(+) (limited to 'src/rpc') diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index e890c0108a..b4533c14d0 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -124,6 +124,17 @@ std::string HelpExampleRpc(const std::string& methodname, const std::string& arg "\"method\": \"" + methodname + "\", \"params\": [" + args + "]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n"; } +std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList& args) +{ + UniValue params(UniValue::VOBJ); + for (const auto& param: args) { + params.pushKV(param.first, param.second); + } + + return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", " + "\"method\": \"" + methodname + "\", \"params\": " + params.write() + "}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n"; +} + // Converts a hex string to a public key if possible CPubKey HexToPubKey(const std::string& hex_in) { diff --git a/src/rpc/util.h b/src/rpc/util.h index c54ce85f60..184dfc2940 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -78,8 +78,11 @@ extern std::vector ParseHexV(const UniValue& v, std::string strNa extern std::vector ParseHexO(const UniValue& o, std::string strKey); extern CAmount AmountFromValue(const UniValue& value); + +using RPCArgList = std::vector>; extern std::string HelpExampleCli(const std::string& methodname, const std::string& args); extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args); +extern std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList& args); CPubKey HexToPubKey(const std::string& hex_in); CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in); -- cgit v1.2.3