Skip to content

Commit 5d5a90e

Browse files
committed
rpc: Add HelpExampleRpcNamed
1 parent e491174 commit 5d5a90e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/rpc/util.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ std::string HelpExampleRpc(const std::string& methodname, const std::string& arg
124124
"\"method\": \"" + methodname + "\", \"params\": [" + args + "]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n";
125125
}
126126

127+
std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList& args)
128+
{
129+
UniValue params(UniValue::VOBJ);
130+
for (const auto& param: args) {
131+
params.pushKV(param.first, param.second);
132+
}
133+
134+
return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", "
135+
"\"method\": \"" + methodname + "\", \"params\": " + params.write() + "}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n";
136+
}
137+
127138
// Converts a hex string to a public key if possible
128139
CPubKey HexToPubKey(const std::string& hex_in)
129140
{

src/rpc/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strNa
7878
extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
7979

8080
extern CAmount AmountFromValue(const UniValue& value);
81+
82+
using RPCArgList = std::vector<std::pair<std::string, UniValue>>;
8183
extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
8284
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
85+
extern std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList& args);
8386

8487
CPubKey HexToPubKey(const std::string& hex_in);
8588
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in);

0 commit comments

Comments
 (0)