Skip to content

Commit 7275365

Browse files
author
MarcoFalke
committed
Merge #14987: RPCHelpMan: Pass through Result and Examples
faa1522 RPCHelpMan: Pass through Result and Examples (MarcoFalke) Pull request description: Passing the rpc result and rpc examples through `RPCHelpMan` makes it clear in what order they appear in the stringified version. Future improvements could then autoformat or autogenerate them. Tree-SHA512: b32a5c178cc80f50a7e9b93a38e2b26d5994188ecafe9e61bbc599941b44b9b0e4e4be6413d4464fac6e8e73661a191a77d34917f2e6293de19fb59519dd4487
2 parents d6e700e + faa1522 commit 7275365

File tree

11 files changed

+1011
-759
lines changed

11 files changed

+1011
-759
lines changed

src/rpc/blockchain.cpp

Lines changed: 214 additions & 168 deletions
Large diffs are not rendered by default.

src/rpc/mining.cpp

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,15 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request)
9494
{
9595
{"nblocks", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "120", "The number of blocks, or -1 for blocks since last difficulty change."},
9696
{"height", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "-1", "To estimate at the time of the given height."},
97-
}}
98-
.ToString() +
99-
"\nResult:\n"
97+
},
98+
RPCResult{
10099
"x (numeric) Hashes per second estimated\n"
101-
"\nExamples:\n"
102-
+ HelpExampleCli("getnetworkhashps", "")
100+
},
101+
RPCExamples{
102+
HelpExampleCli("getnetworkhashps", "")
103103
+ HelpExampleRpc("getnetworkhashps", "")
104-
);
104+
},
105+
}.ToString());
105106

106107
LOCK(cs_main);
107108
return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1);
@@ -165,16 +166,17 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
165166
{"nblocks", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "How many blocks are generated immediately."},
166167
{"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The address to send the newly generated bitcoin to."},
167168
{"maxtries", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "1000000", "How many iterations to try."},
168-
}}
169-
.ToString() +
170-
"\nResult:\n"
169+
},
170+
RPCResult{
171171
"[ blockhashes ] (array) hashes of blocks generated\n"
172-
"\nExamples:\n"
172+
},
173+
RPCExamples{
173174
"\nGenerate 11 blocks to myaddress\n"
174175
+ HelpExampleCli("generatetoaddress", "11 \"myaddress\"")
175176
+ "If you are running the bitcoin core wallet, you can get a new address to send the newly generated bitcoin to with:\n"
176177
+ HelpExampleCli("getnewaddress", "")
177-
);
178+
},
179+
}.ToString());
178180

179181
int nGenerate = request.params[0].get_int();
180182
uint64_t nMaxTries = 1000000;
@@ -198,9 +200,9 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
198200
if (request.fHelp || request.params.size() != 0)
199201
throw std::runtime_error(
200202
RPCHelpMan{"getmininginfo",
201-
"\nReturns a json object containing mining-related information.", {}}
202-
.ToString() +
203-
"\nResult:\n"
203+
"\nReturns a json object containing mining-related information.",
204+
{},
205+
RPCResult{
204206
"{\n"
205207
" \"blocks\": nnn, (numeric) The current block\n"
206208
" \"currentblockweight\": nnn, (numeric) The last block weight\n"
@@ -211,10 +213,12 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
211213
" \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
212214
" \"warnings\": \"...\" (string) any network and blockchain warnings\n"
213215
"}\n"
214-
"\nExamples:\n"
215-
+ HelpExampleCli("getmininginfo", "")
216+
},
217+
RPCExamples{
218+
HelpExampleCli("getmininginfo", "")
216219
+ HelpExampleRpc("getmininginfo", "")
217-
);
220+
},
221+
}.ToString());
218222

219223

220224
LOCK(cs_main);
@@ -247,14 +251,15 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
247251
" Note, that this value is not a fee rate. It is a value to modify absolute fee of the TX.\n"
248252
" The fee is not actually paid, only the algorithm for selecting transactions into a block\n"
249253
" considers the transaction as it would have paid a higher (or lower) fee."},
250-
}}
251-
.ToString() +
252-
"\nResult:\n"
254+
},
255+
RPCResult{
253256
"true (boolean) Returns true\n"
254-
"\nExamples:\n"
255-
+ HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000")
257+
},
258+
RPCExamples{
259+
HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000")
256260
+ HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")
257-
);
261+
},
262+
}.ToString());
258263

259264
LOCK(cs_main);
260265

