Skip to content

Commit

Permalink
Merge #14987: RPCHelpMan: Pass through Result and Examples
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MarcoFalke committed Jan 29, 2019
2 parents d6e700e + faa1522 commit 7275365
Show file tree
Hide file tree
Showing 11 changed files with 1,011 additions and 759 deletions.
382 changes: 214 additions & 168 deletions src/rpc/blockchain.cpp

Large diffs are not rendered by default.

117 changes: 63 additions & 54 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request)
{
{"nblocks", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "120", "The number of blocks, or -1 for blocks since last difficulty change."},
{"height", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "-1", "To estimate at the time of the given height."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"x (numeric) Hashes per second estimated\n"
"\nExamples:\n"
+ HelpExampleCli("getnetworkhashps", "")
},
RPCExamples{
HelpExampleCli("getnetworkhashps", "")
+ HelpExampleRpc("getnetworkhashps", "")
);
},
}.ToString());

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

int nGenerate = request.params[0].get_int();
uint64_t nMaxTries = 1000000;
Expand All @@ -198,9 +200,9 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"getmininginfo",
"\nReturns a json object containing mining-related information.", {}}
.ToString() +
"\nResult:\n"
"\nReturns a json object containing mining-related information.",
{},
RPCResult{
"{\n"
" \"blocks\": nnn, (numeric) The current block\n"
" \"currentblockweight\": nnn, (numeric) The last block weight\n"
Expand All @@ -211,10 +213,12 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
" \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
" \"warnings\": \"...\" (string) any network and blockchain warnings\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getmininginfo", "")
},
RPCExamples{
HelpExampleCli("getmininginfo", "")
+ HelpExampleRpc("getmininginfo", "")
);
},
}.ToString());


LOCK(cs_main);
Expand Down Expand Up @@ -247,14 +251,15 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
" Note, that this value is not a fee rate. It is a value to modify absolute fee of the TX.\n"
" The fee is not actually paid, only the algorithm for selecting transactions into a block\n"
" considers the transaction as it would have paid a higher (or lower) fee."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"true (boolean) Returns true\n"
"\nExamples:\n"
+ HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000")
},
RPCExamples{
HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000")
+ HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")
);
},
}.ToString());

LOCK(cs_main);

Expand Down Expand Up @@ -326,9 +331,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
},
},
"\"template_request\""},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"version\" : n, (numeric) The preferred block version\n"
" \"rules\" : [ \"rulename\", ... ], (array of strings) specific block rules that are to be enforced\n"
Expand Down Expand Up @@ -372,11 +376,12 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
" \"bits\" : \"xxxxxxxx\", (string) compressed target of next block\n"
" \"height\" : n (numeric) The height of the next block\n"
"}\n"

"\nExamples:\n"
+ HelpExampleCli("getblocktemplate", "{\"rules\": [\"segwit\"]}")
},
RPCExamples{
HelpExampleCli("getblocktemplate", "{\"rules\": [\"segwit\"]}")
+ HelpExampleRpc("getblocktemplate", "{\"rules\": [\"segwit\"]}")
);
},
}.ToString());

LOCK(cs_main);

Expand Down Expand Up @@ -713,13 +718,13 @@ static UniValue submitblock(const JSONRPCRequest& request)
{
{"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded block data to submit"},
{"dummy", RPCArg::Type::STR, /* opt */ true, /* default_val */ "ignored", "dummy value, for compatibility with BIP22. This value is ignored."},
}}
.ToString() +
"\nResult:\n"
"\nExamples:\n"
+ HelpExampleCli("submitblock", "\"mydata\"")
},
RPCResults{},
RPCExamples{
HelpExampleCli("submitblock", "\"mydata\"")
+ HelpExampleRpc("submitblock", "\"mydata\"")
);
},
}.ToString());
}

std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
Expand Down Expand Up @@ -777,13 +782,15 @@ static UniValue submitheader(const JSONRPCRequest& request)
"\nThrows when the header is invalid.\n",
{
{"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded block header data"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"None"
"\nExamples:\n" +
HelpExampleCli("submitheader", "\"aabbcc\"") +
HelpExampleRpc("submitheader", "\"aabbcc\""));
},
RPCExamples{
HelpExampleCli("submitheader", "\"aabbcc\"") +
HelpExampleRpc("submitheader", "\"aabbcc\"")
},
}.ToString());
}

CBlockHeader h;
Expand Down Expand Up @@ -826,9 +833,8 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
" \"UNSET\"\n"
" \"ECONOMICAL\"\n"
" \"CONSERVATIVE\""},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"feerate\" : x.x, (numeric, optional) estimate fee rate in " + CURRENCY_UNIT + "/kB\n"
" \"errors\": [ str... ] (json array of strings, optional) Errors encountered during processing\n"
Expand All @@ -839,9 +845,11 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
"fee estimation is able to return based on how long it has been running.\n"
"An error is returned if not enough transactions and blocks\n"
"have been observed to make an estimate for any number of blocks.\n"
"\nExample:\n"
+ HelpExampleCli("estimatesmartfee", "6")
);
},
RPCExamples{
HelpExampleCli("estimatesmartfee", "6")
},
}.ToString());

RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR});
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
Expand Down Expand Up @@ -886,9 +894,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
{"threshold", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0.95", "The proportion of transactions in a given feerate range that must have been\n"
" confirmed within conf_target in order to consider those feerates as high enough and proceed to check\n"
" lower buckets."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"short\" : { (json object, optional) estimate for short time horizon\n"
" \"feerate\" : x.x, (numeric, optional) estimate fee rate in " + CURRENCY_UNIT + "/kB\n"
Expand All @@ -910,9 +917,11 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
"}\n"
"\n"
"Results are returned for any horizon which tracks blocks up to the confirmation target.\n"
"\nExample:\n"
+ HelpExampleCli("estimaterawfee", "6 0.9")
);
},
RPCExamples{
HelpExampleCli("estimaterawfee", "6 0.9")
},
}.ToString());

RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VNUM}, true);
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
Expand Down
Loading

0 comments on commit 7275365

Please sign in to comment.