Merge #14987: RPCHelpMan: Pass through Result and Examples

faa1522e5e 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
This commit is contained in:
MarcoFalke 2019-01-29 09:55:37 -05:00 committed by Dzutte
parent c679fd9ab6
commit 57841be492
11 changed files with 1016 additions and 773 deletions

View File

@ -190,14 +190,16 @@ static UniValue getblockcount(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"getblockcount",
"\nReturns the number of blocks in the longest blockchain.\n", {}}
.ToString() +
"\nResult:\n"
"\nReturns the number of blocks in the longest blockchain.\n",
{},
RPCResult{
"n (numeric) The current block count\n"
"\nExamples:\n"
+ HelpExampleCli("getblockcount", "")
},
RPCExamples{
HelpExampleCli("getblockcount", "")
+ HelpExampleRpc("getblockcount", "")
);
},
}.ToString());
LOCK(cs_main);
return ::ChainActive().Height();
@ -208,14 +210,16 @@ static UniValue getbestblockhash(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"getbestblockhash",
"\nReturns the hash of the best (tip) block in the longest blockchain.\n", {}}
.ToString() +
"\nResult:\n"
"\nReturns the hash of the best (tip) block in the longest blockchain.\n",
{},
RPCResult{
"\"hex\" (string) the block hash, hex-encoded\n"
"\nExamples:\n"
+ HelpExampleCli("getbestblockhash", "")
},
RPCExamples{
HelpExampleCli("getbestblockhash", "")
+ HelpExampleRpc("getbestblockhash", "")
);
},
}.ToString());
LOCK(cs_main);
return ::ChainActive().Tip()->GetBlockHash().GetHex();
@ -273,20 +277,19 @@ static UniValue waitfornewblock(const JSONRPCRequest& request)
"\nWaits for a specific new block and returns useful info about it.\n"
"\nReturns the current block on timeout or exit.\n",
{
{"timeout", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", ""},
}}
.ToString() +
"\nArguments:\n"
"1. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n"
"\nResult:\n"
{"timeout", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."},
},
RPCResult{
"{ (json object)\n"
" \"hash\" : { (string) The blockhash\n"
" \"height\" : { (int) Block height\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("waitfornewblock", "1000")
},
RPCExamples{
HelpExampleCli("waitfornewblock", "1000")
+ HelpExampleRpc("waitfornewblock", "1000")
);
},
}.ToString());
int timeout = 0;
if (!request.params[0].isNull())
timeout = request.params[0].get_int();
@ -317,17 +320,18 @@ static UniValue waitforblock(const JSONRPCRequest& request)
{
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "Block hash to wait for."},
{"timeout", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{ (json object)\n"
" \"hash\" : { (string) The blockhash\n"
" \"height\" : { (int) Block height\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000")
},
RPCExamples{
HelpExampleCli("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000")
+ HelpExampleRpc("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000")
);
},
}.ToString());
int timeout = 0;
uint256 hash = uint256S(request.params[0].get_str());
@ -362,17 +366,18 @@ static UniValue waitforblockheight(const JSONRPCRequest& request)
{
{"height", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "Block height to wait for."},
{"timeout", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{ (json object)\n"
" \"hash\" : { (string) The blockhash\n"
" \"height\" : { (int) Block height\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("waitforblockheight", "\"100\", 1000")
},
RPCExamples{
HelpExampleCli("waitforblockheight", "\"100\", 1000")
+ HelpExampleRpc("waitforblockheight", "\"100\", 1000")
);
},
}.ToString());
int timeout = 0;
int height = request.params[0].get_int();
@ -401,12 +406,14 @@ static UniValue syncwithvalidationinterfacequeue(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() > 0) {
throw std::runtime_error(
RPCHelpMan{"syncwithvalidationinterfacequeue",
"\nWaits for the validation interface queue to catch up on everything that was there when we entered this function.\n", {}}
.ToString() +
"\nExamples:\n"
+ HelpExampleCli("syncwithvalidationinterfacequeue","")
"\nWaits for the validation interface queue to catch up on everything that was there when we entered this function.\n",
{},
RPCResults{},
RPCExamples{
HelpExampleCli("syncwithvalidationinterfacequeue","")
+ HelpExampleRpc("syncwithvalidationinterfacequeue","")
);
},
}.ToString());
}
SyncWithValidationInterfaceQueue();
return NullUniValue;
@ -417,14 +424,16 @@ static UniValue getdifficulty(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"getdifficulty",
"\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n", {}}
.ToString() +
"\nResult:\n"
"\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n",
{},
RPCResult{
"n.nnn (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
"\nExamples:\n"
+ HelpExampleCli("getdifficulty", "")
},
RPCExamples{
HelpExampleCli("getdifficulty", "")
+ HelpExampleRpc("getdifficulty", "")
);
},
}.ToString());
LOCK(cs_main);
return GetDifficulty(::ChainActive().Tip());
@ -543,9 +552,8 @@ static UniValue getrawmempool(const JSONRPCRequest& request)
"\nHint: use getmempoolentry to fetch a specific transaction from the mempool.\n",
{
{"verbose", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "True for a json object, false for array of transaction ids"},
}}
.ToString() +
"\nResult: (for verbose = false):\n"
},
RPCResult{"for verbose = false",
"[ (json array of string)\n"
" \"transactionid\" (string) The transaction id\n"
" ,...\n"
@ -556,10 +564,12 @@ static UniValue getrawmempool(const JSONRPCRequest& request)
+ EntryDescriptionString()
+ " }, ...\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getrawmempool", "true")
},
RPCExamples{
HelpExampleCli("getrawmempool", "true")
+ HelpExampleRpc("getrawmempool", "true")
);
},
}.ToString());
bool fVerbose = false;
if (!request.params[0].isNull())
@ -577,23 +587,27 @@ static UniValue getmempoolancestors(const JSONRPCRequest& request)
{
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id (must be in mempool)"},
{"verbose", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "True for a json object, false for array of transaction ids"},
}}
.ToString() +
"\nResult (for verbose = false):\n"
},
{
RPCResult{"for verbose = false",
"[ (json array of strings)\n"
" \"transactionid\" (string) The transaction id of an in-mempool ancestor transaction\n"
" ,...\n"
"]\n"
"\nResult (for verbose = true):\n"
},
RPCResult{"for verbose = true",
"{ (json object)\n"
" \"transactionid\" : { (json object)\n"
+ EntryDescriptionString()
+ " }, ...\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getmempoolancestors", "\"mytxid\"")
},
},
RPCExamples{
HelpExampleCli("getmempoolancestors", "\"mytxid\"")
+ HelpExampleRpc("getmempoolancestors", "\"mytxid\"")
);
},
}.ToString());
}
bool fVerbose = false;
@ -643,23 +657,27 @@ static UniValue getmempooldescendants(const JSONRPCRequest& request)
{
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id (must be in mempool)"},
{"verbose", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "True for a json object, false for array of transaction ids"},
}}
.ToString() +
"\nResult (for verbose = false):\n"
},
{
RPCResult{"for verbose = false",
"[ (json array of strings)\n"
" \"transactionid\" (string) The transaction id of an in-mempool descendant transaction\n"
" ,...\n"
"]\n"
"\nResult (for verbose = true):\n"
},
RPCResult{"for verbose = true",
"{ (json object)\n"
" \"transactionid\" : { (json object)\n"
+ EntryDescriptionString()
+ " }, ...\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getmempooldescendants", "\"mytxid\"")
},
},
RPCExamples{
HelpExampleCli("getmempooldescendants", "\"mytxid\"")
+ HelpExampleRpc("getmempooldescendants", "\"mytxid\"")
);
},
}.ToString());
}
bool fVerbose = false;
@ -708,16 +726,17 @@ static UniValue getmempoolentry(const JSONRPCRequest& request)
"\nReturns mempool data for given transaction\n",
{
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id (must be in mempool)"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{ (json object)\n"
+ EntryDescriptionString()
+ "}\n"
"\nExamples:\n"
+ HelpExampleCli("getmempoolentry", "\"mytxid\"")
},
RPCExamples{
HelpExampleCli("getmempoolentry", "\"mytxid\"")
+ HelpExampleRpc("getmempoolentry", "\"mytxid\"")
);
},
}.ToString());
}
uint256 hash = ParseHashV(request.params[0], "parameter 1");
@ -779,14 +798,15 @@ static UniValue getblockhash(const JSONRPCRequest& request)
"\nReturns hash of block in best-block-chain at height provided.\n",
{
{"height", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The height index"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"\"hash\" (string) The block hash\n"
"\nExamples:\n"
+ HelpExampleCli("getblockhash", "1000")
},
RPCExamples{
HelpExampleCli("getblockhash", "1000")
+ HelpExampleRpc("getblockhash", "1000")
);
},
}.ToString());
LOCK(cs_main);
@ -808,9 +828,9 @@ static UniValue getblockheader(const JSONRPCRequest& request)
{
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The block hash"},
{"verbose", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "true", "true for a json object, false for the hex-encoded data"},
}}
.ToString() +
"\nResult (for verbose = true):\n"
},
{
RPCResult{"for verbose = true",
"{\n"
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
@ -828,12 +848,16 @@ static UniValue getblockheader(const JSONRPCRequest& request)
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
" \"nextblockhash\" : \"hash\", (string) The hash of the next block\n"
"}\n"
"\nResult (for verbose=false):\n"
},
RPCResult{"for verbose=false",
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
"\nExamples:\n"
+ HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
},
},
RPCExamples{
HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
+ HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
);
},
}.ToString());
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
@ -1065,11 +1089,12 @@ static UniValue getblock(const JSONRPCRequest& request)
{
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The block hash"},
{"verbosity", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "1", "0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data"},
}}
.ToString() +
"\nResult (for verbosity = 0):\n"
},
{
RPCResult{"for verbosity = 0",
"\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
"\nResult (for verbose = 1):\n"
},
RPCResult{"for verbosity = 1",
"{\n"
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
@ -1098,7 +1123,8 @@ static UniValue getblock(const JSONRPCRequest& request)
" \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
" \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
"}\n"
"\nResult (for verbosity = 2):\n"
},
RPCResult{"for verbosity = 2",
"{\n"
" ..., Same output as verbosity = 1.\n"
" \"tx\" : [ (array of Objects) The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 \"tx\" result.\n"
@ -1106,10 +1132,13 @@ static UniValue getblock(const JSONRPCRequest& request)
" ],\n"
" ,... Same output as verbosity = 1.\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"")
},
},
RPCExamples{
HelpExampleCli("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"")
+ HelpExampleRpc("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"")
);
},
}.ToString());
LOCK(cs_main);
@ -1150,13 +1179,15 @@ static UniValue pruneblockchain(const JSONRPCRequest& request)
{
{"height", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The block height to prune up to. May be set to a discrete height, or a unix timestamp\n"
" to prune blocks whose block time is at least 2 hours older than the provided timestamp."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"n (numeric) Height of the last block pruned.\n"
"\nExamples:\n"
+ HelpExampleCli("pruneblockchain", "1000")
+ HelpExampleRpc("pruneblockchain", "1000"));
},
RPCExamples{
HelpExampleCli("pruneblockchain", "1000")
+ HelpExampleRpc("pruneblockchain", "1000")
},
}.ToString());
if (!fPruneMode)
throw JSONRPCError(RPC_MISC_ERROR, "Cannot prune blocks because node is not in prune mode.");
@ -1200,9 +1231,8 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
RPCHelpMan{"gettxoutsetinfo",
"\nReturns statistics about the unspent transaction output set.\n"
"Note this call may take some time.\n",
{}}
.ToString() +
"\nResult:\n"
{},
RPCResult{
"{\n"
" \"height\":n, (numeric) The current block height (index)\n"
" \"bestblock\": \"hex\", (string) The hash of the block at the tip of the chain\n"
@ -1213,10 +1243,12 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
" \"disk_size\": n, (numeric) The estimated size of the chainstate on disk\n"
" \"total_amount\": x.xxx (numeric) The total amount\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("gettxoutsetinfo", "")
},
RPCExamples{
HelpExampleCli("gettxoutsetinfo", "")
+ HelpExampleRpc("gettxoutsetinfo", "")
);
},
}.ToString());
UniValue ret(UniValue::VOBJ);
@ -1249,9 +1281,8 @@ static UniValue gettxout(const JSONRPCRequest& request)
{"txid", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The transaction id"},
{"n", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "vout number"},
{"include_mempool", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "true", "Whether to include the mempool. Note that an unspent output that is spent in the mempool won't appear."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"bestblock\": \"hash\", (string) The hash of the block at the tip of the chain\n"
" \"confirmations\" : n, (numeric) The number of confirmations\n"
@ -1268,15 +1299,16 @@ static UniValue gettxout(const JSONRPCRequest& request)
" },\n"
" \"coinbase\" : true|false (boolean) Coinbase or not\n"
"}\n"
"\nExamples:\n"
},
RPCExamples{
"\nGet unspent transactions\n"
+ HelpExampleCli("listunspent", "") +
"\nView the details\n"
+ HelpExampleCli("gettxout", "\"txid\" 1") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("gettxout", "\"txid\", 1")
);
},
}.ToString());
LOCK(cs_main);
@ -1332,14 +1364,15 @@ static UniValue verifychain(const JSONRPCRequest& request)
{
{"checklevel", RPCArg::Type::NUM, /* opt */ true, /* default_val */ strprintf("%d, range=0-4", nCheckLevel), "How thorough the block verification is."},
{"nblocks", RPCArg::Type::NUM, /* opt */ true, /* default_val */ strprintf("%d, 0=all", nCheckDepth), "The number of blocks to check."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"true|false (boolean) Verified or not\n"
"\nExamples:\n"
+ HelpExampleCli("verifychain", "")
},
RPCExamples{
HelpExampleCli("verifychain", "")
+ HelpExampleRpc("verifychain", "")
);
},
}.ToString());
LOCK(cs_main);
@ -1428,9 +1461,9 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"getblockchaininfo",
"Returns an object containing various state info regarding blockchain processing.\n", {}}
.ToString() +
"\nResult:\n"
"Returns an object containing various state info regarding blockchain processing.\n",
{},
RPCResult{
"{\n"
" \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest) and\n"
" devnet or devnet-<name> for \"-devnet\" and \"-devnet=<name>\" respectively\n"
@ -1474,10 +1507,12 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
" }\n"
" \"warnings\" : \"...\", (string) any network and blockchain warnings.\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getblockchaininfo", "")
},
RPCExamples{
HelpExampleCli("getblockchaininfo", "")
+ HelpExampleRpc("getblockchaininfo", "")
);
},
}.ToString());
LOCK(cs_main);
@ -1555,9 +1590,8 @@ static UniValue getchaintips(const JSONRPCRequest& request)
{
{"count", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "only show this much of latest tips"},
{"branchlen", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "only show tips that have equal or greater length of branch"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"[\n"
" {\n"
" \"height\": xxxx, (numeric) height of the chain tip\n"
@ -1584,10 +1618,12 @@ static UniValue getchaintips(const JSONRPCRequest& request)
"3. \"valid-headers\" All blocks are available for this branch, but they were never fully validated\n"
"4. \"valid-fork\" This branch is not part of the active chain, but is fully validated\n"
"5. \"active\" This is the tip of the active main chain, which is certainly valid\n"
"\nExamples:\n"
+ HelpExampleCli("getchaintips", "")
},
RPCExamples{
HelpExampleCli("getchaintips", "")
+ HelpExampleRpc("getchaintips", "")
);
},
}.ToString());
LOCK(cs_main);
@ -1698,9 +1734,9 @@ static UniValue getmempoolinfo(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"getmempoolinfo",
"\nReturns details on the active state of the TX memory pool.\n", {}}
.ToString() +
"\nResult:\n"
"\nReturns details on the active state of the TX memory pool.\n",
{},
RPCResult{
"{\n"
" \"size\": xxxxx, (numeric) Current tx count\n"
" \"bytes\": xxxxx, (numeric) Sum of all tx sizes\n"
@ -1710,10 +1746,12 @@ static UniValue getmempoolinfo(const JSONRPCRequest& request)
" \"minrelaytxfee\": xxxxx (numeric) Current minimum relay fee for transactions\n"
" \"instantsendlocks\": xxxxx, (numeric) Number of unconfirmed instant send locks\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getmempoolinfo", "")
},
RPCExamples{
HelpExampleCli("getmempoolinfo", "")
+ HelpExampleRpc("getmempoolinfo", "")
);
},
}.ToString());
return MempoolInfoToJSON(::mempool);
}
@ -1728,13 +1766,13 @@ static UniValue preciousblock(const JSONRPCRequest& request)
"\nThe effects of preciousblock are not retained across restarts.\n",
{
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hash of the block to mark as precious"},
}}
.ToString() +
"\nResult:\n"
"\nExamples:\n"
+ HelpExampleCli("preciousblock", "\"blockhash\"")
},
RPCResults{},
RPCExamples{
HelpExampleCli("preciousblock", "\"blockhash\"")
+ HelpExampleRpc("preciousblock", "\"blockhash\"")
);
},
}.ToString());
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
@ -1766,13 +1804,13 @@ static UniValue invalidateblock(const JSONRPCRequest& request)
"\nPermanently marks a block as invalid, as if it violated a consensus rule.\n",
{
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hash of the block to mark as invalid"},
}}
.ToString() +
"\nResult:\n"
"\nExamples:\n"
+ HelpExampleCli("invalidateblock", "\"blockhash\"")
},
RPCResults{},
RPCExamples{
HelpExampleCli("invalidateblock", "\"blockhash\"")
+ HelpExampleRpc("invalidateblock", "\"blockhash\"")
);
},
}.ToString());
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
@ -1808,13 +1846,13 @@ static UniValue reconsiderblock(const JSONRPCRequest& request)
"This can be used to undo the effects of invalidateblock.\n",
{
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hash of the block to reconsider"},
}}
.ToString() +
"\nResult:\n"
"\nExamples:\n"
+ HelpExampleCli("reconsiderblock", "\"blockhash\"")
},
RPCResults{},
RPCExamples{
HelpExampleCli("reconsiderblock", "\"blockhash\"")
+ HelpExampleRpc("reconsiderblock", "\"blockhash\"")
);
},
}.ToString());
std::string strHash = request.params[0].get_str();
uint256 hash(uint256S(strHash));
@ -1848,9 +1886,8 @@ static UniValue getchaintxstats(const JSONRPCRequest& request)
{
{"nblocks", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "one month", "Size of the window in number of blocks"},
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, /* default_val */ "", "The hash of the block that ends the window."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n"
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n"
@ -1861,10 +1898,12 @@ static UniValue getchaintxstats(const JSONRPCRequest& request)
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n"
" \"txrate\": x.xx, (numeric) The average rate of transactions per second in the window. Only returned if \"window_interval\" is > 0.\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getchaintxstats", "")
},
RPCExamples{
HelpExampleCli("getchaintxstats", "")
+ HelpExampleRpc("getchaintxstats", "2016")
);
},
}.ToString());
const CBlockIndex* pindex;
int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month
@ -1989,9 +2028,8 @@ static UniValue getblockstats(const JSONRPCRequest& request)
{"time", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "Selected statistic"},
},
"stats"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{ (json object)\n"
" \"avgfee\": xxxxx, (numeric) Average fee in the block\n"
" \"avgfeerate\": xxxxx, (numeric) Average feerate (in duffs per byte)\n"
@ -2025,10 +2063,12 @@ static UniValue getblockstats(const JSONRPCRequest& request)
" \"utxo_increase\": xxxxx, (numeric) The increase/decrease in the number of unspent outputs\n"
" \"utxo_size_inc\": xxxxx, (numeric) The increase/decrease in size for the utxo index (not discounting op_return and similar)\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getblockstats", "1000 '[\"minfeerate\",\"avgfeerate\"]'")
},
RPCExamples{
HelpExampleCli("getblockstats", "1000 '[\"minfeerate\",\"avgfeerate\"]'")
+ HelpExampleRpc("getblockstats", "1000 '[\"minfeerate\",\"avgfeerate\"]'")
);
},
}.ToString());
}
if (g_txindex) {
@ -2327,12 +2367,14 @@ static UniValue savemempool(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0) {
throw std::runtime_error(
RPCHelpMan{"savemempool",
"\nDumps the mempool to disk. It will fail until the previous dump is fully loaded.\n", {}}
.ToString() +
"\nExamples:\n"
+ HelpExampleCli("savemempool", "")
"\nDumps the mempool to disk. It will fail until the previous dump is fully loaded.\n",
{},
RPCResults{},
RPCExamples{
HelpExampleCli("savemempool", "")
+ HelpExampleRpc("savemempool", "")
);
},
}.ToString());
}
if (!g_is_mempool_loaded) {
@ -2441,9 +2483,8 @@ UniValue scantxoutset(const JSONRPCRequest& request)
},
},
"[scanobjects,...]"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"unspents\": [\n"
" {\n"
@ -2457,6 +2498,9 @@ UniValue scantxoutset(const JSONRPCRequest& request)
" ,...], \n"
" \"total_amount\" : x.xxx, (numeric) The total amount of all found unspent outputs in " + CURRENCY_UNIT + "\n"
"]\n"
},
RPCExamples{""},
}.ToString()
);
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR});