@@ -326,9 +331,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
326331
},
327332
},
328333
"\"template_request\""},
329-
}}
330-
.ToString() +
331-
"\nResult:\n"
334+
},
335+
RPCResult{
332336
"{\n"
333337
" \"version\" : n, (numeric) The preferred block version\n"
334338
" \"rules\" : [ \"rulename\", ... ], (array of strings) specific block rules that are to be enforced\n"
@@ -372,11 +376,12 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
372376
" \"bits\" : \"xxxxxxxx\", (string) compressed target of next block\n"
373377
" \"height\" : n (numeric) The height of the next block\n"
374378
"}\n"
375-
376-
"\nExamples:\n"
377-
+ HelpExampleCli("getblocktemplate", "{\"rules\": [\"segwit\"]}")
379+
},
380+
RPCExamples{
381+
HelpExampleCli("getblocktemplate", "{\"rules\": [\"segwit\"]}")
378382
+ HelpExampleRpc("getblocktemplate", "{\"rules\": [\"segwit\"]}")
379-
);
383+
},
384+
}.ToString());
380385

381386
LOCK(cs_main);
382387

@@ -713,13 +718,13 @@ static UniValue submitblock(const JSONRPCRequest& request)
713718
{
714719
{"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded block data to submit"},
715720
{"dummy", RPCArg::Type::STR, /* opt */ true, /* default_val */ "ignored", "dummy value, for compatibility with BIP22. This value is ignored."},
716-
}}
717-
.ToString() +
718-
"\nResult:\n"
719-
"\nExamples:\n"
720-
+ HelpExampleCli("submitblock", "\"mydata\"")
721+
},
722+
RPCResults{},
723+
RPCExamples{
724+
HelpExampleCli("submitblock", "\"mydata\"")
721725
+ HelpExampleRpc("submitblock", "\"mydata\"")
722-
);
726+
},
727+
}.ToString());
723728
}
724729

725730
std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
@@ -777,13 +782,15 @@ static UniValue submitheader(const JSONRPCRequest& request)
777782
"\nThrows when the header is invalid.\n",
778783
{
779784
{"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded block header data"},
780-
}}
781-
.ToString() +
782-
"\nResult:\n"
785+
},
786+
RPCResult{
783787
"None"
784-
"\nExamples:\n" +
785-
HelpExampleCli("submitheader", "\"aabbcc\"") +
786-
HelpExampleRpc("submitheader", "\"aabbcc\""));
788+
},
789+
RPCExamples{
790+
HelpExampleCli("submitheader", "\"aabbcc\"") +
791+
HelpExampleRpc("submitheader", "\"aabbcc\"")
792+
},
793+
}.ToString());
787794
}
788795

789796
CBlockHeader h;
@@ -826,9 +833,8 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
826833
" \"UNSET\"\n"
827834
" \"ECONOMICAL\"\n"
828835
" \"CONSERVATIVE\""},
829-
}}
830-
.ToString() +
831-
"\nResult:\n"
836+
},
837+
RPCResult{
832838
"{\n"
833839
" \"feerate\" : x.x, (numeric, optional) estimate fee rate in " + CURRENCY_UNIT + "/kB\n"
834840
" \"errors\": [ str... ] (json array of strings, optional) Errors encountered during processing\n"
@@ -839,9 +845,11 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
839845
"fee estimation is able to return based on how long it has been running.\n"
840846
"An error is returned if not enough transactions and blocks\n"
841847
"have been observed to make an estimate for any number of blocks.\n"
842-
"\nExample:\n"
843-
+ HelpExampleCli("estimatesmartfee", "6")
844-
);
848+
},
849+
RPCExamples{
850+
HelpExampleCli("estimatesmartfee", "6")
851+
},
852+
}.ToString());
845853

846854
RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR});
847855
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
@@ -886,9 +894,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
886894
{"threshold", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0.95", "The proportion of transactions in a given feerate range that must have been\n"
887895
" confirmed within conf_target in order to consider those feerates as high enough and proceed to check\n"
888896
" lower buckets."},
889-
}}
890-
.ToString() +
891-
"\nResult:\n"
897+
},
898+
RPCResult{
892899
"{\n"
893900
" \"short\" : { (json object, optional) estimate for short time horizon\n"
894901
" \"feerate\" : x.x, (numeric, optional) estimate fee rate in " + CURRENCY_UNIT + "/kB\n"
@@ -910,9 +917,11 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
910917
"}\n"
911918
"\n"
912919
"Results are returned for any horizon which tracks blocks up to the confirmation target.\n"
913-
"\nExample:\n"
914-
+ HelpExampleCli("estimaterawfee", "6 0.9")
915-
);
920+
},
921+
RPCExamples{
922+
HelpExampleCli("estimaterawfee", "6 0.9")
923+
},
924+
}.ToString());
916925

917926
RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VNUM}, true);
918927
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);

0 commit comments

Comments
 (0)