From 57841be49231fb412c48fc64c29163d6d0c51750 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 29 Jan 2019 09:55:37 -0500 Subject: [PATCH 1/4] 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 --- src/rpc/blockchain.cpp | 386 ++++++++++++++------------ src/rpc/mining.cpp | 117 ++++---- src/rpc/misc.cpp | 94 ++++--- src/rpc/net.cpp | 165 ++++++----- src/rpc/rawtransaction.cpp | 206 +++++++------- src/rpc/server.cpp | 31 ++- src/rpc/util.cpp | 33 ++- src/rpc/util.h | 56 +++- src/wallet/rpcdump.cpp | 136 +++++---- src/wallet/rpcwallet.cpp | 551 ++++++++++++++++++++----------------- src/zmq/zmqrpc.cpp | 14 +- 11 files changed, 1016 insertions(+), 773 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 0c11c2b020..f29892f3b9 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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- for \"-devnet\" and \"-devnet=\" 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}); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index b45bde00b2..b68e5cf697 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -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 blockptr = std::make_shared(); @@ -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" + - HelpExampleCli("submitheader", "\"aabbcc\"") + - HelpExampleRpc("submitheader", "\"aabbcc\"")); + }, + RPCExamples{ + HelpExampleCli("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); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 6392903856..f855af4ed3 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -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\"", "\"...\"\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; } diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 9460af4894..8fa2c5765f 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -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", "") - + HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") + }, + 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"); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 3a250778d8..f42345b4a8 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -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 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); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 569d15a569..ec8a1ba538 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -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(); } diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 8cf995f1cb..1cf82134e2 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -219,8 +219,12 @@ struct Sections { } }; -RPCHelpMan::RPCHelpMan(const std::string& name, const std::string& description, const std::vector& args) - : m_name{name}, m_description{description}, m_args{args} +RPCHelpMan::RPCHelpMan(std::string name, std::string description, std::vector 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 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; } diff --git a/src/rpc/util.h b/src/rpc/util.h index 8b76ee8bba..038b56cd6e 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -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 m_results; + + RPCResults() + : m_results{} + { + } + + RPCResults(RPCResult result) + : m_results{{result}} + { + } + + RPCResults(std::initializer_list 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& args); + RPCHelpMan(std::string name, std::string description, std::vector 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 m_args; + const RPCResults m_results; + const RPCExamples m_examples; }; RPCErrorCode RPCErrorFromTransactionError(TransactionError terr); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 54c33420ae..451aec37ff 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -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\": \"\" }, \"timestamp\":1455191478 }, " - "{ \"scriptPubKey\": { \"address\": \"\" }, \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") + - HelpExampleCli("importmulti", "'[{ \"scriptPubKey\": { \"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\": \"\" }, \"timestamp\":1455191478 }, " + "{ \"scriptPubKey\": { \"address\": \"\" }, \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") + + HelpExampleCli("importmulti", "'[{ \"scriptPubKey\": { \"address\": \"\" }, \"timestamp\":1455191478 }]' '{ \"rescan\": false}'") + }, + }.ToString() + ); RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ}); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e4d70de876..7cecfdc424 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -160,15 +160,16 @@ UniValue getnewaddress(const JSONRPCRequest& request) "If 'label' is specified, it is added to the address book \n" "so payments received with the address will be associated with 'label'.\n", { - {"label", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "The label name for the address to be linked to. If not provided, the default label \"\" is used. It can also be set to the empty string \"\" to represent the default label. The label does not need to exist, it will be created if there is no label by the given name."}, - }} - .ToString() + - "\nResult:\n" + {"label", RPCArg::Type::STR, /* opt */ true, /* default_val */ "null", "The label name for the address to be linked to. If not provided, the default label \"\" is used. It can also be set to the empty string \"\" to represent the default label. The label does not need to exist, it will be created if there is no label by the given name."}, + }, + RPCResult{ "\"address\" (string) The new dash address\n" - "\nExamples:\n" - + HelpExampleCli("getnewaddress", "") + }, + RPCExamples{ + HelpExampleCli("getnewaddress", "") + HelpExampleRpc("getnewaddress", "") - ); + }, + }.ToString()); if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet"); @@ -211,14 +212,15 @@ static UniValue getrawchangeaddress(const JSONRPCRequest& request) RPCHelpMan{"getrawchangeaddress", "\nReturns a new Dash address, for receiving change.\n" "This is for use with raw transactions, NOT normal use.\n", - {}} - .ToString() + - "\nResult:\n" + {}, + RPCResult{ "\"address\" (string) The address\n" - "\nExamples:\n" - + HelpExampleCli("getrawchangeaddress", "") + }, + RPCExamples{ + HelpExampleCli("getrawchangeaddress", "") + HelpExampleRpc("getrawchangeaddress", "") - ); + }, + }.ToString()); if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet"); @@ -259,12 +261,13 @@ static UniValue setlabel(const JSONRPCRequest& request) { {"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The dash address to be associated with a label."}, {"label", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The label to assign to the address."}, - }} - .ToString() + - "\nExamples:\n" - + HelpExampleCli("setlabel", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"tabby\"") + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("setlabel", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"tabby\"") + HelpExampleRpc("setlabel", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", \"tabby\"") - ); + }, + }.ToString()); LOCK(pwallet->cs_wallet); @@ -360,16 +363,17 @@ static UniValue sendtoaddress(const JSONRPCRequest& request) " \"UNSET\"\n" " \"ECONOMICAL\"\n" " \"CONSERVATIVE\""}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "\"txid\" (string) The transaction id.\n" - "\nExamples:\n" - + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1") + }, + RPCExamples{ + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1") + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1 \"donation\" \"seans outpost\"") + HelpExampleCli("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 0.1 \"\" \"\" true") + HelpExampleRpc("sendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", 0.1, \"donation\", \"seans outpost\"") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -447,9 +451,8 @@ static UniValue listaddressgroupings(const JSONRPCRequest& request) "\nLists groups of addresses which have had their common ownership\n" "made public by common use as inputs or as the resulting change\n" "in past transactions\n", - {}} - .ToString() + - "\nResult:\n" + {}, + RPCResult{ "[\n" " [\n" " [\n" @@ -461,10 +464,12 @@ static UniValue listaddressgroupings(const JSONRPCRequest& request) " ]\n" " ,...\n" "]\n" - "\nExamples:\n" - + HelpExampleCli("listaddressgroupings", "") + }, + RPCExamples{ + HelpExampleCli("listaddressgroupings", "") + HelpExampleRpc("listaddressgroupings", "") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -557,11 +562,11 @@ static UniValue signmessage(const JSONRPCRequest& request) { {"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The dash address to use for the private key."}, {"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{ "\nUnlock the wallet for 30 seconds\n" + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + "\nCreate the signature\n" @@ -570,7 +575,8 @@ static UniValue signmessage(const JSONRPCRequest& request) + HelpExampleCli("verifymessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"signature\" \"my message\"") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("signmessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", \"my message\"") - ); + }, + }.ToString()); auto locked_chain = pwallet->chain().lock(); LOCK(pwallet->cs_wallet); @@ -623,11 +629,11 @@ static UniValue getreceivedbyaddress(const JSONRPCRequest& request) {"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The dash address for transactions."}, {"minconf", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "1", "Only include transactions confirmed at least this many times."}, {"addlocked", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Whether to include transactions locked via InstantSend."}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n" - "\nExamples:\n" + }, + RPCExamples{ "\nThe amount from transactions with at least 1 confirmation\n" + HelpExampleCli("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\"") + "\nThe amount including unconfirmed transactions, zero confirmations\n" @@ -636,7 +642,8 @@ static UniValue getreceivedbyaddress(const JSONRPCRequest& request) + HelpExampleCli("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" 6") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("getreceivedbyaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", 6") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -696,11 +703,11 @@ static UniValue getreceivedbylabel(const JSONRPCRequest& request) {"label", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The selected label, may be the default label using \"\"."}, {"minconf", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "1", "Only include transactions confirmed at least this many times."}, {"addlocked", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Whether to include transactions locked via InstantSend."}, - }} - .ToString() + - "\nResult:\n" - "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this label.\n" - "\nExamples:\n" + }, + RPCResult{ + "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this label.\n" + }, + RPCExamples{ "\nAmount received by the default label with at least 1 confirmation\n" + HelpExampleCli("getreceivedbylabel", "\"\"") + "\nAmount received at the tabby label including unconfirmed amounts with zero confirmations\n" @@ -709,7 +716,8 @@ static UniValue getreceivedbylabel(const JSONRPCRequest& request) + HelpExampleCli("getreceivedbylabel", "\"tabby\" 6") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("getreceivedbylabel", "\"tabby\", 6") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -770,18 +778,19 @@ static UniValue getbalance(const JSONRPCRequest& request) {"minconf", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "Only include transactions confirmed at least this many times."}, {"addlocked", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Whether to include transactions locked via InstantSend in the wallet's balance."}, {"include_watchonly", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Also include balance in watch-only addresses (see 'importaddress')"}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this wallet.\n" - "\nExamples:\n" + }, + RPCExamples{ "\nThe total amount in the wallet with 0 or more confirmations\n" + HelpExampleCli("getbalance", "") + "\nThe total amount in the wallet with at least 6 confirmations\n" + HelpExampleCli("getbalance", "\"*\" 6") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("getbalance", "\"*\", 6") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -828,8 +837,11 @@ static UniValue getunconfirmedbalance(const JSONRPCRequest &request) if (request.fHelp || request.params.size() > 0) throw std::runtime_error( RPCHelpMan{"getunconfirmedbalance", - "Returns the server's total unconfirmed balance\n", {}} - .ToString()); + "Returns the server's total unconfirmed balance\n", + {}, + RPCResults{}, + RPCExamples{""}, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -881,19 +893,21 @@ static UniValue sendmany(const JSONRPCRequest& request) " \"UNSET\"\n" " \"ECONOMICAL\"\n" " \"CONSERVATIVE\""}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "\"txid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n" " the number of addresses.\n" - "\nExamples:\n" + }, + RPCExamples{ "\nSend two amounts to two different addresses:\n" + HelpExampleCli("sendmany", "\"\" \"{\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\\\":0.01,\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcG\\\":0.02}\"") + "\nSend two amounts to two different addresses setting the confirmation and comment:\n" + HelpExampleCli("sendmany", "\"\" \"{\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\\\":0.01,\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcG\\\":0.02}\" 6 false \"testing\"") + "\nAs a json rpc call\n" + HelpExampleRpc("sendmany", "\"\", \"{\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\\\":0.01,\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcG\\\":0.02}\", 6, false, \"testing\"") - ); + }, + }.ToString()); + // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now pwallet->BlockUntilSyncedToCurrentChain(); @@ -1027,20 +1041,21 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request) {"key", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "dash address or hex-encoded public key"}, }, }, - {"label", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "A label to assign the addresses to."}, - }} - .ToString() + - "\nResult:\n" + {"label", RPCArg::Type::STR, /* opt */ true, /* default_val */ "null", "A label to assign the addresses to."}, + }, + 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{ "\nAdd a multisig address from 2 addresses\n" + HelpExampleCli("addmultisigaddress", "2 \"[\\\"Xt4qk9uKvQYAonVGSZNXqxeDmtjaEWgfrS\\\",\\\"XoSoWQkpgLpppPoyyzbUFh1fq2RBvW6UK2\\\"]\"") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"Xt4qk9uKvQYAonVGSZNXqxeDmtjaEWgfrS\\\",\\\"XoSoWQkpgLpppPoyyzbUFh1fq2RBvW6UK2\\\"]\"") - ; + }, + }.ToString(); throw std::runtime_error(msg); } @@ -1260,10 +1275,9 @@ static UniValue listreceivedbyaddress(const JSONRPCRequest& request) {"addlocked", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Whether to include transactions locked via InstantSend."}, {"include_empty", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Whether to include addresses that haven't received any payments."}, {"include_watchonly", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Whether to include watch-only addresses (see 'importaddress')."}, - {"address_filter", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "If present, only return information on this address."}, - }} - .ToString() + - "\nResult:\n" + {"address_filter", RPCArg::Type::STR, /* opt */ true, /* default_val */ "null", "If present, only return information on this address."}, + }, + RPCResult{ "[\n" " {\n" " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n" @@ -1280,13 +1294,14 @@ static UniValue listreceivedbyaddress(const JSONRPCRequest& request) " }\n" " ,...\n" "]\n" - - "\nExamples:\n" - + HelpExampleCli("listreceivedbyaddress", "") + }, + RPCExamples{ + HelpExampleCli("listreceivedbyaddress", "") + HelpExampleCli("listreceivedbyaddress", "6 false true") + HelpExampleRpc("listreceivedbyaddress", "6, false, true, true") + HelpExampleRpc("listreceivedbyaddress", "6, false, true, true, \"XbtdLrTsrPDhGy1wXtwKYoBpuKovE3JeBK\"") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -1316,9 +1331,8 @@ static UniValue listreceivedbylabel(const JSONRPCRequest& request) {"addlocked", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Whether to include transactions locked via InstantSend."}, {"include_empty", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Whether to include labels that haven't received any payments."}, {"include_watchonly", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Whether to include watch-only addresses (see 'importaddress')."}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "[\n" " {\n" " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n" @@ -1328,12 +1342,13 @@ static UniValue listreceivedbylabel(const JSONRPCRequest& request) " }\n" " ,...\n" "]\n" - - "\nExamples:\n" - + HelpExampleCli("listreceivedbylabel", "") - + HelpExampleCli("listreceivedbylabel", "6 false true") - + HelpExampleRpc("listreceivedbylabel", "6, false, true, true") - ); + }, + RPCExamples{ + HelpExampleCli("listreceivedbylabel", "") + + HelpExampleCli("listreceivedbylabel", "6 true") + + HelpExampleRpc("listreceivedbylabel", "6, true, true") + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -1460,9 +1475,8 @@ static UniValue listtransactions(const JSONRPCRequest& request) {"count", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "10", "The number of transactions to return"}, {"skip", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "The number of transactions to skip"}, {"include_watchonly", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Include transactions to watch-only addresses (see 'importaddress')"}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "[\n" " {\n" " \"address\":\"address\", (string) The dash address of the transaction. Not present for \n" @@ -1499,15 +1513,16 @@ static UniValue listtransactions(const JSONRPCRequest& request) " 'send' category of transactions.\n" " }\n" "]\n" - - "\nExamples:\n" + }, + RPCExamples{ "\nList the most recent 10 transactions in the systems\n" + HelpExampleCli("listtransactions", "") + "\nList transactions 100 to 120\n" + HelpExampleCli("listtransactions", "\"\" 20 100") + "\nAs a json rpc call\n" + HelpExampleRpc("listtransactions", "\"\", 20, 100") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -1587,9 +1602,8 @@ static UniValue listsinceblock(const JSONRPCRequest& request) {"include_watchonly", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Include transactions to watch-only addresses (see 'importaddress')"}, {"include_removed", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "true", "Show transactions that were removed due to a reorg in the \"removed\" array\n" " (not guaranteed to work on pruned nodes)"}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "{\n" " \"transactions\": [\n" " \"address\":\"address\", (string) The dash address of the transaction. Not present for move transactions (category = move).\n" @@ -1620,11 +1634,13 @@ static UniValue listsinceblock(const JSONRPCRequest& request) " ],\n" " \"lastblock\": \"lastblockhash\" (string) The hash of the block (target_confirmations-1) from the best block on the main chain. This is typically used to feed back into listsinceblock the next time you call it. So you would generally use a target_confirmations of say 6, so you will be continually re-notified of transactions until they've reached 6 confirmations plus any new ones\n" "}\n" - "\nExamples:\n" - + HelpExampleCli("listsinceblock", "") + }, + RPCExamples{ + HelpExampleCli("listsinceblock", "") + HelpExampleCli("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\" 6") + HelpExampleRpc("listsinceblock", "\"000000000000000bacf66f7497b7dc45ef753ee9a7d38571037cdb1a57f663ad\", 6") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -1728,9 +1744,8 @@ static UniValue gettransaction(const JSONRPCRequest& request) { {"txid", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The transaction id"}, {"include_watchonly", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Whether to include watch-only addresses in balance calculation and details[]"}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "{\n" " \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + "\n" " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n" @@ -1761,12 +1776,13 @@ static UniValue gettransaction(const JSONRPCRequest& request) " ],\n" " \"hex\" : \"data\" (string) Raw data for transaction\n" "}\n" - - "\nExamples:\n" - + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"") + }, + RPCExamples{ + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"") + HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true") + HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -1830,13 +1846,13 @@ static UniValue abandontransaction(const JSONRPCRequest& request) "It has no effect on transactions which are already abandoned.\n", { {"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id"}, - }} - .ToString() + - "\nResult:\n" - "\nExamples:\n" - + HelpExampleCli("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"") + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"") + HelpExampleRpc("abandontransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"") - ); + }, + }.ToString()); } // Make sure the results are valid at least up to the most recent block @@ -1875,12 +1891,13 @@ static UniValue backupwallet(const JSONRPCRequest& request) "\nSafely copies current wallet file to destination, which can be a directory or a path with filename.\n", { {"destination", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The destination directory or file"}, - }} - .ToString() + - "\nExamples:\n" - + HelpExampleCli("backupwallet", "\"backup.dat\"") + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("backupwallet", "\"backup.dat\"") + HelpExampleRpc("backupwallet", "\"backup.dat\"") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -1914,12 +1931,13 @@ static UniValue keypoolrefill(const JSONRPCRequest& request) HelpRequiringPassphrase(pwallet) + "\n", { {"newsize", RPCArg::Type::NUM, /* opt */ true, /* default_val */ itostr(DEFAULT_KEYPOOL_SIZE), "The new keypool size"}, - }} - .ToString() + - "\nExamples:\n" - + HelpExampleCli("keypoolrefill", "") + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("keypoolrefill", "") + HelpExampleRpc("keypoolrefill", "") - ); + }, + }.ToString()); if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet"); @@ -1960,17 +1978,17 @@ static UniValue walletpassphrase(const JSONRPCRequest& request) throw std::runtime_error( RPCHelpMan{"walletpassphrase", "\nStores the wallet decryption key in memory for 'timeout' seconds.\n" - "This is needed prior to performing transactions related to private keys such as sending dashs\n", + "This is needed prior to performing transactions related to private keys such as sending dashs\n" + "\nNote:\n" + "Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n" + "time that overrides the old one.\n", { {"passphrase", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The wallet passphrase"}, {"timeout", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The time to keep the decryption key in seconds; capped at 100000000 (~3 years)."}, {"mixingonly", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "If is true sending functions are disabled."}, - }} - .ToString() + - "\nNote:\n" - "Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n" - "time that overrides the old one.\n" - "\nExamples:\n" + }, + RPCResults{}, + RPCExamples{ "\nUnlock the wallet for 60 seconds\n" + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") + "\nUnlock the wallet for 60 seconds but allow CoinJoin only\n" @@ -1979,7 +1997,8 @@ static UniValue walletpassphrase(const JSONRPCRequest& request) + HelpExampleCli("walletlock", "") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60") - ); + }, + }.ToString()); } auto locked_chain = pwallet->chain().lock(); @@ -2063,12 +2082,13 @@ static UniValue walletpassphrasechange(const JSONRPCRequest& request) { {"oldpassphrase", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The current passphrase"}, {"newpassphrase", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The new passphrase"}, - }} - .ToString() + - "\nExamples:\n" - + HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"") + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"") + HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"") - ); + }, + }.ToString()); } auto locked_chain = pwallet->chain().lock(); @@ -2115,9 +2135,9 @@ static UniValue walletlock(const JSONRPCRequest& request) "\nRemoves the wallet encryption key from memory, locking the wallet.\n" "After calling this method, you will need to call walletpassphrase again\n" "before being able to call any methods which require the wallet to be unlocked.\n", - {}} - .ToString() + - "\nExamples:\n" + {}, + RPCResults{}, + RPCExamples{ "\nSet the passphrase for 2 minutes to perform a transaction\n" + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") + "\nPerform a send (requires passphrase set)\n" @@ -2126,7 +2146,8 @@ static UniValue walletlock(const JSONRPCRequest& request) + HelpExampleCli("walletlock", "") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("walletlock", "") - ); + }, + }.ToString()); } auto locked_chain = pwallet->chain().lock(); @@ -2162,9 +2183,9 @@ static UniValue encryptwallet(const JSONRPCRequest& request) "If the wallet is already encrypted, use the walletpassphrasechange call.\n", { {"passphrase", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long."}, - }} - .ToString() + - "\nExamples:\n" + }, + RPCResults{}, + RPCExamples{ "\nEncrypt your wallet\n" + HelpExampleCli("encryptwallet", "\"my pass phrase\"") + "\nNow set the passphrase to use the wallet, such as for signing or sending dash\n" @@ -2175,7 +2196,8 @@ static UniValue encryptwallet(const JSONRPCRequest& request) + HelpExampleCli("walletlock", "") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("encryptwallet", "\"my pass phrase\"") - ); + }, + }.ToString()); } auto locked_chain = pwallet->chain().lock(); @@ -2233,12 +2255,11 @@ static UniValue lockunspent(const JSONRPCRequest& request) }, }, }, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "true|false (boolean) Whether the command was successful or not\n" - - "\nExamples:\n" + }, + RPCExamples{ "\nList the unspent transactions\n" + HelpExampleCli("listunspent", "") + "\nLock an unspent transaction\n" @@ -2249,7 +2270,8 @@ static UniValue lockunspent(const JSONRPCRequest& request) + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("lockunspent", "false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -2349,9 +2371,8 @@ static UniValue listlockunspent(const JSONRPCRequest& request) RPCHelpMan{"listlockunspent", "\nReturns list of temporarily unspendable outputs.\n" "See the lockunspent call to lock and unlock transactions for spending.\n", - {}} - .ToString() + - "\nResult:\n" + {}, + RPCResult{ "[\n" " {\n" " \"txid\" : \"transactionid\", (string) The transaction id locked\n" @@ -2359,7 +2380,8 @@ static UniValue listlockunspent(const JSONRPCRequest& request) " }\n" " ,...\n" "]\n" - "\nExamples:\n" + }, + RPCExamples{ "\nList the unspent transactions\n" + HelpExampleCli("listunspent", "") + "\nLock an unspent transaction\n" @@ -2370,7 +2392,8 @@ static UniValue listlockunspent(const JSONRPCRequest& request) + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("listlockunspent", "") - ); + }, + }.ToString()); auto locked_chain = pwallet->chain().lock(); LOCK(pwallet->cs_wallet); @@ -2406,14 +2429,15 @@ static UniValue settxfee(const JSONRPCRequest& request) "\nSet the transaction fee per kB for this wallet. Overrides the global -paytxfee command line parameter.\n", { {"amount", RPCArg::Type::AMOUNT, /* opt */ false, /* default_val */ "", "The transaction fee in " + CURRENCY_UNIT + "/kB"}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "true|false (boolean) Returns true if successful\n" - "\nExamples:\n" - + HelpExampleCli("settxfee", "0.00001") + }, + RPCExamples{ + HelpExampleCli("settxfee", "0.00001") + HelpExampleRpc("settxfee", "0.00001") - ); + }, + }.ToString()); } auto locked_chain = pwallet->chain().lock(); @@ -2508,9 +2532,9 @@ static UniValue getwalletinfo(const JSONRPCRequest& request) if (request.fHelp || request.params.size() != 0) throw std::runtime_error( RPCHelpMan{"getwalletinfo", - "Returns an object containing various wallet state info.\n", {}} - .ToString() + - "\nResult:\n" + "Returns an object containing various wallet state info.\n", + {}, + RPCResult{ "{\n" " \"walletname\": xxxxx, (string) the wallet name\n" " \"walletversion\": xxxxx, (numeric) the wallet version\n" @@ -2543,10 +2567,12 @@ static UniValue getwalletinfo(const JSONRPCRequest& request) " }\n" " \"private_keys_enabled\": true|false (boolean) false if privatekeys are disabled for this wallet (enforced watch-only wallet)\n" "}\n" - "\nExamples:\n" - + HelpExampleCli("getwalletinfo", "") + }, + RPCExamples{ + HelpExampleCli("getwalletinfo", "") + HelpExampleRpc("getwalletinfo", "") - ); + }, + }.ToString()); // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -2613,8 +2639,9 @@ static UniValue listwalletdir(const JSONRPCRequest& request) if (request.fHelp || request.params.size() != 0) { throw std::runtime_error( RPCHelpMan{"listwalletdir", - "Returns a list of wallets in the wallet directory.\n", {}} - .ToString() + + "Returns a list of wallets in the wallet directory.\n", + {}, + RPCResult{ "{\n" " \"wallets\" : [ (json array of objects)\n" " {\n" @@ -2623,10 +2650,12 @@ static UniValue listwalletdir(const JSONRPCRequest& request) " ,...\n" " ]\n" "}\n" - "\nExamples:\n" - + HelpExampleCli("listwalletdir", "") + }, + RPCExamples{ + HelpExampleCli("listwalletdir", "") + HelpExampleRpc("listwalletdir", "") - ); + }, + }.ToString()); } UniValue wallets(UniValue::VARR); @@ -2648,17 +2677,18 @@ static UniValue listwallets(const JSONRPCRequest& request) RPCHelpMan{"listwallets", "Returns a list of currently loaded wallets.\n" "For full information on the wallet, use \"getwalletinfo\"\n", - {}} - .ToString() + - "\nResult:\n" + {}, + RPCResult{ "[ (json array of strings)\n" " \"walletname\" (string) the wallet name\n" " ...\n" "]\n" - "\nExamples:\n" - + HelpExampleCli("listwallets", "") + }, + RPCExamples{ + HelpExampleCli("listwallets", "") + HelpExampleRpc("listwallets", "") - ); + }, + }.ToString()); UniValue obj(UniValue::VARR); @@ -2844,17 +2874,18 @@ static UniValue loadwallet(const JSONRPCRequest& request) "\napplied to the new wallet (eg -zapwallettxes, upgradewallet, rescan, etc).\n", { {"filename", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The wallet directory or .dat file."}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "{\n" " \"name\" : , (string) The wallet name if loaded successfully.\n" " \"warning\" : , (string) Warning message if wallet was not loaded cleanly.\n" "}\n" - "\nExamples:\n" - + HelpExampleCli("loadwallet", "\"test.dat\"") + }, + RPCExamples{ + HelpExampleCli("loadwallet", "\"test.dat\"") + HelpExampleRpc("loadwallet", "\"test.dat\"") - ); + }, + }.ToString()); WalletLocation location(request.params[0].get_str()); @@ -2888,17 +2919,18 @@ static UniValue createwallet(const JSONRPCRequest& request) { {"wallet_name", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The name for the new wallet. If this is a path, the wallet will be created at the path location."}, {"disable_private_keys", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Disable the possibility of private keys (only watchonlys are possible in this mode)."}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "{\n" " \"name\" : , (string) The wallet name if created successfully. If the wallet was created using a full path, the wallet_name will be the full path.\n" " \"warning\" : , (string) Warning message if wallet was not loaded cleanly.\n" "}\n" - "\nExamples:\n" - + HelpExampleCli("createwallet", "\"testwallet\"") + }, + RPCExamples{ + HelpExampleCli("createwallet", "\"testwallet\"") + HelpExampleRpc("createwallet", "\"testwallet\"") - ); + }, + }.ToString()); } std::string error; std::string warning; @@ -2942,12 +2974,13 @@ static UniValue unloadwallet(const JSONRPCRequest& request) "Specifying the wallet name on a wallet endpoint is invalid.", { {"wallet_name", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "The name of the wallet to unload."}, - }} - .ToString() + - "\nExamples:\n" - + HelpExampleCli("unloadwallet", "wallet_name") + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("unloadwallet", "wallet_name") + HelpExampleRpc("unloadwallet", "wallet_name") - ); + }, + }.ToString()); } std::string wallet_name; @@ -2989,12 +3022,15 @@ static UniValue resendwallettransactions(const JSONRPCRequest& request) throw std::runtime_error( RPCHelpMan{"resendwallettransactions", "Immediately re-broadcast unconfirmed wallet transactions to all peers.\n" - "Intended only for testing; the wallet code periodically re-broadcasts\n", - {}} - .ToString() + - "automatically.\n" + "Intended only for testing; the wallet code periodically re-broadcasts\n" + "automatically.\n", + {}, + RPCResult{ "Returns an RPC error if -walletbroadcast is set to false.\n" "Returns array of transaction ids that were re-broadcast.\n" + }, + RPCExamples{""}, + }.ToString() ); if (!g_connman) @@ -3052,9 +3088,8 @@ static UniValue listunspent(const JSONRPCRequest& request) " 4=ONLY_MASTERNODE_COLLATERAL, 5=ONLY_COINJOIN_COLLATERAL" }, }, "query_options"}, - }} - .ToString() + - "\nResult\n" + }, + RPCResult{ "[ (array of json object)\n" " {\n" " \"txid\" : \"txid\", (string) the transaction id \n" @@ -3075,14 +3110,15 @@ static UniValue listunspent(const JSONRPCRequest& request) " }\n" " ,...\n" "]\n" - - "\nExamples:\n" - + HelpExampleCli("listunspent", "") + }, + RPCExamples{ + HelpExampleCli("listunspent", "") + HelpExampleCli("listunspent", "6 9999999 \"[\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\\\",\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcg\\\"]\"") + HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\\\",\\\"XuQQkwA4FYkq2XERzMY2CiAZhJTEDAbtcg\\\"]\"") + HelpExampleCli("listunspent", "6 9999999 '[]' true '{ \"minimumAmount\": 0.005 }'") + HelpExampleRpc("listunspent", "6, 9999999, [] , true, { \"minimumAmount\": 0.005 } ") - ); + }, + }.ToString()); int nMinDepth = 1; if (!request.params[0].isNull()) { @@ -3374,15 +3410,15 @@ static UniValue fundrawtransaction(const JSONRPCRequest& request) " \"CONSERVATIVE\""}, }, "options"}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "{\n" " \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n" " \"fee\": n, (numeric) Fee in " + CURRENCY_UNIT + " the resulting transaction pays\n" " \"changepos\": n (numeric) The position of the added change output, or -1\n" "}\n" - "\nExamples:\n" + }, + RPCExamples{ "\nCreate a transaction with no inputs\n" + HelpExampleCli("createrawtransaction", "\"[]\" \"{\\\"myaddress\\\":0.01}\"") + "\nAdd sufficient unsigned inputs to meet the output value\n" @@ -3391,7 +3427,8 @@ static UniValue fundrawtransaction(const JSONRPCRequest& request) + HelpExampleCli("signrawtransaction", "\"fundedtransactionhex\"") + "\nSend the transaction\n" + HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"") - ); + }, + }.ToString()); RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType(), UniValue::VBOOL}); @@ -3451,9 +3488,8 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request) " \"ALL|ANYONECANPAY\"\n" " \"NONE|ANYONECANPAY\"\n" " \"SINGLE|ANYONECANPAY\""}, - }} - .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" @@ -3468,11 +3504,12 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request) " ,...\n" " ]\n" "}\n" - - "\nExamples:\n" - + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") + }, + RPCExamples{ + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") + HelpExampleRpc("signrawtransactionwithwallet", "\"myhex\"") - ); + }, + }.ToString()); RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VSTR}, true); @@ -3506,15 +3543,16 @@ UniValue generate(const JSONRPCRequest& request) "\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n", { {"nblocks", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "How many blocks are generated immediately."}, - {"maxtries", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "How many iterations to try (default = 1000000)."}, - }} - .ToString() + - "\nResult:\n" + {"maxtries", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "1000000", "How many iterations to try."}, + }, + RPCResult{ "[ blockhashes ] (array) hashes of blocks generated\n" - "\nExamples:\n" + }, + RPCExamples{ "\nGenerate 11 blocks\n" + HelpExampleCli("generate", "11") - ); + }, + }.ToString()); } int num_generate = request.params[0].get_int(); @@ -3559,19 +3597,20 @@ static UniValue rescanblockchain(const JSONRPCRequest& request) RPCHelpMan{"rescanblockchain", "\nRescan the local blockchain for wallet related transactions.\n", { - {"start_height", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "block height where the rescan should start"}, + {"start_height", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "block height where the rescan should start"}, {"stop_height", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "the last block height that should be scanned. If none is provided it will rescan up to the tip at return time of this call."}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "{\n" " \"start_height\" (numeric) The block height where the rescan has started.\n" " \"stop_height\" (numeric) The height of the last rescanned block.\n" "}\n" - "\nExamples:\n" - + HelpExampleCli("rescanblockchain", "100000 120000") + }, + RPCExamples{ + HelpExampleCli("rescanblockchain", "100000 120000") + HelpExampleRpc("rescanblockchain", "100000, 120000") - ); + }, + }.ToString()); } WalletRescanReserver reserver(pwallet); @@ -3712,9 +3751,8 @@ UniValue getaddressinfo(const JSONRPCRequest& request) "to be in the wallet.\n", { {"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The dash address to get the information of."}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "{\n" " \"address\" : \"address\", (string) The dash address validated\n" " \"scriptPubKey\" : \"hex\", (string) The hex-encoded scriptPubKey generated by the address\n" @@ -3748,10 +3786,12 @@ UniValue getaddressinfo(const JSONRPCRequest& request) " },...\n" " ]\n" "}\n" - "\nExamples:\n" - + HelpExampleCli("getaddressinfo", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"") + }, + RPCExamples{ + HelpExampleCli("getaddressinfo", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"") + HelpExampleRpc("getaddressinfo", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"") - ); + }, + }.ToString()); } LOCK(pwallet->cs_wallet); @@ -3836,18 +3876,19 @@ static UniValue getaddressesbylabel(const JSONRPCRequest& request) "\nReturns the list of addresses assigned the specified label.\n", { {"label", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The label."}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "{ (json object with addresses as keys)\n" " \"address\": { (json object with information about address)\n" " \"purpose\": \"string\" (string) Purpose of address (\"send\" for sending address, \"receive\" for receiving address)\n" " },...\n" "}\n" - "\nExamples:\n" - + HelpExampleCli("getaddressesbylabel", "\"tabby\"") + }, + RPCExamples{ + HelpExampleCli("getaddressesbylabel", "\"tabby\"") + HelpExampleRpc("getaddressesbylabel", "\"tabby\"") - ); + }, + }.ToString()); LOCK(pwallet->cs_wallet); @@ -3893,15 +3934,15 @@ static UniValue listlabels(const JSONRPCRequest& request) RPCHelpMan{"listlabels", "\nReturns the list of all labels, or labels that are assigned to addresses with a specific purpose.\n", { - {"purpose", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "Address purpose to list labels for ('send','receive'). An empty string is the same as not providing this argument."}, - }} - .ToString() + - "\nResult:\n" + {"purpose", RPCArg::Type::STR, /* opt */ true, /* default_val */ "null", "Address purpose to list labels for ('send','receive'). An empty string is the same as not providing this argument."}, + }, + RPCResult{ "[ (json array of string)\n" " \"label\", (string) Label name\n" " ...\n" "]\n" - "\nExamples:\n" + }, + RPCExamples{ "\nList all labels\n" + HelpExampleCli("listlabels", "") + "\nList labels that have receiving addresses\n" @@ -3910,7 +3951,8 @@ static UniValue listlabels(const JSONRPCRequest& request) + HelpExampleCli("listlabels", "send") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("listlabels", "receive") - ); + }, + }.ToString()); LOCK(pwallet->cs_wallet); @@ -3974,18 +4016,18 @@ UniValue walletprocesspsbt(const JSONRPCRequest& request) " \"NONE|ANYONECANPAY\"\n" " \"SINGLE|ANYONECANPAY\""}, {"bip32derivs", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "If true, includes the BIP 32 derivation paths for public keys if we know them"}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "{\n" " \"psbt\" : \"value\", (string) The base64-encoded partially signed transaction\n" " \"complete\" : true|false, (boolean) If the transaction has a complete set of signatures\n" " ]\n" "}\n" - - "\nExamples:\n" - + HelpExampleCli("walletprocesspsbt", "\"psbt\"") - ); + }, + RPCExamples{ + HelpExampleCli("walletprocesspsbt", "\"psbt\"") + }, + }.ToString()); RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VSTR}); @@ -4088,18 +4130,19 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request) }, "options"}, {"bip32derivs", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "If true, includes the BIP 32 derivation paths for public keys if we know them"}, - }} - .ToString() + - "\nResult:\n" + }, + RPCResult{ "{\n" " \"psbt\": \"value\", (string) The resulting raw transaction (base64-encoded string)\n" " \"fee\": n, (numeric) Fee in " + CURRENCY_UNIT + " the resulting transaction pays\n" " \"changepos\": n (numeric) The position of the added change output, or -1\n" "}\n" - "\nExamples:\n" + }, + RPCExamples{ "\nCreate a transaction with no inputs\n" + HelpExampleCli("walletcreatefundedpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") - ); + }, + }.ToString()); RPCTypeCheck(request.params, { UniValue::VARR, diff --git a/src/zmq/zmqrpc.cpp b/src/zmq/zmqrpc.cpp index d3eab46e5f..a34968ef7d 100644 --- a/src/zmq/zmqrpc.cpp +++ b/src/zmq/zmqrpc.cpp @@ -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); From 2ff928c8504e8e6407401cec18cc7e57bd10a76a Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 12 Feb 2019 18:42:50 -0500 Subject: [PATCH 2/4] Merge #14918: RPCHelpMan: Check default values are given at compile-time fa0ad4e7ce RPCHelpMan: Check default values are given at compile-time (MarcoFalke) Pull request description: Remove the run time assertions on the default values and ensure that the correct default type and value is provided at compile time. Tree-SHA512: 80df2f3fab4379b500c773c27da63f22786c58be5963fe99744746320e43627a5d433eedf8b32209158df7805ebdce65ed4d242c829c4fe6e5d13deb4799ed42 --- src/rpc/blockchain.cpp | 74 +++++----- src/rpc/mining.cpp | 40 +++--- src/rpc/misc.cpp | 30 ++-- src/rpc/net.cpp | 22 +-- src/rpc/rawtransaction.cpp | 117 +++++++-------- src/rpc/server.cpp | 4 +- src/rpc/util.cpp | 47 +++--- src/rpc/util.h | 38 +++-- src/wallet/rpcdump.cpp | 68 ++++----- src/wallet/rpcwallet.cpp | 284 ++++++++++++++++++------------------- 10 files changed, 375 insertions(+), 349 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index f29892f3b9..3c22716070 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -277,7 +277,7 @@ 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 */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."}, + {"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."}, }, RPCResult{ "{ (json object)\n" @@ -318,8 +318,8 @@ static UniValue waitforblock(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", { - {"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."}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "Block hash to wait for."}, + {"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."}, }, RPCResult{ "{ (json object)\n" @@ -364,8 +364,8 @@ static UniValue waitforblockheight(const JSONRPCRequest& request) "of the current tip.\n" "\nReturns the current block on timeout or exit.\n", { - {"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."}, + {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "Block height to wait for."}, + {"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."}, }, RPCResult{ "{ (json object)\n" @@ -551,7 +551,7 @@ static UniValue getrawmempool(const JSONRPCRequest& request) "\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n" "\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"}, + {"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"}, }, RPCResult{"for verbose = false", "[ (json array of string)\n" @@ -585,8 +585,8 @@ static UniValue getmempoolancestors(const JSONRPCRequest& request) RPCHelpMan{"getmempoolancestors", "\nIf txid is in the mempool, returns all in-mempool ancestors.\n", { - {"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"}, + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"}, + {"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"}, }, { RPCResult{"for verbose = false", @@ -655,8 +655,8 @@ static UniValue getmempooldescendants(const JSONRPCRequest& request) RPCHelpMan{"getmempooldescendants", "\nIf txid is in the mempool, returns all in-mempool descendants.\n", { - {"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"}, + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"}, + {"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"}, }, { RPCResult{"for verbose = false", @@ -725,7 +725,7 @@ static UniValue getmempoolentry(const JSONRPCRequest& request) RPCHelpMan{"getmempoolentry", "\nReturns mempool data for given transaction\n", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id (must be in mempool)"}, + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"}, }, RPCResult{ "{ (json object)\n" @@ -797,7 +797,7 @@ static UniValue getblockhash(const JSONRPCRequest& request) RPCHelpMan{"getblockhash", "\nReturns hash of block in best-block-chain at height provided.\n", { - {"height", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The height index"}, + {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "The height index"}, }, RPCResult{ "\"hash\" (string) The block hash\n" @@ -826,8 +826,8 @@ static UniValue getblockheader(const JSONRPCRequest& request) "\nIf verbose is false, returns a string that is serialized, hex-encoded data for blockheader 'hash'.\n" "If verbose is true, returns an Object with information about blockheader .\n", { - {"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"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, + {"verbose", RPCArg::Type::BOOL, /* default */ "true", "true for a json object, false for the hex-encoded data"}, }, { RPCResult{"for verbose = true", @@ -1087,8 +1087,8 @@ static UniValue getblock(const JSONRPCRequest& request) "If verbosity is 1, returns an Object with information about block .\n" "If verbosity is 2, returns an Object with information about block and information about each transaction. \n", { - {"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"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, + {"verbosity", RPCArg::Type::NUM, /* default */ "1", "0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data"}, }, { RPCResult{"for verbosity = 0", @@ -1177,7 +1177,7 @@ static UniValue pruneblockchain(const JSONRPCRequest& request) throw std::runtime_error( RPCHelpMan{"pruneblockchain", "", { - {"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" + {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "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."}, }, RPCResult{ @@ -1278,9 +1278,9 @@ static UniValue gettxout(const JSONRPCRequest& request) RPCHelpMan{"gettxout", "\nReturns details about an unspent transaction output.\n", { - {"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."}, + {"txid", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction id"}, + {"n", RPCArg::Type::NUM, RPCArg::Optional::NO, "vout number"}, + {"include_mempool", RPCArg::Type::BOOL, /* default */ "true", "Whether to include the mempool. Note that an unspent output that is spent in the mempool won't appear."}, }, RPCResult{ "{\n" @@ -1362,8 +1362,8 @@ static UniValue verifychain(const JSONRPCRequest& request) RPCHelpMan{"verifychain", "\nVerifies blockchain database.\n", { - {"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."}, + {"checklevel", RPCArg::Type::NUM, /* default */ strprintf("%d, range=0-4", nCheckLevel), "How thorough the block verification is."}, + {"nblocks", RPCArg::Type::NUM, /* default */ strprintf("%d, 0=all", nCheckDepth), "The number of blocks to check."}, }, RPCResult{ "true|false (boolean) Verified or not\n" @@ -1765,7 +1765,7 @@ static UniValue preciousblock(const JSONRPCRequest& request) "\nA later preciousblock call can override the effect of an earlier one.\n" "\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"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as precious"}, }, RPCResults{}, RPCExamples{ @@ -1803,7 +1803,7 @@ static UniValue invalidateblock(const JSONRPCRequest& request) RPCHelpMan{"invalidateblock", "\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"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as invalid"}, }, RPCResults{}, RPCExamples{ @@ -1845,7 +1845,7 @@ static UniValue reconsiderblock(const JSONRPCRequest& request) "\nRemoves invalidity status of a block and its descendants, reconsider them for activation.\n" "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"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to reconsider"}, }, RPCResults{}, RPCExamples{ @@ -1884,8 +1884,8 @@ static UniValue getchaintxstats(const JSONRPCRequest& request) RPCHelpMan{"getchaintxstats", "\nCompute statistics about the total number and rate of transactions in the chain.\n", { - {"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."}, + {"nblocks", RPCArg::Type::NUM, /* default */ "one month", "Size of the window in number of blocks"}, + {"blockhash", RPCArg::Type::STR_HEX, /* default */ "chain tip", "The hash of the block that ends the window."}, }, RPCResult{ "{\n" @@ -2021,11 +2021,11 @@ static UniValue getblockstats(const JSONRPCRequest& request) "It won't work for some heights with pruning.\n" "It won't work without -txindex for utxo_size_inc, *fee or *feerate stats.\n", { - {"hash_or_height", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The block hash or height of the target block", "", {"", "string or numeric"}}, - {"stats", RPCArg::Type::ARR, /* opt */ true, /* default_val */ "", "Values to plot, by default all values (see result below)", + {"hash_or_height", RPCArg::Type::NUM, RPCArg::Optional::NO, "The block hash or height of the target block", "", {"", "string or numeric"}}, + {"stats", RPCArg::Type::ARR, /* default */ "all values", "Values to plot (see result below)", { - {"height", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "Selected statistic"}, - {"time", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "Selected statistic"}, + {"height", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Selected statistic"}, + {"time", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Selected statistic"}, }, "stats"}, }, @@ -2467,18 +2467,18 @@ UniValue scantxoutset(const JSONRPCRequest& request) "In the latter case, a range needs to be specified by below if different from 1000.\n" "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n", { - {"action", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The action to execute\n" + {"action", RPCArg::Type::STR, RPCArg::Optional::NO, "The action to execute\n" " \"start\" for starting a scan\n" " \"abort\" for aborting the current scan (returns true when abort was successful)\n" " \"status\" for progress report (in %) of the current scan"}, - {"scanobjects", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "Array of scan objects\n" + {"scanobjects", RPCArg::Type::ARR, RPCArg::Optional::NO, "Array of scan objects\n" " Every scan object is either a string descriptor or an object:", { - {"descriptor", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "An output descriptor"}, - {"", RPCArg::Type::OBJ, /* opt */ true, /* default_val */ "", "An object with output descriptor and metadata", + {"descriptor", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "An output descriptor"}, + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "An object with output descriptor and metadata", { - {"desc", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "An output descriptor"}, - {"range", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "1000", "Up to what child index HD chains should be explored"}, + {"desc", RPCArg::Type::STR, RPCArg::Optional::NO, "An output descriptor"}, + {"range", RPCArg::Type::NUM, /* default */ "1000", "Up to what child index HD chains should be explored"}, }, }, }, diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index b68e5cf697..6a16749e5d 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -91,8 +91,8 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request) "Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n" "Pass in [height] to estimate the network speed at the time when a certain block was found.\n", { - {"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."}, + {"nblocks", RPCArg::Type::NUM, /* default */ "120", "The number of blocks, or -1 for blocks since last difficulty change."}, + {"height", RPCArg::Type::NUM, /* default */ "-1", "To estimate at the time of the given height."}, }, RPCResult{ "x (numeric) Hashes per second estimated\n" @@ -163,9 +163,9 @@ static UniValue generatetoaddress(const JSONRPCRequest& request) RPCHelpMan{"generatetoaddress", "\nMine blocks immediately to a specified address (before the RPC call returns)\n", { - {"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."}, + {"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."}, + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address to send the newly generated Dash to."}, + {"maxtries", RPCArg::Type::NUM, /* default */ "1000000", "How many iterations to try."}, }, RPCResult{ "[ blockhashes ] (array) hashes of blocks generated\n" @@ -248,8 +248,8 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request) RPCHelpMan{"prioritisetransaction", "Accepts the transaction into mined blocks at a higher (or lower) priority\n", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id."}, - {"fee_delta", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The fee value (in duffs) to add (or subtract, if negative).\n" + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id."}, + {"fee_delta", RPCArg::Type::NUM, RPCArg::Optional::NO, "The fee value (in duffs) to add (or subtract, if negative).\n" " 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."}, @@ -313,17 +313,17 @@ static UniValue getblocktemplate(const JSONRPCRequest& request) " https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki\n" " https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n", { - {"template_request", RPCArg::Type::OBJ, /* opt */ true, /* default_val */ "", "A json object in the following spec", + {"template_request", RPCArg::Type::OBJ, /* default_val */ "", "A json object in the following spec", { - {"mode", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "This must be set to \"template\", \"proposal\" (see BIP 23), or omitted"}, - {"capabilities", RPCArg::Type::ARR, /* opt */ true, /* default_val */ "", "A list of strings", + {"mode", RPCArg::Type::STR, /* treat as named arg */ RPCArg::Optional::OMITTED_NAMED_ARG, "This must be set to \"template\", \"proposal\" (see BIP 23), or omitted"}, + {"capabilities", RPCArg::Type::ARR, /* treat as named arg */ RPCArg::Optional::OMITTED_NAMED_ARG, "A list of strings", { - {"support", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'"}, + {"support", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'"}, }, }, - {"rules", RPCArg::Type::ARR, /* opt */ true, /* default_val */ "", "A list of strings", + {"rules", RPCArg::Type::ARR, /* default_val */ "", "A list of strings", { - {"support", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "client side supported softfork deployment"}, + {"support", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported softfork deployment"}, }, }, }, @@ -740,8 +740,8 @@ static UniValue submitblock(const JSONRPCRequest& request) "\nAttempts to submit new block to network.\n" "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n", { - {"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."}, + {"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded block data to submit"}, + {"dummy", RPCArg::Type::STR, /* default */ "ignored", "dummy value, for compatibility with BIP22. This value is ignored."}, }, RPCResults{}, RPCExamples{ @@ -797,7 +797,7 @@ static UniValue submitheader(const JSONRPCRequest& request) "\nDecode the given hexdata as a header and submit it as a candidate chain tip if valid." "\nThrows when the header is invalid.\n", { - {"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded block header data"}, + {"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded block header data"}, }, RPCResult{ "None" @@ -838,8 +838,8 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request) "confirmation within conf_target blocks if possible and return the number of blocks\n" "for which the estimate is valid.\n", { - {"conf_target", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "Confirmation target in blocks (1 - 1008)"}, - {"estimate_mode", RPCArg::Type::STR, /* opt */ true, /* default_val */ "CONSERVATIVE", "The fee estimate mode.\n" + {"conf_target", RPCArg::Type::NUM, RPCArg::Optional::NO, "Confirmation target in blocks (1 - 1008)"}, + {"estimate_mode", RPCArg::Type::STR, /* default */ "CONSERVATIVE", "The fee estimate mode.\n" " Whether to return a more conservative estimate which also satisfies\n" " a longer history. A conservative estimate potentially returns a\n" " higher feerate and is more likely to be sufficient for the desired\n" @@ -904,8 +904,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request) "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n" "confirmation within conf_target blocks if possible.\n", { - {"conf_target", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "Confirmation target in blocks (1 - 1008)"}, - {"threshold", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "The proportion of transactions in a given feerate range that must have been\n" + {"conf_target", RPCArg::Type::NUM, RPCArg::Optional::NO, "Confirmation target in blocks (1 - 1008)"}, + {"threshold", RPCArg::Type::NUM, /* default */ "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. Default: 0.95"}, }, diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index f855af4ed3..668488485d 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -203,7 +203,7 @@ static UniValue validateaddress(const JSONRPCRequest& request) RPCHelpMan{"validateaddress", "\nReturn information about the given dash address.\n", { - {"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The dash address to validate"}, + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The dash address to validate"}, }, RPCResult{ "{\n" @@ -247,10 +247,10 @@ static UniValue createmultisig(const JSONRPCRequest& request) "\nCreates a multi-signature address with n signature of m keys required.\n" "It returns a json object with the address and redeemScript.\n", { - {"nrequired", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The number of required signatures out of the n keys."}, - {"keys", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "A json array of hex-encoded public keys.", + {"nrequired", RPCArg::Type::NUM, RPCArg::Optional::NO, "The number of required signatures out of the n keys."}, + {"keys", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of hex-encoded public keys.", { - {"key", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The hex-encoded public key"}, + {"key", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "The hex-encoded public key"}, }}, }, RPCResult{ @@ -429,9 +429,9 @@ static UniValue verifymessage(const JSONRPCRequest& request) RPCHelpMan{"verifymessage", "\nVerify a signed message\n", { - {"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."}, + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The dash address to use for the signature."}, + {"signature", RPCArg::Type::STR, RPCArg::Optional::NO, "The signature provided by the signer in base 64 encoding (see signmessage)."}, + {"message", RPCArg::Type::STR, RPCArg::Optional::NO, "The message that was signed."}, }, RPCResult{ "true|false (boolean) If the signature is verified or not.\n" @@ -488,8 +488,8 @@ static UniValue signmessagewithprivkey(const JSONRPCRequest& request) RPCHelpMan{"signmessagewithprivkey", "\nSign a message with the private key of an address\n", { - {"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."}, + {"privkey", RPCArg::Type::STR, RPCArg::Optional::NO, "The private key to sign the message with."}, + {"message", RPCArg::Type::STR, RPCArg::Optional::NO, "The message to create a signature of."}, }, RPCResult{ "\"signature\" (string) The signature of the message encoded in base 64\n" @@ -530,7 +530,7 @@ static UniValue setmocktime(const JSONRPCRequest& request) RPCHelpMan{"setmocktime", "\nSet the local time to given timestamp (-regtest only)\n", { - {"timestamp", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "Unix seconds-since-epoch timestamp\n" + {"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, "Unix seconds-since-epoch timestamp\n" " Pass 0 to go back to using the system time."}, }, RPCResults{}, @@ -1121,7 +1121,7 @@ static UniValue getmemoryinfo(const JSONRPCRequest& request) RPCHelpMan{"getmemoryinfo", "Returns an object containing information about memory usage.\n", { - {"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" + {"mode", RPCArg::Type::STR, /* default */ "\"stats\"", "determines what kind of information is returned.\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+)."}, }, @@ -1200,13 +1200,13 @@ static UniValue logging(const JSONRPCRequest& request) " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n" , { - {"include", RPCArg::Type::ARR, /* opt */ true, /* default_val */ "", "A json array of categories to add debug logging", + {"include", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of categories to add debug logging", { - {"include_category", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "the valid logging category"}, + {"include_category", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "the valid logging category"}, }}, - {"exclude", RPCArg::Type::ARR, /* opt */ true, /* default_val */ "", "A json array of categories to remove debug logging", + {"exclude", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of categories to remove debug logging", { - {"exclude_category", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "the valid logging category"}, + {"exclude_category", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "the valid logging category"}, }}, }, RPCResult{ diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 8fa2c5765f..29b7811855 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -249,8 +249,8 @@ static UniValue addnode(const JSONRPCRequest& request) "Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be\n" "full nodes as other outbound peers are (though such peers will not be synced from).\n", { - {"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"}, + {"node", RPCArg::Type::STR, RPCArg::Optional::NO, "The node (see getpeerinfo for nodes)"}, + {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'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"}, }, RPCResults{}, RPCExamples{ @@ -294,8 +294,8 @@ 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 */ "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)"}, + {"address", RPCArg::Type::STR, /* default */ "fallback to nodeid", "The IP address/port of the node"}, + {"nodeid", RPCArg::Type::NUM, /* default */ "fallback to address", "The node ID (see getpeerinfo for node IDs)"}, }, RPCResults{}, RPCExamples{ @@ -339,7 +339,7 @@ static UniValue getaddednodeinfo(const JSONRPCRequest& request) "\nReturns information about the given added node, or all added nodes\n" "(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."}, + {"node", RPCArg::Type::STR, /* default */ "all nodes", "If provided, return information about this specific node, otherwise all nodes are returned."}, }, RPCResult{ "[\n" @@ -589,10 +589,10 @@ static UniValue setban(const JSONRPCRequest& request) RPCHelpMan{"setban", "\nAttempts to add or remove an IP/Subnet from the banned list.\n", { - {"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 */ "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)"}, + {"subnet", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP/Subnet (see getpeerinfo for nodes IP) with an optional netmask (default is /32 = single IP)"}, + {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'add' to add an IP/Subnet to the list, 'remove' to remove an IP/Subnet from the list"}, + {"bantime", RPCArg::Type::NUM, /* default */ "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, /* default */ "false", "If set, the bantime must be an absolute timestamp in seconds since epoch (Jan 1 1970 GMT)"}, }, RPCResults{}, RPCExamples{ @@ -724,7 +724,7 @@ static UniValue setnetworkactive(const JSONRPCRequest& request) RPCHelpMan{"setnetworkactive", "\nDisable/enable all p2p network activity.\n", { - {"state", RPCArg::Type::BOOL, /* opt */ false, /* default_val */ "", "true to enable networking, false to disable"}, + {"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, "true to enable networking, false to disable"}, }, RPCResults{}, RPCExamples{""}, @@ -748,7 +748,7 @@ static UniValue getnodeaddresses(const JSONRPCRequest& request) RPCHelpMan{"getnodeaddresses", "\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."}, + {"count", RPCArg::Type::NUM, /* default */ "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."}, }, RPCResult{ "[\n" diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index f42345b4a8..2291cf0a82 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -119,9 +119,9 @@ static UniValue getrawtransaction(const JSONRPCRequest& request) "\nIf verbose is 'true', returns an Object with information about 'txid'.\n" "If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'.\n", { - {"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 */ "null", "The block in which to look for the transaction"}, + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"}, + {"verbose", RPCArg::Type::BOOL, /* default */ "false", "If false, return a string, otherwise return a json object"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED_NAMED_ARG, "The block in which to look for the transaction"}, }, { RPCResult{"if verbose is not set or set to false", @@ -257,12 +257,12 @@ static UniValue gettxoutproof(const JSONRPCRequest& request) "you need to maintain a transaction index, using the -txindex command line option or\n" "specify the block in which the transaction is included manually (by blockhash).\n", { - {"txids", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "A json array of txids to filter", + {"txids", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of txids to filter", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "A transaction hash"}, + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A transaction hash"}, }, }, - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, /* default_val */ "null", "If specified, looks for txid in the block with this hash"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED_NAMED_ARG, "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" @@ -356,7 +356,7 @@ static UniValue verifytxoutproof(const JSONRPCRequest& request) "\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n" "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"}, + {"proof", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded proof generated by gettxoutproof"}, }, RPCResult{ "[\"txid\"] (array, strings) The txid(s) which the proof commits to, or empty array if the proof can not be validated.\n" @@ -497,34 +497,35 @@ static UniValue createrawtransaction(const JSONRPCRequest& request) "Note that the transaction's inputs are not signed, and\n" "it is not stored in the wallet or transmitted to the network.\n", { - {"inputs", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "A json array of json objects", + {"inputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of json objects", { - {"", RPCArg::Type::OBJ, /* opt */ false, /* default_val */ "", "", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id"}, - {"vout", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The output number"}, - {"sequence", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "The sequence number"}, + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"}, + {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"}, + {"sequence", RPCArg::Type::NUM, /* default */ "", "The sequence number"}, }, }, }, }, - {"outputs", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "a json array with outputs (key-value pairs).\n" + {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "a json array with outputs (key-value pairs).\n" + "That is, each address can only appear once and there can only be one 'data' object.\n" "For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also\n" " accepted as second parameter.", { - {"", RPCArg::Type::OBJ, /* opt */ true, /* default_val */ "", "", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"address", RPCArg::Type::AMOUNT, /* opt */ false, /* default_val */ "", "A key-value pair. The key (string) is the dash address, the value (float or string) is the amount in " + CURRENCY_UNIT}, + {"address", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "A key-value pair. The key (string) is the dash address, the value (float or string) is the amount in " + CURRENCY_UNIT}, }, }, - {"", RPCArg::Type::OBJ, /* opt */ true, /* default_val */ "", "", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"data", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "A key-value pair. The key must be \"data\", the value is hex-encoded data"}, + {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data"}, }, }, }, }, - {"locktime", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"}, + {"locktime", RPCArg::Type::NUM, /* default */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"}, }, RPCResult{ "\"transaction\" (string) hex string of the transaction\n" @@ -557,7 +558,7 @@ static UniValue decoderawtransaction(const JSONRPCRequest& request) RPCHelpMan{"decoderawtransaction", "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n", { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction hex string"}, + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction hex string"}, }, RPCResult{ "{\n" @@ -625,7 +626,7 @@ static UniValue decodescript(const JSONRPCRequest& request) RPCHelpMan{"decodescript", "\nDecode a hex-encoded script.\n", { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded script"}, + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded script"}, }, RPCResult{ "{\n" @@ -692,9 +693,9 @@ static UniValue combinerawtransaction(const JSONRPCRequest& request) "The combined transaction may be another partially signed transaction or a \n" "fully signed transaction.", { - {"txs", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "A json array of hex strings of partially signed transactions", + {"txs", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of hex strings of partially signed transactions", { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "A transaction hash"}, + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A transaction hash"}, }, }, }, @@ -910,26 +911,26 @@ static UniValue signrawtransactionwithkey(const JSONRPCRequest& request) "The third optional argument (may be null) is an array of previous transaction outputs that\n" "this transaction depends on but may not yet be in the block chain.\n", { - {"hexstring", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The transaction hex string"}, - {"privkeys", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "A json array of base58-encoded private keys for signing", + {"hexstring", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction hex string"}, + {"privkeys", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of base58-encoded private keys for signing", { - {"privatekey", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "private key in base58-encoding"}, + {"privatekey", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "private key in base58-encoding"}, }, }, - {"prevtxs", RPCArg::Type::ARR, /* opt */ true, /* default_val */ "", "A json array of previous dependent transaction outputs", + {"prevtxs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of previous dependent transaction outputs", { - {"", RPCArg::Type::OBJ, /* opt */ true, /* default_val */ "", "", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id"}, - {"vout", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The output number"}, - {"scriptPubKey", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "script key"}, - {"redeemScript", RPCArg::Type::STR_HEX, /* opt */ true, /* default_val */ "", "(required for P2SH or P2WSH) redeem script"}, - {"amount", RPCArg::Type::AMOUNT, /* opt */ false, /* default_val */ "", "The amount spent"}, + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"}, + {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"}, + {"scriptPubKey", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "script key"}, + {"redeemScript", RPCArg::Type::STR_HEX, /* default_val */ "", "(required for P2SH or P2WSH) redeem script"}, + {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The amount spent"}, }, }, }, }, - {"sighashtype", RPCArg::Type::STR, /* opt */ true, /* default_val */ "ALL", "The signature hash type. Must be one of:\n" + {"sighashtype", RPCArg::Type::STR, /* default */ "ALL", "The signature hash type. Must be one of:\n" " \"ALL\"\n" " \"NONE\"\n" " \"SINGLE\"\n" @@ -989,10 +990,10 @@ UniValue sendrawtransaction(const JSONRPCRequest& request) "\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n" "\nAlso see createrawtransaction and signrawtransactionwithkey calls.\n", { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The hex string of the raw transaction"}, - {"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"}, + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"}, + {"allowhighfees", RPCArg::Type::BOOL, /* default */ "false", "Allow high fees"}, + {"instantsend", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Deprecated and ignored"}, + {"bypasslimits", RPCArg::Type::BOOL, /* default_val */ "false", "Bypass transaction policy limits"}, }, RPCResult{ "\"hex\" (string) The transaction hash in hex\n" @@ -1040,13 +1041,13 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request) "\nThis checks if the transaction violates the consensus or policy rules.\n" "\nSee sendrawtransaction call.\n", { - {"rawtxs", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "An array of hex strings of raw transactions.\n" + {"rawtxs", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of hex strings of raw transactions.\n" " Length must be one for now.", { - {"rawtx", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", ""}, + {"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""}, }, }, - {"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Allow high fees"}, + {"allowhighfees", RPCArg::Type::BOOL, /* default */ "false", "Allow high fees"}, }, RPCResult{ "[ (array) The result of the mempool acceptance test for each raw transaction in the input array.\n" @@ -1141,7 +1142,7 @@ UniValue decodepsbt(const JSONRPCRequest& request) RPCHelpMan{"decodepsbt", "\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"}, + {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "The PSBT base64 string"}, }, RPCResult{ "{\n" @@ -1368,9 +1369,9 @@ UniValue combinepsbt(const JSONRPCRequest& request) "\nCombine multiple partially signed Dash transactions into one transaction.\n" "Implements the Combiner role.\n", { - {"txs", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "A json array of base64 strings of partially signed transactions", + {"txs", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of base64 strings of partially signed transactions", { - {"psbt", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "A base64 string of a PSBT"}, + {"psbt", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "A base64 string of a PSBT"}, }, }, }, @@ -1420,8 +1421,8 @@ UniValue finalizepsbt(const JSONRPCRequest& request) "created which has the final_scriptSig field filled for inputs that are complete.\n" "Implements the Finalizer and Extractor roles.\n", { - {"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" + {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "A base64 string of a PSBT"}, + {"extract", RPCArg::Type::BOOL, /* default */ "true", "If true and the transaction is complete,\n" " extract and return the complete transaction in normal network serialization instead of the PSBT."}, }, RPCResult{ @@ -1477,34 +1478,34 @@ UniValue createpsbt(const JSONRPCRequest& request) "\nCreates a transaction in the Partially Signed Transaction format.\n" "Implements the Creator role.\n", { - {"inputs", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "A json array of json objects", + {"inputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of json objects", { - {"", RPCArg::Type::OBJ, /* opt */ false, /* default_val */ "", "", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id"}, - {"vout", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The output number"}, - {"sequence", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "The sequence number"}, + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"}, + {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"}, + {"sequence", RPCArg::Type::NUM, /* default */ "", "The sequence number"}, }, }, }, }, - {"outputs", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "a json array with outputs (key-value pairs).\n" + {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "a json array with outputs (key-value pairs).\n" "For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also\n" " accepted as second parameter.", { - {"", RPCArg::Type::OBJ, /* opt */ true, /* default_val */ "", "", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"address", RPCArg::Type::AMOUNT, /* opt */ false, /* default_val */ "", "A key-value pair. The key (string) is the Dash address, the value (float or string) is the amount in " + CURRENCY_UNIT}, + {"address", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "A key-value pair. The key (string) is the Dash address, the value (float or string) is the amount in " + CURRENCY_UNIT}, }, }, - {"", RPCArg::Type::OBJ, /* opt */ true, /* default_val */ "", "", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"data", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "A key-value pair. The key must be \"data\", the value is hex-encoded data"}, + {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data"}, }, }, }, }, - {"locktime", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"}, + {"locktime", RPCArg::Type::NUM, /* default */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"}, }, RPCResult{ " \"psbt\" (string) The resulting raw transaction (base64-encoded string)\n" @@ -1549,8 +1550,8 @@ UniValue converttopsbt(const JSONRPCRequest& request) "\nConverts a network serialized transaction to a PSBT. This should be used only with createrawtransaction and fundrawtransaction\n" "createpsbt and walletcreatefundedpsbt should be used for new applications.\n", { - {"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" + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of a raw transaction"}, + {"permitsigdata", RPCArg::Type::BOOL, /* default */ "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."}, }, RPCResult{ diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index ec8a1ba538..31a2035bf3 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -276,8 +276,8 @@ 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 */ "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"}, + {"command", RPCArg::Type::STR, /* default */ "all commands", "The command to get help on"}, + {"subcommand", RPCArg::Type::STR, /* default */ "all subcommands", "The subcommand to get help on. Please note that not all subcommands support this at the moment"}, }, RPCResult{ "\"text\" (string) The help text\n" diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 1cf82134e2..5381ac7cb8 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -147,12 +147,12 @@ struct Sections { left += outer_type == OuterType::OBJ ? arg.ToStringObj(/* oneline */ false) : arg.ToString(/* oneline */ false); } left += ","; - PushSection({left, arg.ToDescriptionString(/* implicitly_required */ outer_type == OuterType::ARR)}); + PushSection({left, arg.ToDescriptionString()}); break; } case RPCArg::Type::OBJ: case RPCArg::Type::OBJ_USER_KEYS: { - const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString(/* implicitly_required */ outer_type == OuterType::ARR); + const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString(); PushSection({indent + "{", right}); for (const auto& arg_inner : arg.m_inner) { Push(arg_inner, current_indent + 2, OuterType::OBJ); @@ -167,7 +167,7 @@ struct Sections { auto left = indent; left += outer_type == OuterType::OBJ ? "\"" + arg.m_name + "\": " : ""; left += "["; - const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString(/* implicitly_required */ outer_type == OuterType::ARR); + const auto right = outer_type == OuterType::NAMED_ARG ? "" : arg.ToDescriptionString(); PushSection({left, right}); for (const auto& arg_inner : arg.m_inner) { Push(arg_inner, current_indent + 2, OuterType::ARR); @@ -260,8 +260,14 @@ std::string RPCHelpMan::ToString() const ret += m_name; bool was_optional{false}; for (const auto& arg : m_args) { + bool optional; + if (arg.m_fallback.which() == 1) { + optional = true; + } else { + optional = RPCArg::Optional::NO != boost::get(arg.m_fallback); + } ret += " "; - if (arg.m_optional) { + if (optional) { if (!was_optional) ret += "( "; was_optional = true; } else { @@ -301,7 +307,7 @@ std::string RPCHelpMan::ToString() const return ret; } -std::string RPCArg::ToDescriptionString(const bool implicitly_required) const +std::string RPCArg::ToDescriptionString() const { std::string ret; ret += "("; @@ -339,19 +345,24 @@ std::string RPCArg::ToDescriptionString(const bool implicitly_required) const // no default case, so the compiler can warn about missing cases } } - if (!implicitly_required) { - ret += ", "; - if (m_optional) { - ret += "optional"; - if (!m_default_value.empty()) { - ret += ", default=" + m_default_value; - } else { - // TODO enable this assert, when all optional parameters have their default value documented - //assert(false); - } - } else { - ret += "required"; - assert(m_default_value.empty()); // Default value is ignored, and must not be present + if (m_fallback.which() == 1) { + ret += ", optional, default=" + boost::get(m_fallback); + } else { + switch (boost::get(m_fallback)) { + case RPCArg::Optional::OMITTED: { + // nothing to do. Element is treated as if not present and has no default value + break; + } + case RPCArg::Optional::OMITTED_NAMED_ARG: { + ret += ", optional"; // Default value is "null" + break; + } + case RPCArg::Optional::NO: { + ret += ", required"; + break; + } + + // no default case, so the compiler can warn about missing cases } } ret += ")"; diff --git a/src/rpc/util.h b/src/rpc/util.h index 038b56cd6e..e5e58e9042 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -16,6 +16,8 @@ #include #include +#include + class CKeyStore; class CPubKey; class CScript; @@ -49,11 +51,28 @@ struct RPCArg { AMOUNT, //!< Special type representing a floating point amount (can be either NUM or STR) STR_HEX, //!< Special type that is a STR with only hex chars }; + + enum class Optional { + /** Required arg */ + NO, + /** + * Optinal arg that is a named argument and has a default value of + * `null`. When possible, the default value should be specified. + */ + OMITTED_NAMED_ARG, + /** + * Optional argument with default value omitted because they are + * implicitly clear. That is, elements in an array or object may not + * exist by default. + * When possible, the default value should be specified. + */ + OMITTED, + }; + using Fallback = boost::variant; const std::string m_name; //!< The name of the arg (can be empty for inner args) const Type m_type; const std::vector m_inner; //!< Only used for arrays or dicts - const bool m_optional; - const std::string m_default_value; //!< Only used for optional args + const Fallback m_fallback; const std::string m_description; const std::string m_oneline_description; //!< Should be empty unless it is supposed to override the auto-generated summary line const std::vector m_type_str; //!< Should be empty unless it is supposed to override the auto-generated type strings. Vector length is either 0 or 2, m_type_str.at(0) will override the type of the value in a key-value pair, m_type_str.at(1) will override the type in the argument description. @@ -61,15 +80,13 @@ struct RPCArg { RPCArg( const std::string& name, const Type& type, - const bool opt, - const std::string& default_val, + const Fallback& fallback, const std::string& description, const std::string& oneline_description = "", const std::vector& type_str = {}) : m_name{name}, m_type{type}, - m_optional{opt}, - m_default_value{default_val}, + m_fallback{fallback}, m_description{description}, m_oneline_description{oneline_description}, m_type_str{type_str} @@ -80,8 +97,7 @@ struct RPCArg { RPCArg( const std::string& name, const Type& type, - const bool opt, - const std::string& default_val, + const Fallback& fallback, const std::string& description, const std::vector& inner, const std::string& oneline_description = "", @@ -89,8 +105,7 @@ struct RPCArg { : m_name{name}, m_type{type}, m_inner{inner}, - m_optional{opt}, - m_default_value{default_val}, + m_fallback{fallback}, m_description{description}, m_oneline_description{oneline_description}, m_type_str{type_str} @@ -111,9 +126,8 @@ struct RPCArg { /** * Return the description string, including the argument type and whether * the argument is required. - * implicitly_required is set for arguments in an array, which are neither optional nor required. */ - std::string ToDescriptionString(bool implicitly_required = false) const; + std::string ToDescriptionString() const; }; struct RPCResult { diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 451aec37ff..90cad647f3 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -96,9 +96,9 @@ UniValue importprivkey(const JSONRPCRequest& request) "\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"}, + {"privkey", RPCArg::Type::STR, RPCArg::Optional::NO, "The private key (see dumpprivkey)"}, + {"label", RPCArg::Type::STR, /* default */ "current label if address exists, otherwise \"\"", "An optional label"}, + {"rescan", RPCArg::Type::BOOL, /* default */ "true", "Rescan the wallet for transactions"}, }, RPCResults{}, RPCExamples{ @@ -256,10 +256,10 @@ UniValue importaddress(const JSONRPCRequest& request) "\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"}, + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The Dash address (or hex-encoded script)"}, + {"label", RPCArg::Type::STR, /* default */ "\"\"", "An optional label"}, + {"rescan", RPCArg::Type::BOOL, /* default */ "true", "Rescan the wallet for transactions"}, + {"p2sh", RPCArg::Type::BOOL, /* default */ "false", "Add the P2SH version of the script as well"}, }, RPCResults{}, RPCExamples{ @@ -334,8 +334,8 @@ UniValue importprunedfunds(const JSONRPCRequest& request) RPCHelpMan{"importprunedfunds", "\nImports funds without rescan. Corresponding address or script must previously be included in wallet. Aimed towards pruned wallets. The end-user is responsible to import additional transactions that subsequently spend the imported outputs or rescan after the point in the blockchain the transaction is included.\n", { - {"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"}, + {"rawtransaction", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A raw transaction in hex funding an already-existing address in wallet"}, + {"txoutproof", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex output from gettxoutproof that contains the transaction"}, }, RPCResults{}, RPCExamples{""}, @@ -404,7 +404,7 @@ UniValue removeprunedfunds(const JSONRPCRequest& request) RPCHelpMan{"removeprunedfunds", "\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"}, + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded id of the transaction you are deleting"}, }, RPCResults{}, RPCExamples{ @@ -449,9 +449,9 @@ UniValue importpubkey(const JSONRPCRequest& request) "\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"}, + {"pubkey", RPCArg::Type::STR, RPCArg::Optional::NO, "The hex-encoded public key"}, + {"label", RPCArg::Type::STR, /* default */ "\"\"", "An optional label"}, + {"rescan", RPCArg::Type::BOOL, /* default */ "true", "Rescan the wallet for transactions"}, }, RPCResults{}, RPCExamples{ @@ -519,7 +519,7 @@ UniValue importwallet(const JSONRPCRequest& request) RPCHelpMan{"importwallet", "\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"}, + {"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The wallet file"}, }, RPCResults{}, RPCExamples{ @@ -825,7 +825,7 @@ UniValue dumpprivkey(const JSONRPCRequest& request) "\nReveals the private key corresponding to 'address'.\n" "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"}, + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The dash address for the private key"}, }, RPCResult{ "\"key\" (string) The private key\n" @@ -921,7 +921,7 @@ UniValue dumpwallet(const JSONRPCRequest& request) "Note that if your wallet contains keys which are not derived from your HD seed (e.g. imported keys), these are not covered by\n" "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)"}, + {"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The filename with path (either absolute or relative to dashd)"}, }, RPCResult{ "{ (json object)\n" @@ -1476,16 +1476,16 @@ UniValue importmulti(const JSONRPCRequest& mainRequest) "\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", + {"requests", RPCArg::Type::ARR, RPCArg::Optional::NO, "Data to be imported", { - {"", RPCArg::Type::OBJ, /* opt */ false, /* default_val */ "", "", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"desc", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "Descriptor to import. If using descriptor, do not also provide address/scriptPubKey, scripts, or pubkeys" + {"desc", RPCArg::Type::STR, /* default */ "", "Descriptor to import. If using descriptor, do not also provide address/scriptPubKey, scripts, or pubkeys" }, - {"scriptPubKey", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "Type of scriptPubKey (string for script, json for address). Should not be provided if using a descriptor", + {"scriptPubKey", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of scriptPubKey (string for script, json for address). Should not be provided if using a descriptor", /* oneline_description */ "", {"\"