View File

@ -93,14 +93,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);
@ -165,14 +166,15 @@ 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 Dash 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\"")
);
},
}.ToString());
int nGenerate = request.params[0].get_int();
uint64_t nMaxTries = 1000000;
@ -202,9 +204,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"
" \"currentblocksize\": nnn, (numeric) The last block size\n"
@ -215,10 +217,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);
@ -249,14 +253,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\" 10000")
},
RPCExamples{
HelpExampleCli("prioritisetransaction", "\"txid\" 10000")
+ HelpExampleRpc("prioritisetransaction", "\"txid\", 10000")
);
},
}.ToString());
LOCK(cs_main);
@ -323,9 +328,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
},
},
"\"template_request\""},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"capabilities\" : [ \"capability\", ... ], (array of strings) specific client side supported features\n"
" \"version\" : n, (numeric) The preferred block version\n"
@ -386,11 +390,12 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
" \"superblocks_enabled\" : true|false, (boolean) true, if superblock payments are enabled\n"
" \"coinbase_payload\" : \"xxxxxxxx\" (string) coinbase transaction payload data encoded in hexadecimal\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getblocktemplate", "")
},
RPCExamples{
HelpExampleCli("getblocktemplate", "")
+ HelpExampleRpc("getblocktemplate", "")
);
},
}.ToString());
LOCK(cs_main);
@ -737,13 +742,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 */ "", "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>();
@ -793,13 +798,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" +
},
RPCExamples{
HelpExampleCli("submitheader", "\"aabbcc\"") +
HelpExampleRpc("submitheader", "\"aabbcc\""));
HelpExampleRpc("submitheader", "\"aabbcc\"")
},
}.ToString());
}
CBlockHeader h;
@ -841,9 +848,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"
@ -854,9 +860,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);
@ -900,9 +908,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
{"threshold", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "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. Default: 0.95"},
}}
.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"
@ -924,9 +931,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);

View File

@ -204,19 +204,20 @@ static UniValue validateaddress(const JSONRPCRequest& request)
"\nReturn information about the given dash address.\n",
{
{"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The dash address to validate"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n"
" \"address\" : \"address\", (string) The dash address validated\n"
" \"scriptPubKey\" : \"hex\", (string) The hex-encoded scriptPubKey generated by the address\n"
" \"isscript\" : true|false, (boolean) If the key is a script\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("validateaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"")
},
RPCExamples{
HelpExampleCli("validateaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"")
+ HelpExampleRpc("validateaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"")
);
},
}.ToString());
CTxDestination dest = DecodeDestination(request.params[0].get_str());
bool isValid = IsValidDestination(dest);
@ -251,20 +252,20 @@ static UniValue createmultisig(const JSONRPCRequest& request)
{
{"key", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The hex-encoded public key"},
}},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"address\":\"multisigaddress\", (string) The value of the new multisig address.\n"
" \"redeemScript\":\"script\" (string) The string value of the hex-encoded redemption script.\n"
"}\n"
"\nExamples:\n"
},
RPCExamples{
"\nCreate a multisig address from 2 public keys\n"
+ HelpExampleCli("createmultisig", "2 \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("createmultisig", "2, \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"")
;
},
}.ToString();
throw std::runtime_error(msg);
}
@ -431,11 +432,11 @@ static UniValue verifymessage(const JSONRPCRequest& request)
{"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The dash address to use for the signature."},
{"signature", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The signature provided by the signer in base 64 encoding (see signmessage)."},
{"message", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The message that was signed."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"true|false (boolean) If the signature is verified or not.\n"
"\nExamples:\n"
},
RPCExamples{
"\nUnlock the wallet for 30 seconds\n"
+ HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
"\nCreate the signature\n"
@ -444,7 +445,8 @@ static UniValue verifymessage(const JSONRPCRequest& request)
+ HelpExampleCli("verifymessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"signature\" \"my message\"") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("verifymessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", \"signature\", \"my message\"")
);
},
}.ToString());
LOCK(cs_main);
@ -488,18 +490,19 @@ static UniValue signmessagewithprivkey(const JSONRPCRequest& request)
{
{"privkey", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The private key to sign the message with."},
{"message", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The message to create a signature of."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"\"signature\" (string) The signature of the message encoded in base 64\n"
"\nExamples:\n"
},
RPCExamples{
"\nCreate the signature\n"
+ HelpExampleCli("signmessagewithprivkey", "\"privkey\" \"my message\"") +
"\nVerify the signature\n"
+ HelpExampleCli("verifymessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"signature\" \"my message\"") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("signmessagewithprivkey", "\"privkey\", \"my message\"")
);
},
}.ToString());
std::string strPrivkey = request.params[0].get_str();
std::string strMessage = request.params[1].get_str();
@ -529,8 +532,10 @@ static UniValue setmocktime(const JSONRPCRequest& request)
{
{"timestamp", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "Unix seconds-since-epoch timestamp\n"
" Pass 0 to go back to using the system time."},
}}
.ToString()
},
RPCResults{},
RPCExamples{""},
}.ToString()
);
if (!Params().MineBlocksOnDemand())
@ -1119,9 +1124,9 @@ static UniValue getmemoryinfo(const JSONRPCRequest& request)
{"mode", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "determines what kind of information is returned. This argument is optional, the default mode is \"stats\".\n"
" - \"stats\" returns general statistics about memory usage in the daemon.\n"
" - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+)."},
}}
.ToString() +
"\nResult (mode \"stats\"):\n"
},
{
RPCResult{"mode \"stats\"",
"{\n"
" \"locked\": { (json object) Information about locked memory manager\n"
" \"used\": xxxxx, (numeric) Number of bytes used\n"
@ -1132,12 +1137,16 @@ static UniValue getmemoryinfo(const JSONRPCRequest& request)
" \"chunks_free\": xxxxx, (numeric) Number unused chunks\n"
" }\n"
"}\n"
"\nResult (mode \"mallocinfo\"):\n"
},
RPCResult{"mode \"mallocinfo\"",
"\"<malloc version=\"1\">...\"\n"
"\nExamples:\n"
+ HelpExampleCli("getmemoryinfo", "")
},
},
RPCExamples{
HelpExampleCli("getmemoryinfo", "")
+ HelpExampleRpc("getmemoryinfo", "")
);
},
}.ToString());
std::string mode = request.params[0].isNull() ? "stats" : request.params[0].get_str();
if (mode == "stats") {
@ -1199,17 +1208,18 @@ static UniValue logging(const JSONRPCRequest& request)
{
{"exclude_category", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "the valid logging category"},
}},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{ (json object where keys are the logging categories, and values indicates its status\n"
" \"category\": true|false, (bool) if being debug logged or not. false:inactive, true:active\n"
" ...\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")
+ HelpExampleRpc("logging", "[\"all\"], [\"libevent\"]")
);
},
RPCExamples{
HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")
+ HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"")
},
}.ToString());
}
uint64_t original_log_categories = LogInstance().GetCategoryMask();
@ -1253,9 +1263,11 @@ static UniValue echo(const JSONRPCRequest& request)
"\nSimply echo back the input arguments. This command is for testing.\n"
"\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in "
"dash-cli and the GUI. There is no server-side difference.",
{}}
.ToString() +
"");
{},
RPCResults{},
RPCExamples{""},
}.ToString()
);
return request.params;
}

View File

@ -32,14 +32,16 @@ static UniValue getconnectioncount(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"getconnectioncount",
"\nReturns the number of connections to other nodes.\n", {}}
.ToString() +
"\nResult:\n"
"\nReturns the number of connections to other nodes.\n",
{},
RPCResult{
"n (numeric) The connection count\n"
"\nExamples:\n"
+ HelpExampleCli("getconnectioncount", "")
},
RPCExamples{
HelpExampleCli("getconnectioncount", "")
+ HelpExampleRpc("getconnectioncount", "")
);
},
}.ToString());
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
@ -55,12 +57,13 @@ static UniValue ping(const JSONRPCRequest& request)
"\nRequests that a ping be sent to all other nodes, to measure ping time.\n"
"Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n"
"Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n",
{}}
.ToString() +
"\nExamples:\n"
+ HelpExampleCli("ping", "")
{},
RPCResults{},
RPCExamples{
HelpExampleCli("ping", "")
+ HelpExampleRpc("ping", "")
);
},
}.ToString());
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
@ -77,9 +80,9 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"getpeerinfo",
"\nReturns data about each connected network node as a json array of objects.\n", {}}
.ToString() +
"\nResult:\n"
"\nReturns data about each connected network node as a json array of objects.\n",
{},
RPCResult{
"[\n"
" {\n"
" \"id\": n, (numeric) Peer index\n"
@ -137,10 +140,12 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
" }\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getpeerinfo", "")
},
RPCExamples{
HelpExampleCli("getpeerinfo", "")
+ HelpExampleRpc("getpeerinfo", "")
);
},
}.ToString());
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
@ -246,12 +251,13 @@ static UniValue addnode(const JSONRPCRequest& request)
{
{"node", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The node (see getpeerinfo for nodes)"},
{"command", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once"},
}}
.ToString() +
"\nExamples:\n"
+ HelpExampleCli("addnode", "\"192.168.0.6:9999\" \"onetry\"")
},
RPCResults{},
RPCExamples{
HelpExampleCli("addnode", "\"192.168.0.6:9999\" \"onetry\"")
+ HelpExampleRpc("addnode", "\"192.168.0.6:9999\", \"onetry\"")
);
},
}.ToString());
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
@ -288,16 +294,17 @@ static UniValue disconnectnode(const JSONRPCRequest& request)
"\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n"
"\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n",
{
{"address", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "The IP address/port of the node"},
{"nodeid", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "The node ID (see getpeerinfo for node IDs)"},
}}
.ToString() +
"\nExamples:\n"
+ HelpExampleCli("disconnectnode", "\"192.168.0.6:9999\"")
{"address", RPCArg::Type::STR, /* opt */ true, /* default_val */ "fallback to nodeid", "The IP address/port of the node"},
{"nodeid", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "fallback to address", "The node ID (see getpeerinfo for node IDs)"},
},
RPCResults{},
RPCExamples{
HelpExampleCli("disconnectnode", "\"192.168.0.6:9999\"")
+ HelpExampleCli("disconnectnode", "\"\" 1")
+ HelpExampleRpc("disconnectnode", "\"192.168.0.6:9999\"")
+ HelpExampleRpc("disconnectnode", "\"\", 1")
);
},
}.ToString());
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
@ -333,9 +340,8 @@ static UniValue getaddednodeinfo(const JSONRPCRequest& request)
"(note that onetry addnodes are not listed here)\n",
{
{"node", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "If provided, return information about this specific node, otherwise all nodes are returned."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"[\n"
" {\n"
" \"addednode\" : \"192.168.0.201\", (string) The node IP address or name (as provided to addnode)\n"
@ -349,11 +355,13 @@ static UniValue getaddednodeinfo(const JSONRPCRequest& request)
" }\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getaddednodeinfo", "")
},
RPCExamples{
HelpExampleCli("getaddednodeinfo", "")
+ HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"")
+ HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")
);
},
}.ToString());
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
@ -401,9 +409,8 @@ static UniValue getnettotals(const JSONRPCRequest& request)
RPCHelpMan{"getnettotals",
"\nReturns information about network traffic, including bytes in, bytes out,\n"
"and current time.\n",
{}}
.ToString() +
"\nResult:\n"
{},
RPCResult{
"{\n"
" \"totalbytesrecv\": n, (numeric) Total bytes received\n"
" \"totalbytessent\": n, (numeric) Total bytes sent\n"
@ -418,10 +425,12 @@ static UniValue getnettotals(const JSONRPCRequest& request)
" \"time_left_in_cycle\": t (numeric) Seconds left in current time cycle\n"
" }\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getnettotals", "")
},
RPCExamples{
HelpExampleCli("getnettotals", "")
+ HelpExampleRpc("getnettotals", "")
);
},
}.ToString());
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
@ -467,9 +476,9 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"getnetworkinfo",
"Returns an object containing various state info regarding P2P networking.\n", {}}
.ToString() +
"\nResult:\n"
"Returns an object containing various state info regarding P2P networking.\n",
{},
RPCResult{
"{\n"
" \"version\": xxxxx, (numeric) the server version\n"
" \"buildversion\": \"x.x.x.x-xxx\", (string) the server build version including RC info or commit as relevant\n"
@ -507,10 +516,12 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
" ]\n"
" \"warnings\": \"...\" (string) any network and blockchain warnings\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getnetworkinfo", "")
},
RPCExamples{
HelpExampleCli("getnetworkinfo", "")
+ HelpExampleRpc("getnetworkinfo", "")
);
},
}.ToString());
LOCK(cs_main);
UniValue obj(UniValue::VOBJ);
@ -580,15 +591,16 @@ static UniValue setban(const JSONRPCRequest& request)
{
{"subnet", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default is /32 = single IP)"},
{"command", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "'add' to add an IP/Subnet to the list, 'remove' to remove an IP/Subnet from the list"},
{"bantime", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "time in seconds how long (or until when if [absolute] is set) the IP is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument)"},
{"absolute", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "", "If set, the bantime must be an absolute timestamp in seconds since epoch (Jan 1 1970 GMT)"},
}}
.ToString() +
"\nExamples:\n"
+ HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400")
{"bantime", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "time in seconds how long (or until when if [absolute] is set) the IP is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument)"},
{"absolute", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "If set, the bantime must be an absolute timestamp in seconds since epoch (Jan 1 1970 GMT)"},
},
RPCResults{},
RPCExamples{
HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400")
+ HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"")
+ HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")
);
},
}.ToString());
if (!g_banman) {
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
}
@ -651,12 +663,14 @@ static UniValue listbanned(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"listbanned",
"\nList all banned IPs/Subnets.\n", {}}
.ToString() +
"\nExamples:\n"
+ HelpExampleCli("listbanned", "")
"\nList all banned IPs/Subnets.\n",
{},
RPCResults{},
RPCExamples{
HelpExampleCli("listbanned", "")
+ HelpExampleRpc("listbanned", "")
);
},
}.ToString());
if(!g_banman) {
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
@ -686,12 +700,14 @@ static UniValue clearbanned(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
RPCHelpMan{"clearbanned",
"\nClear all banned IPs.\n", {}}
.ToString() +
"\nExamples:\n"
+ HelpExampleCli("clearbanned", "")
"\nClear all banned IPs.\n",
{},
RPCResults{},
RPCExamples{
HelpExampleCli("clearbanned", "")
+ HelpExampleRpc("clearbanned", "")
);
},
}.ToString());
if (!g_banman) {
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
}
@ -709,8 +725,10 @@ static UniValue setnetworkactive(const JSONRPCRequest& request)
"\nDisable/enable all p2p network activity.\n",
{
{"state", RPCArg::Type::BOOL, /* opt */ false, /* default_val */ "", "true to enable networking, false to disable"},
}}
.ToString()
},
RPCResults{},
RPCExamples{""},
}.ToString()
);
}
@ -731,9 +749,8 @@ static UniValue getnodeaddresses(const JSONRPCRequest& request)
"\nReturn known addresses which can potentially be used to find new nodes in the network\n",
{
{"count", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "1", "How many addresses to return. Limited to the smaller of " + std::to_string(ADDRMAN_GETADDR_MAX) + " or " + std::to_string(ADDRMAN_GETADDR_MAX_PCT) + "% of all known addresses."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"[\n"
" {\n"
" \"time\": ttt, (numeric) Timestamp in seconds since epoch (Jan 1 1970 GMT) keeping track of when the node was last seen\n"
@ -743,10 +760,12 @@ static UniValue getnodeaddresses(const JSONRPCRequest& request)
" }\n"
" ,....\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getnodeaddresses", "8")
},
RPCExamples{
HelpExampleCli("getnodeaddresses", "8")
+ HelpExampleRpc("getnodeaddresses", "8")
);
},
}.ToString());
}
if (!g_connman) {
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");

View File

@ -121,13 +121,13 @@ static UniValue getrawtransaction(const JSONRPCRequest& request)
{
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id"},
{"verbose", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "If false, return a string, otherwise return a json object"},
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, /* default_val */ "", "The block in which to look for the transaction"},
}}
.ToString() +
"\nResult (if verbose is not set or set to false):\n"
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, /* default_val */ "null", "The block in which to look for the transaction"},
},
{
RPCResult{"if verbose is not set or set to false",
"\"data\" (string) The serialized, hex-encoded data for 'txid'\n"
"\nResult (if verbose is set to true):\n"
},
RPCResult{"if verbose is set to true",
"{\n"
" \"in_active_chain\": b, (bool) Whether specified block is in the active chain or not (only present with explicit \"blockhash\" argument)\n"
" \"txid\" : \"id\", (string) The transaction id (same as provided)\n"
@ -175,14 +175,16 @@ static UniValue getrawtransaction(const JSONRPCRequest& request)
" \"instantlock_internal\" : true|false, (bool) Current internal transaction lock state\n"
" \"chainlock\" : true|false, (bool) The state of the corresponding block chainlock\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getrawtransaction", "\"mytxid\"")
},
},
RPCExamples{
HelpExampleCli("getrawtransaction", "\"mytxid\"")
+ HelpExampleCli("getrawtransaction", "\"mytxid\" true")
+ HelpExampleRpc("getrawtransaction", "\"mytxid\", true")
+ HelpExampleCli("getrawtransaction", "\"mytxid\" false \"myblockhash\"")
+ HelpExampleCli("getrawtransaction", "\"mytxid\" true \"myblockhash\"")
);
},
}.ToString());
bool in_active_chain = true;
uint256 hash = ParseHashV(request.params[0], "parameter 1");
@ -260,16 +262,17 @@ static UniValue gettxoutproof(const JSONRPCRequest& request)
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "A transaction hash"},
},
},
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, /* default_val */ "", "If specified, looks for txid in the block with this hash"},
}}
.ToString() +
"\nResult:\n"
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, /* default_val */ "null", "If specified, looks for txid in the block with this hash"},
},
RPCResult{
"\"data\" (string) A string that is a serialized, hex-encoded data for the proof.\n"
"\nExamples:\n"
+ HelpExampleCli("gettxoutproof", "'[\"mytxid\",...]'")
},
RPCExamples{
HelpExampleCli("gettxoutproof", "'[\"mytxid\",...]'")
+ HelpExampleCli("gettxoutproof", "'[\"mytxid\",...]' \"blockhash\"")
+ HelpExampleRpc("gettxoutproof", "[\"mytxid\",...], \"blockhash\"")
},
}.ToString()
);
std::set<uint256> setTxids;
@ -354,14 +357,15 @@ static UniValue verifytxoutproof(const JSONRPCRequest& request)
"and throwing an RPC error if the block is not in our best chain\n",
{
{"proof", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The hex-encoded proof generated by gettxoutproof"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"[\"txid\"] (array, strings) The txid(s) which the proof commits to, or empty array if the proof can not be validated.\n"
"\nExamples:\n"
+ HelpExampleCli("verifytxoutproof", "\"proof\"")
},
RPCExamples{
HelpExampleCli("verifytxoutproof", "\"proof\"")
+ HelpExampleRpc("gettxoutproof", "\"proof\"")
},
}.ToString()
);
CDataStream ssMB(ParseHexV(request.params[0], "proof"), SER_NETWORK, PROTOCOL_VERSION);
@ -521,17 +525,17 @@ static UniValue createrawtransaction(const JSONRPCRequest& request)
},
},
{"locktime", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"\"transaction\" (string) hex string of the transaction\n"
"\nExamples:\n"
+ HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"address\\\":0.01}]\"")
},
RPCExamples{
HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"address\\\":0.01}]\"")
+ HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
+ HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"[{\\\"address\\\":0.01}]\"")
+ HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
);
},
}.ToString());
}
RPCTypeCheck(request.params, {
@ -554,9 +558,8 @@ static UniValue decoderawtransaction(const JSONRPCRequest& request)
"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n",
{
{"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction hex string"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"txid\" : \"id\", (string) The transaction id\n"
" \"size\" : n, (numeric) The transaction size\n"
@ -595,11 +598,12 @@ static UniValue decoderawtransaction(const JSONRPCRequest& request)
" \"extraPayloadSize\" : n (numeric) Size of DIP2 extra payload. Only present if it's a special TX\n"
" \"extraPayload\" : \"hex\" (string) Hex-encoded DIP2 extra payload data. Only present if it's a special TX\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("decoderawtransaction", "\"hexstring\"")
},
RPCExamples{
HelpExampleCli("decoderawtransaction", "\"hexstring\"")
+ HelpExampleRpc("decoderawtransaction", "\"hexstring\"")
);
},
}.ToString());
RPCTypeCheck(request.params, {UniValue::VSTR});
@ -622,9 +626,8 @@ static UniValue decodescript(const JSONRPCRequest& request)
"\nDecode a hex-encoded script.\n",
{
{"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded script"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"asm\":\"asm\", (string) Script public key\n"
" \"hex\":\"hex\", (string) hex-encoded public key\n"
@ -636,10 +639,12 @@ static UniValue decodescript(const JSONRPCRequest& request)
" ],\n"
" \"p2sh\",\"address\" (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("decodescript", "\"hexstring\"")
},
RPCExamples{
HelpExampleCli("decodescript", "\"hexstring\"")
+ HelpExampleRpc("decodescript", "\"hexstring\"")
);
},
}.ToString());
RPCTypeCheck(request.params, {UniValue::VSTR});
@ -692,14 +697,14 @@ static UniValue combinerawtransaction(const JSONRPCRequest& request)
{"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "A transaction hash"},
},
},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"\"hex\" (string) The hex-encoded raw transaction with signature(s)\n"
"\nExamples:\n"
+ HelpExampleCli("combinerawtransaction", "'[\"myhex1\", \"myhex2\", \"myhex3\"]'")
);
},
RPCExamples{
HelpExampleCli("combinerawtransaction", "'[\"myhex1\", \"myhex2\", \"myhex3\"]'")
},
}.ToString());
UniValue txs = request.params[0].get_array();
@ -932,9 +937,8 @@ static UniValue signrawtransactionwithkey(const JSONRPCRequest& request)
" \"NONE|ANYONECANPAY\"\n"
" \"SINGLE|ANYONECANPAY\"\n"
},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"hex\" : \"value\", (string) The hex-encoded raw transaction with signature(s)\n"
" \"complete\" : true|false, (boolean) If the transaction has a complete set of signatures\n"
@ -949,11 +953,12 @@ static UniValue signrawtransactionwithkey(const JSONRPCRequest& request)
" ,...\n"
" ]\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("signrawtransactionwithkey", "\"myhex\"")
},
RPCExamples{
HelpExampleCli("signrawtransactionwithkey", "\"myhex\"")
+ HelpExampleRpc("signrawtransactionwithkey", "\"myhex\"")
);
},
}.ToString());
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VARR, UniValue::VSTR}, true);
@ -988,11 +993,11 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
{"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Allow high fees"},
{"instantsend", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Deprecated and ignored"},
{"bypasslimits", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Bypass transaction policy limits"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"\"hex\" (string) The transaction hash in hex\n"
"\nExamples:\n"
},
RPCExamples{
"\nCreate a transaction\n"
+ HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
"Sign the transaction, and get back the hex\n"
@ -1001,7 +1006,8 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
+ HelpExampleCli("sendrawtransaction", "\"signedhex\"") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("sendrawtransaction", "\"signedhex\"")
);
},
}.ToString());
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VBOOL});
@ -1041,9 +1047,8 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
},
},
{"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Allow high fees"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"[ (array) The result of the mempool acceptance test for each raw transaction in the input array.\n"
" Length is exactly one for now.\n"
" {\n"
@ -1052,7 +1057,8 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
" \"reject-reason\" (string) Rejection string (only present when 'allowed' is false)\n"
" }\n"
"]\n"
"\nExamples:\n"
},
RPCExamples{
"\nCreate a transaction\n"
+ HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
"Sign the transaction, and get back the hex\n"
@ -1061,7 +1067,8 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
+ HelpExampleCli("testmempoolaccept", "[\"signedhex\"]") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]")
);
},
}.ToString());
}
RPCTypeCheck(request.params, {UniValue::VARR, UniValue::VBOOL});
@ -1135,9 +1142,8 @@ UniValue decodepsbt(const JSONRPCRequest& request)
"\nReturn a JSON object representing the serialized, base64-encoded partially signed Dash transaction.\n",
{
{"psbt", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The PSBT base64 string"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"tx\" : { (json object) The decoded network-serialized unsigned transaction.\n"
" ... The layout is the same as the output of decoderawtransaction.\n"
@ -1204,10 +1210,11 @@ UniValue decodepsbt(const JSONRPCRequest& request)
" ]\n"
" \"fee\" : fee (numeric, optional) The transaction fee paid if all UTXOs slots in the PSBT have been filled.\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("decodepsbt", "\"psbt\"")
);
},
RPCExamples{
HelpExampleCli("decodepsbt", "\"psbt\"")
},
}.ToString());
RPCTypeCheck(request.params, {UniValue::VSTR});
@ -1366,13 +1373,14 @@ UniValue combinepsbt(const JSONRPCRequest& request)
{"psbt", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "A base64 string of a PSBT"},
},
},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
" \"psbt\" (string) The base64-encoded partially signed transaction\n"
"\nExamples:\n"
+ HelpExampleCli("combinepsbt", "[\"mybase64_1\", \"mybase64_2\", \"mybase64_3\"]")
);
},
RPCExamples{
HelpExampleCli("combinepsbt", "[\"mybase64_1\", \"mybase64_2\", \"mybase64_3\"]")
},
}.ToString());
RPCTypeCheck(request.params, {UniValue::VARR}, true);
@ -1415,19 +1423,19 @@ UniValue finalizepsbt(const JSONRPCRequest& request)
{"psbt", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "A base64 string of a PSBT"},
{"extract", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "true", "If true and the transaction is complete,\n"
" extract and return the complete transaction in normal network serialization instead of the PSBT."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{\n"
" \"psbt\" : \"value\", (string) The base64-encoded partially signed transaction if not extracted\n"
" \"hex\" : \"value\", (string) The hex-encoded network transaction if extracted\n"
" \"complete\" : true|false, (boolean) If the transaction has a complete set of signatures\n"
" ]\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("finalizepsbt", "\"psbt\"")
);
},
RPCExamples{
HelpExampleCli("finalizepsbt", "\"psbt\"")
},
}.ToString());
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}, true);
@ -1497,13 +1505,14 @@ UniValue createpsbt(const JSONRPCRequest& request)
},
},
{"locktime", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
" \"psbt\" (string) The resulting raw transaction (base64-encoded string)\n"
"\nExamples:\n"
+ HelpExampleCli("createpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
);
},
RPCExamples{
HelpExampleCli("createpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")
},
}.ToString());
RPCTypeCheck(request.params, {
@ -1543,16 +1552,17 @@ UniValue converttopsbt(const JSONRPCRequest& request)
{"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The hex string of a raw transaction"},
{"permitsigdata", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "If true, any signatures in the input will be discarded and conversion.\n"
" will continue. If false, RPC will fail if any signatures are present."},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
" \"psbt\" (string) The resulting raw transaction (base64-encoded string)\n"
"\nExamples:\n"
},
RPCExamples{
"\nCreate a transaction\n"
+ HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") +
"\nConvert the transaction to a PSBT\n"
+ HelpExampleCli("converttopsbt", "\"rawtransaction\"")
);
},
}.ToString());
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VBOOL}, true);

View File

@ -276,12 +276,14 @@ UniValue help(const JSONRPCRequest& jsonRequest)
RPCHelpMan{"help",
"\nList all commands, or get help for a specified command.\n",
{
{"command", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "The command to get help on"},
{"command", RPCArg::Type::STR, /* opt */ true, /* default_val */ "all commands", "The command to get help on"},
{"subcommand", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "The subcommand to get help on. Please note that not all subcommands support this at the moment"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"\"text\" (string) The help text\n"
},
RPCExamples{""},
}.ToString()
);
std::string strCommand, strSubCommand;
@ -303,8 +305,11 @@ UniValue stop(const JSONRPCRequest& jsonRequest)
if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
throw std::runtime_error(
RPCHelpMan{"stop",
"\nStop Dash Core server.", {}}
.ToString());
"\nStop Dash Core server.",
{},
RPCResults{},
RPCExamples{""},
}.ToString());
// Event loop will exit after current HTTP requests have been handled, so
// this reply will get back to the client.
StartShutdown();
@ -319,14 +324,16 @@ static UniValue uptime(const JSONRPCRequest& jsonRequest)
if (jsonRequest.fHelp || jsonRequest.params.size() > 0)
throw std::runtime_error(
RPCHelpMan{"uptime",
"\nReturns the total uptime of the server.\n", {}}
.ToString() +
"\nResult:\n"
"\nReturns the total uptime of the server.\n",
{},
RPCResult{
"ttt (numeric) The number of seconds that the server has been running\n"
"\nExamples:\n"
+ HelpExampleCli("uptime", "")
},
RPCExamples{
HelpExampleCli("uptime", "")
+ HelpExampleRpc("uptime", "")
);
},
}.ToString());
return GetTime() - GetStartupTime();
}

View File

@ -219,8 +219,12 @@ struct Sections {
}
};
RPCHelpMan::RPCHelpMan(const std::string& name, const std::string& description, const std::vector<RPCArg>& args)
: m_name{name}, m_description{description}, m_args{args}
RPCHelpMan::RPCHelpMan(std::string name, std::string description, std::vector<RPCArg> args, RPCResults results, RPCExamples examples)
: m_name{std::move(name)},
m_description{std::move(description)},
m_args{std::move(args)},
m_results{std::move(results)},
m_examples{std::move(examples)}
{
std::set<std::string> named_args;
for (const auto& arg : m_args) {
@ -229,6 +233,25 @@ RPCHelpMan::RPCHelpMan(const std::string& name, const std::string& description,
}
}
std::string RPCResults::ToDescriptionString() const
{
std::string result;
for (const auto& r : m_results) {
if (r.m_cond.empty()) {
result += "\nResult:\n";
} else {
result += "\nResult (" + r.m_cond + "):\n";
}
result += r.m_result;
}
return result;
}
std::string RPCExamples::ToDescriptionString() const
{
return m_examples.empty() ? m_examples : "\nExamples:\n" + m_examples;
}
std::string RPCHelpMan::ToString() const
{
std::string ret;
@ -269,6 +292,12 @@ std::string RPCHelpMan::ToString() const
}
ret += sections.ToString();
// Result
ret += m_results.ToDescriptionString();
// Examples
ret += m_examples.ToDescriptionString();
return ret;
}

View File

@ -116,10 +116,62 @@ struct RPCArg {
std::string ToDescriptionString(bool implicitly_required = false) const;
};
struct RPCResult {
const std::string m_cond;
const std::string m_result;
explicit RPCResult(std::string result)
: m_cond{}, m_result{std::move(result)}
{
assert(!m_result.empty());
}
RPCResult(std::string cond, std::string result)
: m_cond{std::move(cond)}, m_result{std::move(result)}
{
assert(!m_cond.empty());
assert(!m_result.empty());
}
};
struct RPCResults {
const std::vector<RPCResult> m_results;
RPCResults()
: m_results{}
{
}
RPCResults(RPCResult result)
: m_results{{result}}
{
}
RPCResults(std::initializer_list<RPCResult> results)
: m_results{results}
{
}
/**
* Return the description string.
*/
std::string ToDescriptionString() const;
};
struct RPCExamples {
const std::string m_examples;
RPCExamples(
std::string examples)
: m_examples(std::move(examples))
{
}
std::string ToDescriptionString() const;
};
class RPCHelpMan
{
public:
RPCHelpMan(const std::string& name, const std::string& description, const std::vector<RPCArg>& args);
RPCHelpMan(std::string name, std::string description, std::vector<RPCArg> args, RPCResults results, RPCExamples examples);
std::string ToString() const;
@ -127,6 +179,8 @@ private:
const std::string m_name;
const std::string m_description;
const std::vector<RPCArg> m_args;
const RPCResults m_results;
const RPCExamples m_examples;
};
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr);

View File

@ -92,16 +92,16 @@ UniValue importprivkey(const JSONRPCRequest& request)
throw std::runtime_error(
RPCHelpMan{"importprivkey",
"\nAdds a private key (as returned by dumpprivkey) to your wallet. Requires a new wallet backup.\n"
"Hint: use importmulti to import more than one private key.\n",
"Hint: use importmulti to import more than one private key.\n"
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
"may report that the imported key exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n",
{
{"privkey", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The private key (see dumpprivkey)"},
{"label", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "An optional label"},
{"rescan", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "true", "Rescan the wallet for transactions"},
}}
.ToString() +
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
"may report that the imported key exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
"\nExamples:\n"
},
RPCResults{},
RPCExamples{
"\nDump a private key\n"
+ HelpExampleCli("dumpprivkey", "\"myaddress\"") +
"\nImport the private key with rescan\n"
@ -112,7 +112,8 @@ UniValue importprivkey(const JSONRPCRequest& request)
+ HelpExampleCli("importprivkey", "\"mykey\" \"\" false") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false")
);
},
}.ToString());
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled");
@ -183,16 +184,18 @@ UniValue abortrescan(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() > 0)
throw std::runtime_error(
RPCHelpMan{"abortrescan",
"\nStops current wallet rescan triggered by an RPC call, e.g. by an importprivkey call.\n", {}}
.ToString() +
"\nExamples:\n"
"\nStops current wallet rescan triggered by an RPC call, e.g. by an importprivkey call.\n",
{},
RPCResults{},
RPCExamples{
"\nImport a private key\n"
+ HelpExampleCli("importprivkey", "\"mykey\"") +
"\nAbort the running wallet rescan\n"
+ HelpExampleCli("abortrescan", "") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("abortrescan", "")
);
},
}.ToString());
if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) return false;
pwallet->AbortRescan();
@ -246,27 +249,28 @@ UniValue importaddress(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 4)
throw std::runtime_error(
RPCHelpMan{"importaddress",
"\nAdds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n",
"\nAdds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
"may report that the imported address exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
"If you have the full public key, you should call importpubkey instead of this.\n"
"\nNote: If you import a non-standard raw script in hex form, outputs sending to it will be treated\n"
"as change, and not show up in many RPCs.\n",
{
{"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The Dash address (or hex-encoded script)"},
{"label", RPCArg::Type::STR, /* opt */ true, /* default_val */ "\"\"", "An optional label"},
{"rescan", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "true", "Rescan the wallet for transactions"},
{"p2sh", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Add the P2SH version of the script as well"},
}}
.ToString() +
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
"may report that the imported address exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
"If you have the full public key, you should call importpubkey instead of this.\n"
"\nNote: If you import a non-standard raw script in hex form, outputs sending to it will be treated\n"
"as change, and not show up in many RPCs.\n"
"\nExamples:\n"
},
RPCResults{},
RPCExamples{
"\nImport an address with rescan\n"
+ HelpExampleCli("importaddress", "\"myaddress\"") +
"\nImport using a label without rescan\n"
+ HelpExampleCli("importaddress", "\"myaddress\" \"testing\" false") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false")
);
},
}.ToString());
std::string strLabel;
@ -332,8 +336,10 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
{
{"rawtransaction", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "A raw transaction in hex funding an already-existing address in wallet"},
{"txoutproof", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The hex output from gettxoutproof that contains the transaction"},
}}
.ToString()
},
RPCResults{},
RPCExamples{""},
}.ToString()
);
CMutableTransaction tx;
@ -399,13 +405,14 @@ UniValue removeprunedfunds(const JSONRPCRequest& request)
"\nDeletes the specified transaction from the wallet. Meant for use with pruned wallets and as a companion to importprunedfunds. This will affect wallet balances.\n",
{
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The hex-encoded id of the transaction you are deleting"},
}}
.ToString() +
"\nExamples:\n"
+ HelpExampleCli("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"") +
},
RPCResults{},
RPCExamples{
HelpExampleCli("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"")
);
},
}.ToString());
auto locked_chain = pwallet->chain().lock();
LOCK(pwallet->cs_wallet);
@ -438,23 +445,24 @@ UniValue importpubkey(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
throw std::runtime_error(
RPCHelpMan{"importpubkey",
"\nAdds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n",
"\nAdds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
"may report that the imported pubkey exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n",
{
{"pubkey", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The hex-encoded public key"},
{"label", RPCArg::Type::STR, /* opt */ true, /* default_val */ "\"\"", "An optional label"},
{"rescan", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "true", "Rescan the wallet for transactions"},
}}
.ToString() +
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
"may report that the imported pubkey exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
"\nExamples:\n"
},
RPCResults{},
RPCExamples{
"\nImport a public key with rescan\n"
+ HelpExampleCli("importpubkey", "\"mypubkey\"") +
"\nImport using a label without rescan\n"
+ HelpExampleCli("importpubkey", "\"mypubkey\" \"testing\" false") +
"\nAs a JSON-RPC call\n"
+ HelpExampleRpc("importpubkey", "\"mypubkey\", \"testing\", false")
);
},
}.ToString());
std::string strLabel;
@ -512,16 +520,17 @@ UniValue importwallet(const JSONRPCRequest& request)
"\nImports keys from a wallet dump file (see dumpwallet). Requires a new wallet backup to include imported keys.\n",
{
{"filename", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The wallet file"},
}}
.ToString() +
"\nExamples:\n"
},
RPCResults{},
RPCExamples{
"\nDump the wallet\n"
+ HelpExampleCli("dumpwallet", "\"test\"") +
"\nImport the wallet\n"
+ HelpExampleCli("importwallet", "\"test\"") +
"\nImport using the json rpc call\n"
+ HelpExampleRpc("importwallet", "\"test\"")
);
},
}.ToString());
if (fPruneMode)
throw JSONRPCError(RPC_WALLET_ERROR, "Importing wallets is disabled in pruned mode");
@ -817,15 +826,16 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
"Then the importprivkey can be used with this output\n",
{
{"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The dash address for the private key"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"\"key\" (string) The private key\n"
"\nExamples:\n"
+ HelpExampleCli("dumpprivkey", "\"myaddress\"")
},
RPCExamples{
HelpExampleCli("dumpprivkey", "\"myaddress\"")
+ HelpExampleCli("importprivkey", "\"mykey\"")
+ HelpExampleRpc("dumpprivkey", "\"myaddress\"")
);
},
}.ToString());
auto locked_chain = pwallet->chain().lock();
LOCK(pwallet->cs_wallet);
@ -912,18 +922,19 @@ UniValue dumpwallet(const JSONRPCRequest& request)
"only backing up the seed itself, and must be backed up too (e.g. ensure you back up the whole dumpfile).\n",
{
{"filename", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The filename with path (either absolute or relative to dashd)"},
}}
.ToString() +
"\nResult:\n"
},
RPCResult{
"{ (json object)\n"
" \"keys\" : { (int) The number of keys contained in the wallet dump\n"
" \"filename\" : { (string) The filename with full absolute path\n"
" \"warning\" : { (string) A warning about not sharing the wallet dump with anyone\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("dumpwallet", "\"test\"")
},
RPCExamples{
HelpExampleCli("dumpwallet", "\"test\"")
+ HelpExampleRpc("dumpwallet", "\"test\"")
);
},
}.ToString());
auto locked_chain = pwallet->chain().lock();
LockAnnotation lock(::cs_main);
@ -1461,7 +1472,9 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
if (mainRequest.fHelp || mainRequest.params.size() < 1 || mainRequest.params.size() > 2)
throw std::runtime_error(
RPCHelpMan{"importmulti",
"\nImport addresses/scripts (with private or public keys, redeem script (P2SH)), rescanning all addresses in one-shot-only (rescan can be disabled via options). Requires a new wallet backup.\n",
"\nImport addresses/scripts (with private or public keys, redeem script (P2SH)), rescanning all addresses in one-shot-only (rescan can be disabled via options). Requires a new wallet backup.\n"
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
"may report that the imported keys, addresses or scripts exists but related transactions are still missing.\n",
{
{"requests", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "Data to be imported",
{
@ -1509,17 +1522,18 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
{"rescan", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "true", "Stating if should rescan the blockchain after all imports"},
},
"\"options\""},
}}
.ToString() +
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
"may report that the imported keys, addresses or scripts exists but related transactions are still missing.\n"
"\nExamples:\n" +
HelpExampleCli("importmulti", "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, \"timestamp\":1455191478 }, "
"{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" }, \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
HelpExampleCli("importmulti", "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, \"timestamp\":1455191478 }]' '{ \"rescan\": false}'") +
},
RPCResult{
"\nResponse is an array with the same size as the input that has the execution result :\n"
" [{\"success\": true}, {\"success\": true, \"warnings\": [\"Ignoring irrelevant private key\"]}, {\"success\": false, \"error\": {\"code\": -1, \"message\": \"Internal Server Error\"}}, ...]\n");
},
RPCExamples{
HelpExampleCli("importmulti", "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, \"timestamp\":1455191478 }, "
"{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" }, \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") +
HelpExampleCli("importmulti", "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, \"timestamp\":1455191478 }]' '{ \"rescan\": false}'")
},
}.ToString()
);
RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ});

File diff suppressed because it is too large Load Diff

View File

@ -18,9 +18,9 @@ UniValue getzmqnotifications(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0) {
throw std::runtime_error(
RPCHelpMan{"getzmqnotifications",
"\nReturns information about the active ZeroMQ notifications.\n", {}}
.ToString() +
"\nResult:\n"
"\nReturns information about the active ZeroMQ notifications.\n",
{},
RPCResult{
"[\n"
" { (json object)\n"
" \"type\": \"pubhashtx\", (string) Type of notification\n"
@ -29,10 +29,12 @@ UniValue getzmqnotifications(const JSONRPCRequest& request)
" },\n"
" ...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("getzmqnotifications", "")
},
RPCExamples{
HelpExampleCli("getzmqnotifications", "")
+ HelpExampleRpc("getzmqnotifications", "")
);
},
}.ToString());
}
UniValue result(UniValue::VARR);