From 12173ca8610d60dd5f15b31336ab20e7feb9f886 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Wed, 19 Jun 2019 13:59:11 +0900 Subject: [PATCH 01/15] rpc: switch to using RPCHelpMan.Check() --- src/rpc/blockchain.cpp | 1446 ++++++++++++------------ src/rpc/coinjoin.cpp | 4 +- src/rpc/governance.cpp | 8 +- src/rpc/mining.cpp | 530 +++++---- src/rpc/misc.cpp | 786 ++++++------- src/rpc/net.cpp | 560 +++++----- src/rpc/rawtransaction.cpp | 694 ++++++------ src/rpc/server.cpp | 83 +- src/wallet/rpcdump.cpp | 478 ++++---- src/wallet/rpcwallet.cpp | 2163 +++++++++++++++++------------------- src/zmq/zmqrpc.cpp | 41 +- 11 files changed, 3207 insertions(+), 3586 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 71a630eb3ca1..e517f14500dd 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -191,19 +191,17 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIn static UniValue getblockcount(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 0) - throw std::runtime_error( - RPCHelpMan{"getblockcount", - "\nReturns the height of the most-work fully-validated chain.\n" - "The genesis block has height 0.\n", - {}, - RPCResult{ - RPCResult::Type::NUM, "", "The current block count"}, - RPCExamples{ - HelpExampleCli("getblockcount", "") - + HelpExampleRpc("getblockcount", "") - }, - }.ToString()); + RPCHelpMan{"getblockcount", + "\nReturns the height of the most-work fully-validated chain.\n" + "The genesis block has height 0.\n", + {}, + RPCResult{ + RPCResult::Type::NUM, "", "The current block count"}, + RPCExamples{ + HelpExampleCli("getblockcount", "") + + HelpExampleRpc("getblockcount", "") + }, + }.Check(request); LOCK(cs_main); return ::ChainActive().Height(); @@ -211,18 +209,16 @@ static UniValue getblockcount(const JSONRPCRequest& request) 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 most-work fully-validated chain.\n", - {}, - RPCResult{ - RPCResult::Type::STR_HEX, "", "the block hash, hex-encoded"}, - RPCExamples{ - HelpExampleCli("getbestblockhash", "") - + HelpExampleRpc("getbestblockhash", "") - }, - }.ToString()); + RPCHelpMan{"getbestblockhash", + "\nReturns the hash of the best (tip) block in the most-work fully-validated chain.\n", + {}, + RPCResult{ + RPCResult::Type::STR_HEX, "", "the block hash, hex-encoded"}, + RPCExamples{ + HelpExampleCli("getbestblockhash", "") + + HelpExampleRpc("getbestblockhash", "") + }, + }.Check(request); LOCK(cs_main); return ::ChainActive().Tip()->GetBlockHash().GetHex(); @@ -230,24 +226,22 @@ static UniValue getbestblockhash(const JSONRPCRequest& request) static UniValue getbestchainlock(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 0) - throw std::runtime_error( - RPCHelpMan{"getbestchainlock", - "\nReturns information about the best chainlock. Throws an error if there is no known chainlock yet.", - {}, - RPCResult{ - "{\n" - " \"blockhash\" : \"hash\", (string) The block hash hex-encoded\n" - " \"height\" : n, (numeric) The block height or index\n" - " \"signature\" : \"hash\", (string) The chainlock's BLS signature.\n" - " \"known_block\" : true|false (boolean) True if the block is known by our node\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getbestchainlock", "") - + HelpExampleRpc("getbestchainlock", "") - }, - }.ToString()); + RPCHelpMan{"getbestchainlock", + "\nReturns information about the best chainlock. Throws an error if there is no known chainlock yet.", + {}, + RPCResult{ + "{\n" + " \"blockhash\" : \"hash\", (string) The block hash hex-encoded\n" + " \"height\" : n, (numeric) The block height or index\n" + " \"signature\" : \"hash\", (string) The chainlock's BLS signature.\n" + " \"known_block\" : true|false (boolean) True if the block is known by our node\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("getbestchainlock", "") + + HelpExampleRpc("getbestchainlock", "") + }, + }.Check(request); UniValue result(UniValue::VOBJ); llmq::CChainLockSig clsig = llmq::chainLocksHandler->GetBestChainLock(); @@ -275,25 +269,23 @@ void RPCNotifyBlockChange(bool ibd, const CBlockIndex * pindex) static UniValue waitfornewblock(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 1) - throw std::runtime_error( - RPCHelpMan{"waitfornewblock", - "\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, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."}, - }, - RPCResult{ - RPCResult::Type::OBJ, "", "", - { - {RPCResult::Type::STR_HEX, "hash", "The blockhash"}, - {RPCResult::Type::NUM, "height", "Block height"}, - }}, - RPCExamples{ - HelpExampleCli("waitfornewblock", "1000") - + HelpExampleRpc("waitfornewblock", "1000") - }, - }.ToString()); + RPCHelpMan{"waitfornewblock", + "\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, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."}, + }, + RPCResult{ + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::STR_HEX, "hash", "The blockhash"}, + {RPCResult::Type::NUM, "height", "Block height"}, + }}, + RPCExamples{ + HelpExampleCli("waitfornewblock", "1000") + + HelpExampleRpc("waitfornewblock", "1000") + }, + }.Check(request); int timeout = 0; if (!request.params[0].isNull()) timeout = request.params[0].get_int(); @@ -316,26 +308,24 @@ static UniValue waitfornewblock(const JSONRPCRequest& request) static UniValue waitforblock(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"waitforblock", - "\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, 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{ - RPCResult::Type::OBJ, "", "", - { - {RPCResult::Type::STR_HEX, "hash", "The blockhash"}, - {RPCResult::Type::NUM, "height", "Block height"}, - }}, - RPCExamples{ - HelpExampleCli("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\" 1000") - + HelpExampleRpc("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000") - }, - }.ToString()); + RPCHelpMan{"waitforblock", + "\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, 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{ + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::STR_HEX, "hash", "The blockhash"}, + {RPCResult::Type::NUM, "height", "Block height"}, + }}, + RPCExamples{ + HelpExampleCli("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\" 1000") + + HelpExampleRpc("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000") + }, + }.Check(request); int timeout = 0; uint256 hash = uint256S(request.params[0].get_str()); @@ -361,27 +351,25 @@ static UniValue waitforblock(const JSONRPCRequest& request) static UniValue waitforblockheight(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"waitforblockheight", - "\nWaits for (at least) block height and returns the height and hash\n" - "of the current tip.\n" - "\nReturns the current block on timeout or exit.\n", - { - {"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{ - RPCResult::Type::OBJ, "", "", - { - {RPCResult::Type::STR_HEX, "hash", "The blockhash"}, - {RPCResult::Type::NUM, "height", "Block height"}, - }}, - RPCExamples{ - HelpExampleCli("waitforblockheight", "100 1000") - + HelpExampleRpc("waitforblockheight", "100, 1000") - }, - }.ToString()); + RPCHelpMan{"waitforblockheight", + "\nWaits for (at least) block height and returns the height and hash\n" + "of the current tip.\n" + "\nReturns the current block on timeout or exit.\n", + { + {"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{ + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::STR_HEX, "hash", "The blockhash"}, + {RPCResult::Type::NUM, "height", "Block height"}, + }}, + RPCExamples{ + HelpExampleCli("waitforblockheight", "100 1000") + + HelpExampleRpc("waitforblockheight", "100, 1000") + }, + }.Check(request); int timeout = 0; int height = request.params[0].get_int(); @@ -407,36 +395,31 @@ static UniValue waitforblockheight(const JSONRPCRequest& request) 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", - {}, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - HelpExampleCli("syncwithvalidationinterfacequeue","") - + HelpExampleRpc("syncwithvalidationinterfacequeue","") - }, - }.ToString()); - } + RPCHelpMan{"syncwithvalidationinterfacequeue", + "\nWaits for the validation interface queue to catch up on everything that was there when we entered this function.\n", + {}, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("syncwithvalidationinterfacequeue","") + + HelpExampleRpc("syncwithvalidationinterfacequeue","") + }, + }.Check(request); SyncWithValidationInterfaceQueue(); return NullUniValue; } 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", - {}, - RPCResult{ - RPCResult::Type::NUM, "", "the proof-of-work difficulty as a multiple of the minimum difficulty."}, - RPCExamples{ - HelpExampleCli("getdifficulty", "") - + HelpExampleRpc("getdifficulty", "") - }, - }.ToString()); + RPCHelpMan{"getdifficulty", + "\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n", + {}, + RPCResult{ + RPCResult::Type::NUM, "", "the proof-of-work difficulty as a multiple of the minimum difficulty."}, + RPCExamples{ + HelpExampleCli("getdifficulty", "") + + HelpExampleRpc("getdifficulty", "") + }, + }.Check(request); LOCK(cs_main); return GetDifficulty(::ChainActive().Tip()); @@ -551,31 +534,29 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose) static UniValue getrawmempool(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 1) - throw std::runtime_error( - RPCHelpMan{"getrawmempool", - "\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, /* default */ "false", "True for a json object, false for array of transaction ids"}, - }, - RPCResult{"for verbose = false", - "[ (json array of string)\n" - " \"transactionid\" (string) The transaction id\n" - " ,...\n" - "]\n" - "\nResult: (for verbose = true):\n" - "{ (json object)\n" - " \"transactionid\" : { (json object)\n" - + EntryDescriptionString() - + " }, ...\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getrawmempool", "true") - + HelpExampleRpc("getrawmempool", "true") - }, - }.ToString()); + RPCHelpMan{"getrawmempool", + "\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, /* default */ "false", "True for a json object, false for array of transaction ids"}, + }, + RPCResult{"for verbose = false", + "[ (json array of string)\n" + " \"transactionid\" (string) The transaction id\n" + " ,...\n" + "]\n" + "\nResult: (for verbose = true):\n" + "{ (json object)\n" + " \"transactionid\" : { (json object)\n" + + EntryDescriptionString() + + " }, ...\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("getrawmempool", "true") + + HelpExampleRpc("getrawmempool", "true") + }, + }.Check(request); bool fVerbose = false; if (!request.params[0].isNull()) @@ -586,35 +567,32 @@ static UniValue getrawmempool(const JSONRPCRequest& request) static UniValue getmempoolancestors(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"getmempoolancestors", - "\nIf txid is in the mempool, returns all in-mempool ancestors.\n", - { - {"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", - "[ (json array of strings)\n" - " \"transactionid\" (string) The transaction id of an in-mempool ancestor transaction\n" - " ,...\n" - "]\n" - }, - RPCResult{"for verbose = true", - "{ (json object)\n" - " \"transactionid\" : { (json object)\n" - + EntryDescriptionString() - + " }, ...\n" - "}\n" - }, - }, - RPCExamples{ - HelpExampleCli("getmempoolancestors", "\"mytxid\"") - + HelpExampleRpc("getmempoolancestors", "\"mytxid\"") - }, - }.ToString()); - } + RPCHelpMan{"getmempoolancestors", + "\nIf txid is in the mempool, returns all in-mempool ancestors.\n", + { + {"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", + "[ (json array of strings)\n" + " \"transactionid\" (string) The transaction id of an in-mempool ancestor transaction\n" + " ,...\n" + "]\n" + }, + RPCResult{"for verbose = true", + "{ (json object)\n" + " \"transactionid\" : { (json object)\n" + + EntryDescriptionString() + + " }, ...\n" + "}\n" + }, + }, + RPCExamples{ + HelpExampleCli("getmempoolancestors", "\"mytxid\"") + + HelpExampleRpc("getmempoolancestors", "\"mytxid\"") + }, + }.Check(request); bool fVerbose = false; if (!request.params[1].isNull()) @@ -656,35 +634,32 @@ static UniValue getmempoolancestors(const JSONRPCRequest& request) static UniValue getmempooldescendants(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"getmempooldescendants", - "\nIf txid is in the mempool, returns all in-mempool descendants.\n", - { - {"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", - "[ (json array of strings)\n" - " \"transactionid\" (string) The transaction id of an in-mempool descendant transaction\n" - " ,...\n" - "]\n" - }, - RPCResult{"for verbose = true", - "{ (json object)\n" - " \"transactionid\" : { (json object)\n" - + EntryDescriptionString() - + " }, ...\n" - "}\n" - }, - }, - RPCExamples{ - HelpExampleCli("getmempooldescendants", "\"mytxid\"") - + HelpExampleRpc("getmempooldescendants", "\"mytxid\"") - }, - }.ToString()); - } + RPCHelpMan{"getmempooldescendants", + "\nIf txid is in the mempool, returns all in-mempool descendants.\n", + { + {"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", + "[ (json array of strings)\n" + " \"transactionid\" (string) The transaction id of an in-mempool descendant transaction\n" + " ,...\n" + "]\n" + }, + RPCResult{"for verbose = true", + "{ (json object)\n" + " \"transactionid\" : { (json object)\n" + + EntryDescriptionString() + + " }, ...\n" + "}\n" + }, + }, + RPCExamples{ + HelpExampleCli("getmempooldescendants", "\"mytxid\"") + + HelpExampleRpc("getmempooldescendants", "\"mytxid\"") + }, + }.Check(request); bool fVerbose = false; if (!request.params[1].isNull()) @@ -726,24 +701,21 @@ static UniValue getmempooldescendants(const JSONRPCRequest& request) static UniValue getmempoolentry(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"getmempoolentry", - "\nReturns mempool data for given transaction\n", - { - {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"}, - }, - RPCResult{ - "{ (json object)\n" - + EntryDescriptionString() - + "}\n" - }, - RPCExamples{ - HelpExampleCli("getmempoolentry", "\"mytxid\"") - + HelpExampleRpc("getmempoolentry", "\"mytxid\"") - }, - }.ToString()); - } + RPCHelpMan{"getmempoolentry", + "\nReturns mempool data for given transaction\n", + { + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"}, + }, + RPCResult{ + "{ (json object)\n" + + EntryDescriptionString() + + "}\n" + }, + RPCExamples{ + HelpExampleCli("getmempoolentry", "\"mytxid\"") + + HelpExampleRpc("getmempoolentry", "\"mytxid\"") + }, + }.Check(request); uint256 hash = ParseHashV(request.params[0], "parameter 1"); @@ -762,24 +734,22 @@ static UniValue getmempoolentry(const JSONRPCRequest& request) static UniValue getblockhashes(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 2) - throw std::runtime_error( - RPCHelpMan{"getblockhashes", - "\nReturns array of hashes of blocks within the timestamp range provided.\n", - { - {"high", RPCArg::Type::NUM, RPCArg::Optional::NO, "The newer block timestamp"}, - {"low", RPCArg::Type::NUM, RPCArg::Optional::NO, "The older block timestamp"}, - }, - RPCResult{ - "[\n" - " \"hash\" (string) The block hash\n" - "]\n" - }, - RPCExamples{ - HelpExampleCli("getblockhashes", "1231614698 1231024505") - + HelpExampleRpc("getblockhashes", "1231614698, 1231024505") - }, - }.ToString()); + RPCHelpMan{"getblockhashes", + "\nReturns array of hashes of blocks within the timestamp range provided.\n", + { + {"high", RPCArg::Type::NUM, RPCArg::Optional::NO, "The newer block timestamp"}, + {"low", RPCArg::Type::NUM, RPCArg::Optional::NO, "The older block timestamp"}, + }, + RPCResult{ + "[\n" + " \"hash\" (string) The block hash\n" + "]\n" + }, + RPCExamples{ + HelpExampleCli("getblockhashes", "1231614698 1231024505") + + HelpExampleRpc("getblockhashes", "1231614698, 1231024505") + }, + }.Check(request); unsigned int high = request.params[0].get_int(); unsigned int low = request.params[1].get_int(); @@ -799,20 +769,18 @@ static UniValue getblockhashes(const JSONRPCRequest& request) static UniValue getblockhash(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"getblockhash", - "\nReturns hash of block in best-block-chain at height provided.\n", - { - {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "The height index"}, - }, - RPCResult{ - RPCResult::Type::STR_HEX, "", "The block hash"}, - RPCExamples{ - HelpExampleCli("getblockhash", "1000") - + HelpExampleRpc("getblockhash", "1000") - }, - }.ToString()); + RPCHelpMan{"getblockhash", + "\nReturns hash of block in best-block-chain at height provided.\n", + { + {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "The height index"}, + }, + RPCResult{ + RPCResult::Type::STR_HEX, "", "The block hash"}, + RPCExamples{ + HelpExampleCli("getblockhash", "1000") + + HelpExampleRpc("getblockhash", "1000") + }, + }.Check(request); LOCK(cs_main); @@ -826,44 +794,42 @@ static UniValue getblockhash(const JSONRPCRequest& request) static UniValue getblockheader(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"getblockheader", - "\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, 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", - "{\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" - " \"height\" : n, (numeric) The block height or index\n" - " \"version\" : n, (numeric) The block version\n" - " \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n" - " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" - " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" - " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n" - " \"nonce\" : n, (numeric) The nonce\n" - " \"bits\" : \"1d00ffff\", (string) The bits\n" - " \"difficulty\" : x.xxx, (numeric) The difficulty\n" - " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n" - " \"nTx\" : n, (numeric) The number of transactions in the block.\n" - " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" - " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n" - "}\n" - }, - RPCResult{"for verbose=false", - "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n" - }, - }, - RPCExamples{ - HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") - + HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") - }, - }.ToString()); + RPCHelpMan{"getblockheader", + "\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, 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", + "{\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" + " \"height\" : n, (numeric) The block height or index\n" + " \"version\" : n, (numeric) The block version\n" + " \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n" + " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" + " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" + " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n" + " \"nonce\" : n, (numeric) The nonce\n" + " \"bits\" : \"1d00ffff\", (string) The bits\n" + " \"difficulty\" : x.xxx, (numeric) The difficulty\n" + " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n" + " \"nTx\" : n, (numeric) The number of transactions in the block.\n" + " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" + " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n" + "}\n" + }, + RPCResult{"for verbose=false", + "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n" + }, + }, + RPCExamples{ + HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") + + HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") + }, + }.Check(request); std::string strHash = request.params[0].get_str(); uint256 hash(uint256S(strHash)); @@ -897,49 +863,47 @@ static UniValue getblockheader(const JSONRPCRequest& request) static UniValue getblockheaders(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) - throw std::runtime_error( - RPCHelpMan{"getblockheaders", - "\nReturns an array of items with information about blockheaders starting from .\n" - "\nIf verbose is false, each item is a string that is serialized, hex-encoded data for a single blockheader.\n" - "If verbose is true, each item is an Object with information about a single blockheader.\n", - { - {"hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, - {"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS_RESULTS), ""}, - {"verbose", RPCArg::Type::BOOL, /* default */ "true", "true for a json object, false for the hex-encoded data"}, - }, - RPCResults{ - {"for verbose = true", - "[ {\n" - " \"hash\" : \"hash\", (string) The block hash\n" - " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n" - " \"height\" : n, (numeric) The block height or index\n" - " \"version\" : n, (numeric) The block version\n" - " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" - " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" - " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n" - " \"nonce\" : n, (numeric) The nonce\n" - " \"bits\" : \"1d00ffff\", (string) The bits\n" - " \"difficulty\" : x.xxx, (numeric) The difficulty\n" - " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n" - " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" - " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n" - "}, {\n" - " ...\n" - " },\n" - "...\n" - "]\n" - },{"for verbose=false", - "[\n" - " \"data\", (string) A string that is serialized, hex-encoded data for block header.\n" - " ...\n" - "]\n" - }}, - RPCExamples{ - HelpExampleCli("getblockheaders", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 2000") - + HelpExampleRpc("getblockheaders", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 2000") - }, - }.ToString()); + RPCHelpMan{"getblockheaders", + "\nReturns an array of items with information about blockheaders starting from .\n" + "\nIf verbose is false, each item is a string that is serialized, hex-encoded data for a single blockheader.\n" + "If verbose is true, each item is an Object with information about a single blockheader.\n", + { + {"hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, + {"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS_RESULTS), ""}, + {"verbose", RPCArg::Type::BOOL, /* default */ "true", "true for a json object, false for the hex-encoded data"}, + }, + RPCResults{ + {"for verbose = true", + "[ {\n" + " \"hash\" : \"hash\", (string) The block hash\n" + " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n" + " \"height\" : n, (numeric) The block height or index\n" + " \"version\" : n, (numeric) The block version\n" + " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" + " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" + " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n" + " \"nonce\" : n, (numeric) The nonce\n" + " \"bits\" : \"1d00ffff\", (string) The bits\n" + " \"difficulty\" : x.xxx, (numeric) The difficulty\n" + " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n" + " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" + " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n" + "}, {\n" + " ...\n" + " },\n" + "...\n" + "]\n" + },{"for verbose=false", + "[\n" + " \"data\", (string) A string that is serialized, hex-encoded data for block header.\n" + " ...\n" + "]\n" + }}, + RPCExamples{ + HelpExampleCli("getblockheaders", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 2000") + + HelpExampleRpc("getblockheaders", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 2000") + }, + }.Check(request); LOCK(cs_main); @@ -1010,26 +974,24 @@ static CBlock GetBlockChecked(const CBlockIndex* pblockindex) static UniValue getmerkleblocks(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) - throw std::runtime_error( - RPCHelpMan{"getmerkleblocks", - "\nReturns an array of hex-encoded merkleblocks for blocks starting from which match .\n", - { - {"filter", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded bloom filter"}, - {"hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, - {"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS_RESULTS), ""}, - }, - RPCResult{ - "[\n" - " \"data\", (string) A string that is serialized, hex-encoded data for a merkleblock.\n" - " ...\n" - "]\n" - }, - RPCExamples{ - HelpExampleCli("getmerkleblocks", "\"2303028005802040100040000008008400048141010000f8400420800080025004000004130000000000000001\" \"00000000007e1432d2af52e8463278bf556b55cf5049262f25634557e2e91202\" 2000") - + HelpExampleRpc("getmerkleblocks", "\"2303028005802040100040000008008400048141010000f8400420800080025004000004130000000000000001\" \"00000000007e1432d2af52e8463278bf556b55cf5049262f25634557e2e91202\" 2000") - }, - }.ToString()); + RPCHelpMan{"getmerkleblocks", + "\nReturns an array of hex-encoded merkleblocks for blocks starting from which match .\n", + { + {"filter", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded bloom filter"}, + {"hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, + {"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS_RESULTS), ""}, + }, + RPCResult{ + "[\n" + " \"data\", (string) A string that is serialized, hex-encoded data for a merkleblock.\n" + " ...\n" + "]\n" + }, + RPCExamples{ + HelpExampleCli("getmerkleblocks", "\"2303028005802040100040000008008400048141010000f8400420800080025004000004130000000000000001\" \"00000000007e1432d2af52e8463278bf556b55cf5049262f25634557e2e91202\" 2000") + + HelpExampleRpc("getmerkleblocks", "\"2303028005802040100040000008008400048141010000f8400420800080025004000004130000000000000001\" \"00000000007e1432d2af52e8463278bf556b55cf5049262f25634557e2e91202\" 2000") + }, + }.Check(request); LOCK(cs_main); @@ -1089,9 +1051,7 @@ static UniValue getmerkleblocks(const JSONRPCRequest& request) static UniValue getblock(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"getblock", + RPCHelpMan{"getblock", "\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n" "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", @@ -1146,7 +1106,7 @@ static UniValue getblock(const JSONRPCRequest& request) HelpExampleCli("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"") + HelpExampleRpc("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"") }, - }.ToString()); + }.Check(request); LOCK(cs_main); @@ -1181,20 +1141,18 @@ static UniValue getblock(const JSONRPCRequest& request) static UniValue pruneblockchain(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"pruneblockchain", "", - { - {"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{ - RPCResult::Type::NUM, "", "Height of the last block pruned"}, - RPCExamples{ - HelpExampleCli("pruneblockchain", "1000") - + HelpExampleRpc("pruneblockchain", "1000") - }, - }.ToString()); + RPCHelpMan{"pruneblockchain", "", + { + {"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{ + RPCResult::Type::NUM, "", "Height of the last block pruned"}, + RPCExamples{ + HelpExampleCli("pruneblockchain", "1000") + + HelpExampleRpc("pruneblockchain", "1000") + }, + }.Check(request); if (!fPruneMode) throw JSONRPCError(RPC_MISC_ERROR, "Cannot prune blocks because node is not in prune mode."); @@ -1251,32 +1209,30 @@ CoinStatsHashType ParseHashType(const std::string& hash_type_input) static UniValue gettxoutsetinfo(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 1) - throw std::runtime_error( - RPCHelpMan{"gettxoutsetinfo", - "\nReturns statistics about the unspent transaction output set.\n" - "Note this call may take some time.\n", - { - {"hash_type", RPCArg::Type::STR, /* default */ "hash_serialized_2", "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'muhash', 'none'."}, - }, - RPCResult{ - RPCResult::Type::OBJ, "", "", - { - {RPCResult::Type::NUM, "height", "The current block height (index)"}, - {RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at the tip of the chain"}, - {RPCResult::Type::NUM, "transactions", "The number of transactions with unspent outputs"}, - {RPCResult::Type::NUM, "txouts", "The number of unspent transaction outputs"}, - {RPCResult::Type::NUM, "bogosize", "A meaningless metric for UTXO set size"}, - {RPCResult::Type::STR_HEX, "hash_serialized_2", "The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)"}, - {RPCResult::Type::STR_HEX, "muhash", "The serialized hash (only present if 'muhash' hash_type is chosen)"}, - {RPCResult::Type::NUM, "disk_size", "The estimated size of the chainstate on disk"}, - {RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount"}, - }}, - RPCExamples{ - HelpExampleCli("gettxoutsetinfo", "") - + HelpExampleRpc("gettxoutsetinfo", "") - }, - }.ToString()); + RPCHelpMan{"gettxoutsetinfo", + "\nReturns statistics about the unspent transaction output set.\n" + "Note this call may take some time.\n", + { + {"hash_type", RPCArg::Type::STR, /* default */ "hash_serialized_2", "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'muhash', 'none'."}, + }, + RPCResult{ + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::NUM, "height", "The current block height (index)"}, + {RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at the tip of the chain"}, + {RPCResult::Type::NUM, "transactions", "The number of transactions with unspent outputs"}, + {RPCResult::Type::NUM, "txouts", "The number of unspent transaction outputs"}, + {RPCResult::Type::NUM, "bogosize", "A meaningless metric for UTXO set size"}, + {RPCResult::Type::STR_HEX, "hash_serialized_2", "The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)"}, + {RPCResult::Type::STR_HEX, "muhash", "The serialized hash (only present if 'muhash' hash_type is chosen)"}, + {RPCResult::Type::NUM, "disk_size", "The estimated size of the chainstate on disk"}, + {RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount"}, + }}, + RPCExamples{ + HelpExampleCli("gettxoutsetinfo", "") + + HelpExampleRpc("gettxoutsetinfo", "") + }, + }.Check(request); UniValue ret(UniValue::VOBJ); @@ -1308,42 +1264,40 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request) static UniValue gettxout(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) - throw std::runtime_error( - RPCHelpMan{"gettxout", - "\nReturns details about an unspent transaction output.\n", - { - {"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" - " \"bestblock\" : \"hash\", (string) The hash of the block at the tip of the chain\n" - " \"confirmations\" : n, (numeric) The number of confirmations\n" - " \"value\" : x.xxx, (numeric) The transaction value in " + CURRENCY_UNIT + "\n" - " \"scriptPubKey\" : { (json object)\n" - " \"asm\" : \"code\", (string) \n" - " \"hex\" : \"hex\", (string) \n" - " \"reqSigs\" : n, (numeric) Number of required signatures\n" - " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n" - " \"addresses\" : [ (array of string) array of dash addresses\n" - " \"address\" (string) dash address\n" - " ,...\n" - " ]\n" - " },\n" - " \"coinbase\" : true|false (boolean) Coinbase or not\n" - "}\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()); + RPCHelpMan{"gettxout", + "\nReturns details about an unspent transaction output.\n", + { + {"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" + " \"bestblock\" : \"hash\", (string) The hash of the block at the tip of the chain\n" + " \"confirmations\" : n, (numeric) The number of confirmations\n" + " \"value\" : x.xxx, (numeric) The transaction value in " + CURRENCY_UNIT + "\n" + " \"scriptPubKey\" : { (json object)\n" + " \"asm\" : \"code\", (string) \n" + " \"hex\" : \"hex\", (string) \n" + " \"reqSigs\" : n, (numeric) Number of required signatures\n" + " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n" + " \"addresses\" : [ (array of string) array of dash addresses\n" + " \"address\" (string) dash address\n" + " ,...\n" + " ]\n" + " },\n" + " \"coinbase\" : true|false (boolean) Coinbase or not\n" + "}\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") + }, + }.Check(request); LOCK(cs_main); @@ -1392,21 +1346,19 @@ static UniValue verifychain(const JSONRPCRequest& request) { int nCheckLevel = gArgs.GetArg("-checklevel", DEFAULT_CHECKLEVEL); int nCheckDepth = gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS); - if (request.fHelp || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"verifychain", - "\nVerifies blockchain database.\n", - { - {"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{ - RPCResult::Type::BOOL, "", "Verified or not"}, - RPCExamples{ - HelpExampleCli("verifychain", "") - + HelpExampleRpc("verifychain", "") - }, - }.ToString()); + RPCHelpMan{"verifychain", + "\nVerifies blockchain database.\n", + { + {"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{ + RPCResult::Type::BOOL, "", "Verified or not"}, + RPCExamples{ + HelpExampleCli("verifychain", "") + + HelpExampleRpc("verifychain", "") + }, + }.Check(request); LOCK(cs_main); @@ -1492,61 +1444,59 @@ static void BIP9SoftForkDescPushBack(UniValue& bip9_softforks, const Consensus:: 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", - {}, - RPCResult{ - "{\n" - " \"chain\" : \"xxxx\", (string) current network name (main, test, regtest) and\n" - " devnet or devnet- for \"-devnet\" and \"-devnet=\" respectively\n" - " \"blocks\" : xxxxxx, (numeric) the height of the most-work fully-validated chain. The genesis block has height 0\n" - " \"headers\" : xxxxxx, (numeric) the current number of headers we have validated\n" - " \"bestblockhash\" : \"...\", (string) the hash of the currently best block\n" - " \"difficulty\" : xxxxxx, (numeric) the current difficulty\n" - " \"mediantime\" : xxxxxx, (numeric) median time for the current best block\n" - " \"verificationprogress\" : xxxx, (numeric) estimate of verification progress [0..1]\n" - " \"initialblockdownload\" : xxxx, (boolean) (debug information) estimate of whether this node is in Initial Block Download mode.\n" - " \"chainwork\" : \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n" - " \"size_on_disk\" : xxxxxx, (numeric) the estimated size of the block and undo files on disk\n" - " \"pruned\" : xx, (boolean) if the blocks are subject to pruning\n" - " \"pruneheight\" : xxxxxx, (numeric) lowest-height complete block stored (only present if pruning is enabled)\n" - " \"automatic_pruning\" : xx, (boolean) whether automatic pruning is enabled (only present if pruning is enabled)\n" - " \"prune_target_size\" : xxxxxx, (numeric) the target size used by pruning (only present if automatic pruning is enabled)\n" - " \"softforks\" : [ (json array) status of softforks in progress\n" - " {\n" - " \"id\" : \"xxxx\", (string) name of softfork\n" - " \"version\" : xx, (numeric) block version\n" - " \"reject\" : { (json object) progress toward rejecting pre-softfork blocks\n" - " \"status\" : xx, (boolean) true if threshold reached\n" - " },\n" - " }, ...\n" - " ],\n" - " \"bip9_softforks\": { (json object) status of BIP9 softforks in progress\n" - " \"xxxx\" : { (string) name of the softfork\n" - " \"status\" : \"xxxx\", (string) one of \"defined\", \"started\", \"locked_in\", \"active\", \"failed\"\n" - " \"bit\" : xx, (numeric) the bit (0-28) in the block version field used to signal this softfork (only for \"started\" status)\n" - " \"start_time\" : xx, (numeric) the minimum median time past of a block at which the bit gains its meaning\n" - " \"timeout\" : xx, (numeric) the median time past of a block at which the deployment is considered failed if not yet locked in\n" - " \"since\" : xx, (numeric) height of the first block to which the status applies\n" - " \"statistics\" : { (json object) numeric statistics about BIP9 signalling for a softfork (only for \"started\" status)\n" - " \"period\" : xx, (numeric) the length in blocks of the BIP9 signalling period \n" - " \"threshold\" : xx, (numeric) the number of blocks with the version bit set required to activate the feature \n" - " \"elapsed\" : xx, (numeric) the number of blocks elapsed since the beginning of the current period \n" - " \"count\" : xx, (numeric) the number of blocks with the version bit set in the current period \n" - " \"possible\" : xx (boolean) returns false if there are not enough blocks left in this period to pass activation threshold \n" - " }\n" - " }\n" - " }\n" - " \"warnings\" : \"...\", (string) any network and blockchain warnings.\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getblockchaininfo", "") - + HelpExampleRpc("getblockchaininfo", "") - }, - }.ToString()); + RPCHelpMan{"getblockchaininfo", + "Returns an object containing various state info regarding blockchain processing.\n", + {}, + RPCResult{ + "{\n" + " \"chain\" : \"xxxx\", (string) current network name (main, test, regtest) and\n" + " devnet or devnet- for \"-devnet\" and \"-devnet=\" respectively\n" + " \"blocks\" : xxxxxx, (numeric) the height of the most-work fully-validated chain. The genesis block has height 0\n" + " \"headers\" : xxxxxx, (numeric) the current number of headers we have validated\n" + " \"bestblockhash\" : \"...\", (string) the hash of the currently best block\n" + " \"difficulty\" : xxxxxx, (numeric) the current difficulty\n" + " \"mediantime\" : xxxxxx, (numeric) median time for the current best block\n" + " \"verificationprogress\" : xxxx, (numeric) estimate of verification progress [0..1]\n" + " \"initialblockdownload\" : xxxx, (boolean) (debug information) estimate of whether this node is in Initial Block Download mode.\n" + " \"chainwork\" : \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n" + " \"size_on_disk\" : xxxxxx, (numeric) the estimated size of the block and undo files on disk\n" + " \"pruned\" : xx, (boolean) if the blocks are subject to pruning\n" + " \"pruneheight\" : xxxxxx, (numeric) lowest-height complete block stored (only present if pruning is enabled)\n" + " \"automatic_pruning\" : xx, (boolean) whether automatic pruning is enabled (only present if pruning is enabled)\n" + " \"prune_target_size\" : xxxxxx, (numeric) the target size used by pruning (only present if automatic pruning is enabled)\n" + " \"softforks\" : [ (json array) status of softforks in progress\n" + " {\n" + " \"id\" : \"xxxx\", (string) name of softfork\n" + " \"version\" : xx, (numeric) block version\n" + " \"reject\" : { (json object) progress toward rejecting pre-softfork blocks\n" + " \"status\" : xx, (boolean) true if threshold reached\n" + " },\n" + " }, ...\n" + " ],\n" + " \"bip9_softforks\": { (json object) status of BIP9 softforks in progress\n" + " \"xxxx\" : { (string) name of the softfork\n" + " \"status\" : \"xxxx\", (string) one of \"defined\", \"started\", \"locked_in\", \"active\", \"failed\"\n" + " \"bit\" : xx, (numeric) the bit (0-28) in the block version field used to signal this softfork (only for \"started\" status)\n" + " \"start_time\" : xx, (numeric) the minimum median time past of a block at which the bit gains its meaning\n" + " \"timeout\" : xx, (numeric) the median time past of a block at which the deployment is considered failed if not yet locked in\n" + " \"since\" : xx, (numeric) height of the first block to which the status applies\n" + " \"statistics\" : { (json object) numeric statistics about BIP9 signalling for a softfork (only for \"started\" status)\n" + " \"period\" : xx, (numeric) the length in blocks of the BIP9 signalling period \n" + " \"threshold\" : xx, (numeric) the number of blocks with the version bit set required to activate the feature \n" + " \"elapsed\" : xx, (numeric) the number of blocks elapsed since the beginning of the current period \n" + " \"count\" : xx, (numeric) the number of blocks with the version bit set in the current period \n" + " \"possible\" : xx (boolean) returns false if there are not enough blocks left in this period to pass activation threshold \n" + " }\n" + " }\n" + " }\n" + " \"warnings\" : \"...\", (string) any network and blockchain warnings.\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("getblockchaininfo", "") + + HelpExampleRpc("getblockchaininfo", "") + }, + }.Check(request); LOCK(cs_main); @@ -1616,48 +1566,46 @@ struct CompareBlocksByHeight static UniValue getchaintips(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"getchaintips", - "Return information about all known tips in the block tree," - " including the main chain as well as orphaned branches.\n", - { - {"count", RPCArg::Type::NUM, /* default */ "", "only show this much of latest tips"}, - {"branchlen", RPCArg::Type::NUM, /* default */ "", "only show tips that have equal or greater length of branch"}, - }, - RPCResult{ - "[\n" - " {\n" - " \"height\" : xxxx, (numeric) height of the chain tip\n" - " \"hash\" : \"xxxx\", (string) block hash of the tip\n" - " \"difficulty\" : x.xxx, (numeric) The difficulty\n" - " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n" - " \"branchlen\" : 0 (numeric) zero for main chain\n" - " \"forkpoint\" : \"xxxx\", (string) same as \"hash\" for the main chain\n" - " \"status\" : \"active\" (string) \"active\" for the main chain\n" - " },\n" - " {\n" - " \"height\" : xxxx,\n" - " \"hash\" : \"xxxx\",\n" - " \"difficulty\" : x.xxx,\n" - " \"chainwork\" : \"0000...1f3\"\n" - " \"branchlen\" : 1 (numeric) length of branch connecting the tip to the main chain\n" - " \"forkpoint\" : \"xxxx\", (string) block hash of the last common block between this tip and the main chain\n" - " \"status\" : \"xxxx\" (string) status of the chain (active, valid-fork, valid-headers, headers-only, invalid)\n" - " }\n" - "]\n" - "Possible values for status:\n" - "1. \"invalid\" This branch contains at least one invalid block\n" - "2. \"headers-only\" Not all blocks for this branch are available, but the headers are valid\n" - "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" - }, - RPCExamples{ - HelpExampleCli("getchaintips", "") - + HelpExampleRpc("getchaintips", "") - }, - }.ToString()); + RPCHelpMan{"getchaintips", + "Return information about all known tips in the block tree," + " including the main chain as well as orphaned branches.\n", + { + {"count", RPCArg::Type::NUM, /* default */ "", "only show this much of latest tips"}, + {"branchlen", RPCArg::Type::NUM, /* default */ "", "only show tips that have equal or greater length of branch"}, + }, + RPCResult{ + "[\n" + " {\n" + " \"height\" : xxxx, (numeric) height of the chain tip\n" + " \"hash\" : \"xxxx\", (string) block hash of the tip\n" + " \"difficulty\" : x.xxx, (numeric) The difficulty\n" + " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n" + " \"branchlen\" : 0 (numeric) zero for main chain\n" + " \"forkpoint\" : \"xxxx\", (string) same as \"hash\" for the main chain\n" + " \"status\" : \"active\" (string) \"active\" for the main chain\n" + " },\n" + " {\n" + " \"height\" : xxxx,\n" + " \"hash\" : \"xxxx\",\n" + " \"difficulty\" : x.xxx,\n" + " \"chainwork\" : \"0000...1f3\"\n" + " \"branchlen\" : 1 (numeric) length of branch connecting the tip to the main chain\n" + " \"forkpoint\" : \"xxxx\", (string) block hash of the last common block between this tip and the main chain\n" + " \"status\" : \"xxxx\" (string) status of the chain (active, valid-fork, valid-headers, headers-only, invalid)\n" + " }\n" + "]\n" + "Possible values for status:\n" + "1. \"invalid\" This branch contains at least one invalid block\n" + "2. \"headers-only\" Not all blocks for this branch are available, but the headers are valid\n" + "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" + }, + RPCExamples{ + HelpExampleCli("getchaintips", "") + + HelpExampleRpc("getchaintips", "") + }, + }.Check(request); LOCK(cs_main); @@ -1768,49 +1716,45 @@ UniValue MempoolInfoToJSON(const CTxMemPool& pool) 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", - {}, - RPCResult{ - "{\n" - " \"loaded\" : true|false (boolean) True if the mempool is fully loaded\n" - " \"size\" : xxxxx, (numeric) Current tx count\n" - " \"bytes\" : xxxxx, (numeric) Sum of all tx sizes\n" - " \"usage\" : xxxxx, (numeric) Total memory usage for the mempool\n" - " \"maxmempool\" : xxxxx, (numeric) Maximum memory usage for the mempool\n" - " \"mempoolminfee\" : xxxxx (numeric) Minimum fee rate in " + CURRENCY_UNIT + "/kB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee\n" - " \"minrelaytxfee\" : xxxxx (numeric) Current minimum relay fee for transactions\n" - " \"instantsendlocks\" : xxxxx, (numeric) Number of unconfirmed instant send locks\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getmempoolinfo", "") - + HelpExampleRpc("getmempoolinfo", "") - }, - }.ToString()); + RPCHelpMan{"getmempoolinfo", + "\nReturns details on the active state of the TX memory pool.\n", + {}, + RPCResult{ + "{\n" + " \"loaded\" : true|false (boolean) True if the mempool is fully loaded\n" + " \"size\" : xxxxx, (numeric) Current tx count\n" + " \"bytes\" : xxxxx, (numeric) Sum of all tx sizes\n" + " \"usage\" : xxxxx, (numeric) Total memory usage for the mempool\n" + " \"maxmempool\" : xxxxx, (numeric) Maximum memory usage for the mempool\n" + " \"mempoolminfee\" : xxxxx (numeric) Minimum fee rate in " + CURRENCY_UNIT + "/kB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee\n" + " \"minrelaytxfee\" : xxxxx (numeric) Current minimum relay fee for transactions\n" + " \"instantsendlocks\" : xxxxx, (numeric) Number of unconfirmed instant send locks\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("getmempoolinfo", "") + + HelpExampleRpc("getmempoolinfo", "") + }, + }.Check(request); return MempoolInfoToJSON(::mempool); } static UniValue preciousblock(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"preciousblock", - "\nTreats a block as if it were received before others with the same work.\n" - "\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, RPCArg::Optional::NO, "the hash of the block to mark as precious"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - HelpExampleCli("preciousblock", "\"blockhash\"") - + HelpExampleRpc("preciousblock", "\"blockhash\"") - }, - }.ToString()); + RPCHelpMan{"preciousblock", + "\nTreats a block as if it were received before others with the same work.\n" + "\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, RPCArg::Optional::NO, "the hash of the block to mark as precious"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("preciousblock", "\"blockhash\"") + + HelpExampleRpc("preciousblock", "\"blockhash\"") + }, + }.Check(request); std::string strHash = request.params[0].get_str(); uint256 hash(uint256S(strHash)); @@ -1836,19 +1780,17 @@ static UniValue preciousblock(const JSONRPCRequest& request) static UniValue invalidateblock(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"invalidateblock", - "\nPermanently marks a block as invalid, as if it violated a consensus rule.\n", - { - {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as invalid"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - HelpExampleCli("invalidateblock", "\"blockhash\"") - + HelpExampleRpc("invalidateblock", "\"blockhash\"") - }, - }.ToString()); + RPCHelpMan{"invalidateblock", + "\nPermanently marks a block as invalid, as if it violated a consensus rule.\n", + { + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as invalid"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("invalidateblock", "\"blockhash\"") + + HelpExampleRpc("invalidateblock", "\"blockhash\"") + }, + }.Check(request); std::string strHash = request.params[0].get_str(); uint256 hash(uint256S(strHash)); @@ -1877,20 +1819,18 @@ static UniValue invalidateblock(const JSONRPCRequest& request) static UniValue reconsiderblock(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"reconsiderblock", - "\nRemoves invalidity status of a block, its ancestors and its descendants, reconsider them for activation.\n" - "This can be used to undo the effects of invalidateblock.\n", - { - {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to reconsider"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - HelpExampleCli("reconsiderblock", "\"blockhash\"") - + HelpExampleRpc("reconsiderblock", "\"blockhash\"") - }, - }.ToString()); + RPCHelpMan{"reconsiderblock", + "\nRemoves invalidity status of a block, its ancestors and its descendants, reconsider them for activation.\n" + "This can be used to undo the effects of invalidateblock.\n", + { + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to reconsider"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("reconsiderblock", "\"blockhash\"") + + HelpExampleRpc("reconsiderblock", "\"blockhash\"") + }, + }.Check(request); std::string strHash = request.params[0].get_str(); uint256 hash(uint256S(strHash)); @@ -1917,31 +1857,29 @@ static UniValue reconsiderblock(const JSONRPCRequest& request) static UniValue getchaintxstats(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"getchaintxstats", - "\nCompute statistics about the total number and rate of transactions in the chain.\n", - { - {"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" - " \"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" - " \"window_final_block_hash\" : \"...\", (string) The hash of the final block in the window.\n" - " \"window_final_block_height\" : xxxxx, (numeric) The height of the final block in the window.\n" - " \"window_block_count\" : xxxxx, (numeric) Size of the window in number of blocks.\n" - " \"window_tx_count\" : xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n" - " \"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" - }, - RPCExamples{ - HelpExampleCli("getchaintxstats", "") - + HelpExampleRpc("getchaintxstats", "2016") - }, - }.ToString()); + RPCHelpMan{"getchaintxstats", + "\nCompute statistics about the total number and rate of transactions in the chain.\n", + { + {"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" + " \"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" + " \"window_final_block_hash\" : \"...\", (string) The hash of the final block in the window.\n" + " \"window_final_block_height\" : xxxxx, (numeric) The height of the final block in the window.\n" + " \"window_block_count\" : xxxxx, (numeric) Size of the window in number of blocks.\n" + " \"window_tx_count\" : xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n" + " \"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" + }, + RPCExamples{ + HelpExampleCli("getchaintxstats", "") + + HelpExampleRpc("getchaintxstats", "2016") + }, + }.Check(request); const CBlockIndex* pindex; int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month @@ -2052,7 +1990,7 @@ static constexpr size_t PER_UTXO_OVERHEAD = sizeof(COutPoint) + sizeof(uint32_t) static UniValue getblockstats(const JSONRPCRequest& request) { - const RPCHelpMan help{"getblockstats", + RPCHelpMan{"getblockstats", "\nCompute per block statistics for a given window. All amounts are in duffs.\n" "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", @@ -2106,10 +2044,7 @@ static UniValue getblockstats(const JSONRPCRequest& request) HelpExampleRpc("getblockstats", R"("00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09", ["minfeerate","avgfeerate"])") + HelpExampleRpc("getblockstats", R"(1000, ["minfeerate","avgfeerate"])") }, - }; - if (request.fHelp || !help.IsValidNumArgs(request.params.size())) { - throw std::runtime_error(help.ToString()); - } + }.Check(request); if (g_txindex) { g_txindex->BlockUntilSyncedToCurrentChain(); @@ -2301,39 +2236,37 @@ static UniValue getblockstats(const JSONRPCRequest& request) static UniValue getspecialtxes(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 5) - throw std::runtime_error( - RPCHelpMan{"getspecialtxes", - "Returns an array of special transactions found in the specified block\n" - "\nIf verbosity is 0, returns tx hash for each transaction.\n" - "If verbosity is 1, returns hex-encoded data for each transaction.\n" - "If verbosity is 2, returns an Object with information for each transaction.\n", - { - {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, - {"type", RPCArg::Type::NUM, /* default */ "-1", "Filter special txes by type, -1 means all types"}, - {"count", RPCArg::Type::NUM, /* default */ "10", "The number of transactions to return"}, - {"skip", RPCArg::Type::NUM, /* default */ "0", "The number of transactions to skip"}, - {"verbosity", RPCArg::Type::NUM, /* default */ "0", "0 for hashes, 1 for hex-encoded data, and 2 for json object"}, - }, - RPCResults{ - {"for verbosity = 0", - "[\n" - " \"txid\" : \"xxxx\", (string) The transaction id\n" - "]\n" - }, {"for verbosity = 1", - "[\n" - " \"data\", (string) A string that is serialized, hex-encoded data for the transaction\n" - "]\n" - }, {"for verbosity = 2", - "[ (array of Objects) The transactions in the format of the getrawtransaction RPC.\n" - " ...,\n" - "]\n" - }}, - RPCExamples{ - HelpExampleCli("getspecialtxes", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"") - + HelpExampleRpc("getspecialtxes", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"") - }, - }.ToString()); + RPCHelpMan{"getspecialtxes", + "Returns an array of special transactions found in the specified block\n" + "\nIf verbosity is 0, returns tx hash for each transaction.\n" + "If verbosity is 1, returns hex-encoded data for each transaction.\n" + "If verbosity is 2, returns an Object with information for each transaction.\n", + { + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, + {"type", RPCArg::Type::NUM, /* default */ "-1", "Filter special txes by type, -1 means all types"}, + {"count", RPCArg::Type::NUM, /* default */ "10", "The number of transactions to return"}, + {"skip", RPCArg::Type::NUM, /* default */ "0", "The number of transactions to skip"}, + {"verbosity", RPCArg::Type::NUM, /* default */ "0", "0 for hashes, 1 for hex-encoded data, and 2 for json object"}, + }, + RPCResults{ + {"for verbosity = 0", + "[\n" + " \"txid\" : \"xxxx\", (string) The transaction id\n" + "]\n" + }, {"for verbosity = 1", + "[\n" + " \"data\", (string) A string that is serialized, hex-encoded data for the transaction\n" + "]\n" + }, {"for verbosity = 2", + "[ (array of Objects) The transactions in the format of the getrawtransaction RPC.\n" + " ...,\n" + "]\n" + }}, + RPCExamples{ + HelpExampleCli("getspecialtxes", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"") + + HelpExampleRpc("getspecialtxes", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"") + }, + }.Check(request); LOCK(cs_main); @@ -2406,18 +2339,15 @@ static UniValue getspecialtxes(const JSONRPCRequest& request) 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", - {}, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - HelpExampleCli("savemempool", "") - + HelpExampleRpc("savemempool", "") - }, - }.ToString()); - } + RPCHelpMan{"savemempool", + "\nDumps the mempool to disk. It will fail until the previous dump is fully loaded.\n", + {}, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("savemempool", "") + + HelpExampleRpc("savemempool", "") + }, + }.Check(request); if (!::mempool.IsLoaded()) { throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet"); @@ -2492,64 +2422,61 @@ class CoinsViewScanReserver UniValue scantxoutset(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"scantxoutset", - "\nEXPERIMENTAL warning: this call may be removed or changed in future releases.\n" - "\nScans the unspent transaction output set for entries that match certain output descriptors.\n" - "Examples of output descriptors are:\n" - " addr(
) Outputs whose scriptPubKey corresponds to the specified address (does not include P2PK)\n" - " raw() Outputs whose scriptPubKey equals the specified hex scripts\n" - " combo() P2PK and P2PKH outputs for the given pubkey\n" - " pkh() P2PKH outputs for the given pubkey\n" - " sh(multi(,,,...)) P2SH-multisig outputs for the given threshold and pubkeys\n" - "\nIn the above, either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n" - "or more path elements separated by \"/\", and optionally ending in \"/*\" (unhardened), or \"/*'\" or \"/*h\" (hardened) to specify all\n" - "unhardened or hardened child keys.\n" - "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", + RPCHelpMan{"scantxoutset", + "\nEXPERIMENTAL warning: this call may be removed or changed in future releases.\n" + "\nScans the unspent transaction output set for entries that match certain output descriptors.\n" + "Examples of output descriptors are:\n" + " addr(
) Outputs whose scriptPubKey corresponds to the specified address (does not include P2PK)\n" + " raw() Outputs whose scriptPubKey equals the specified hex scripts\n" + " combo() P2PK and P2PKH outputs for the given pubkey\n" + " pkh() P2PKH outputs for the given pubkey\n" + " sh(multi(,,,...)) P2SH-multisig outputs for the given threshold and pubkeys\n" + "\nIn the above, either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n" + "or more path elements separated by \"/\", and optionally ending in \"/*\" (unhardened), or \"/*'\" or \"/*h\" (hardened) to specify all\n" + "unhardened or hardened child keys.\n" + "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, 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, RPCArg::Optional::OMITTED, "Array of scan objects. Required for \"start\" action\n" + " Every scan object is either a string descriptor or an object:", { - {"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, RPCArg::Optional::OMITTED, "Array of scan objects. Required for \"start\" action\n" - " Every scan object is either a string descriptor or an object:", + {"descriptor", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "An output descriptor"}, + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "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, RPCArg::Optional::NO, "An output descriptor"}, - {"range", RPCArg::Type::RANGE, /* default */ "1000", "The range of HD chain indexes to explore (either end or [begin,end])"}, - }, - }, + {"desc", RPCArg::Type::STR, RPCArg::Optional::NO, "An output descriptor"}, + {"range", RPCArg::Type::RANGE, /* default */ "1000", "The range of HD chain indexes to explore (either end or [begin,end])"}, }, - "[scanobjects,...]"}, + }, }, - RPCResult{ - RPCResult::Type::OBJ, "", "", + "[scanobjects,...]"}, + }, + RPCResult{ + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::BOOL, "success", "Whether the scan was completed"}, + {RPCResult::Type::NUM, "txouts", "The number of unspent transaction outputs scanned"}, + {RPCResult::Type::NUM, "height", "The current block height (index)"}, + {RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at the tip of the chain"}, + {RPCResult::Type::ARR, "unspents", "", { - {RPCResult::Type::BOOL, "success", "Whether the scan was completed"}, - {RPCResult::Type::NUM, "txouts", "The number of unspent transaction outputs scanned"}, - {RPCResult::Type::NUM, "height", "The current block height (index)"}, - {RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at the tip of the chain"}, - {RPCResult::Type::ARR, "unspents", "", + {RPCResult::Type::OBJ, "", "", { - {RPCResult::Type::OBJ, "", "", - { - {RPCResult::Type::STR_HEX, "txid", "The transaction id"}, - {RPCResult::Type::NUM, "vout", "The vout value"}, - {RPCResult::Type::STR_HEX, "scriptPubKey", "The script key"}, - {RPCResult::Type::STR, "desc", "A specialized descriptor for the matched scriptPubKey"}, - {RPCResult::Type::STR_AMOUNT, "amount", "The total amount in " + CURRENCY_UNIT + " of the unspent output"}, - {RPCResult::Type::NUM, "height", "Height of the unspent transaction output"}, - }}, + {RPCResult::Type::STR_HEX, "txid", "The transaction id"}, + {RPCResult::Type::NUM, "vout", "The vout value"}, + {RPCResult::Type::STR_HEX, "scriptPubKey", "The script key"}, + {RPCResult::Type::STR, "desc", "A specialized descriptor for the matched scriptPubKey"}, + {RPCResult::Type::STR_AMOUNT, "amount", "The total amount in " + CURRENCY_UNIT + " of the unspent output"}, + {RPCResult::Type::NUM, "height", "Height of the unspent transaction output"}, }}, - {RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount of all found unspent outputs in " + CURRENCY_UNIT}, }}, - RPCExamples{""}, - }.ToString() - ); + {RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount of all found unspent outputs in " + CURRENCY_UNIT}, + }}, + RPCExamples{""}, + }.Check(request); RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR}); @@ -2676,25 +2603,22 @@ UniValue scantxoutset(const JSONRPCRequest& request) static UniValue getblockfilter(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"getblockfilter", - "\nRetrieve a BIP 157 content filter for a particular block.\n", - { - {"blockhash", RPCArg::Type::STR, RPCArg::Optional::NO, "The hash of the block"}, - {"filtertype", RPCArg::Type::STR, /* default */ "basic", "The type name of the filter"}, - }, - RPCResult{ - "{\n" - " \"filter\" : (string) the hex-encoded filter data\n" - " \"header\" : (string) the hex-encoded filter header\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getblockfilter", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" \"basic\"") - }, - }.ToString()); - } + RPCHelpMan{"getblockfilter", + "\nRetrieve a BIP 157 content filter for a particular block.\n", + { + {"blockhash", RPCArg::Type::STR, RPCArg::Optional::NO, "The hash of the block"}, + {"filtertype", RPCArg::Type::STR, /* default */ "basic", "The type name of the filter"}, + }, + RPCResult{ + "{\n" + " \"filter\" : (string) the hex-encoded filter data\n" + " \"header\" : (string) the hex-encoded filter header\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("getblockfilter", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" \"basic\"") + }, + }.Check(request); uint256 block_hash = ParseHashV(request.params[0], "blockhash"); std::string filtertype_name = "basic"; diff --git a/src/rpc/coinjoin.cpp b/src/rpc/coinjoin.cpp index 933afa8df1ed..52118542ff2b 100644 --- a/src/rpc/coinjoin.cpp +++ b/src/rpc/coinjoin.cpp @@ -96,8 +96,6 @@ static UniValue getpoolinfo(const JSONRPCRequest& request) static UniValue getcoinjoininfo(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( RPCHelpMan{"getcoinjoininfo", "Returns an object containing an information about CoinJoin settings and state.\n", {}, @@ -140,7 +138,7 @@ static UniValue getcoinjoininfo(const JSONRPCRequest& request) HelpExampleCli("getcoinjoininfo", "") + HelpExampleRpc("getcoinjoininfo", "") }, - }.ToString()); + }.Check(request); } UniValue obj(UniValue::VOBJ); diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index 12c27cc83c39..6a727bd71b8d 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -1154,8 +1154,6 @@ static UniValue voteraw(const JSONRPCRequest& request) static UniValue getgovernanceinfo(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error( RPCHelpMan{"getgovernanceinfo", "Returns an object containing governance parameters.\n", {}, @@ -1172,7 +1170,7 @@ static UniValue getgovernanceinfo(const JSONRPCRequest& request) HelpExampleCli("getgovernanceinfo", "") + HelpExampleRpc("getgovernanceinfo", "") }, - }.ToString()); + }.Check(request); } int nLastSuperblock = 0, nNextSuperblock = 0; @@ -1194,8 +1192,6 @@ static UniValue getgovernanceinfo(const JSONRPCRequest& request) static UniValue getsuperblockbudget(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( RPCHelpMan{"getsuperblockbudget", "\nReturns the absolute maximum sum of superblock payments allowed.\n", { @@ -1208,7 +1204,7 @@ static UniValue getsuperblockbudget(const JSONRPCRequest& request) HelpExampleCli("getsuperblockbudget", "1000") + HelpExampleRpc("getsuperblockbudget", "1000") }, - }.ToString()); + }.Check(request); } int nBlockHeight = request.params[0].get_int(); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index d22adeb0d123..8f174aaff12d 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -85,23 +85,21 @@ static UniValue GetNetworkHashPS(int lookup, int height) { static UniValue getnetworkhashps(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"getnetworkhashps", - "\nReturns the estimated network hashes per second based on the last n blocks.\n" - "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, /* 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{ - RPCResult::Type::NUM, "", "Hashes per second estimated"}, - RPCExamples{ - HelpExampleCli("getnetworkhashps", "") - + HelpExampleRpc("getnetworkhashps", "") - }, - }.ToString()); + RPCHelpMan{"getnetworkhashps", + "\nReturns the estimated network hashes per second based on the last n blocks.\n" + "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, /* 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{ + RPCResult::Type::NUM, "", "Hashes per second estimated"}, + RPCExamples{ + HelpExampleCli("getnetworkhashps", "") + + HelpExampleRpc("getnetworkhashps", "") + }, + }.Check(request); 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); @@ -246,27 +244,24 @@ static UniValue generatetodescriptor(const JSONRPCRequest& request) static UniValue generatetoaddress(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) - throw std::runtime_error( - RPCHelpMan{"generatetoaddress", - "\nMine blocks immediately to a specified address (before the RPC call returns)\n", - { - {"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{ - RPCResult::Type::ARR, "", "hashes of blocks generated", - { - {RPCResult::Type::STR_HEX, "", "blockhash"}, - }}, - RPCExamples{ - "\nGenerate 11 blocks to myaddress\n" - + HelpExampleCli("generatetoaddress", "11 \"myaddress\"") - + "If you are running the Dash Core wallet, you can get a new address to send the newly generated coins to with:\n" - + HelpExampleCli("getnewaddress", "") - }, - }.ToString()); + RPCHelpMan{"generatetoaddress", + "\nMine blocks immediately to a specified address (before the RPC call returns)\n", + { + {"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{ + RPCResult::Type::ARR, "", "hashes of blocks generated", + { + {RPCResult::Type::STR_HEX, "", "blockhash"}, + }}, + RPCExamples{ + "\nGenerate 11 blocks to myaddress\n" + + HelpExampleCli("generatetoaddress", "11 \"myaddress\"") + + "If you are running the Dash Core wallet, you can get a new address to send the newly generated coins to with:\n" + + HelpExampleCli("getnewaddress", "")}, + }.Check(request); int nGenerate = request.params[0].get_int(); uint64_t nMaxTries = 1000000; @@ -409,29 +404,26 @@ static UniValue generateblock(const JSONRPCRequest& request) 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.", - {}, - RPCResult{ - "{\n" - " \"blocks\" : nnn, (numeric) The current block\n" - " \"currentblocksize\" : nnn, (numeric, optional) The block size of the last assembled block (only present if a block was ever assembled)\n" - " \"currentblocktx\" : nnn, (numeric, optional) The number of block transactions of the last assembled block (only present if a block was ever assembled)\n" - " \"difficulty\" : xxx.xxxxx (numeric) The current difficulty\n" - " \"networkhashps\" : nnn, (numeric) The network hashes per second\n" - " \"pooledtx\" : n (numeric) The size of the mempool\n" - " \"chain\" : \"xxxx\", (string) current network name (main, test, regtest)\n" - " \"warnings\" : \"...\" (string) any network and blockchain warnings\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getmininginfo", "") - + HelpExampleRpc("getmininginfo", "") - }, - }.ToString()); - } + RPCHelpMan{"getmininginfo", + "\nReturns a json object containing mining-related information.", + {}, + RPCResult{ + "{\n" + " \"blocks\" : nnn, (numeric) The current block\n" + " \"currentblocksize\" : nnn, (numeric, optional) The block size of the last assembled block (only present if a block was ever assembled)\n" + " \"currentblocktx\" : nnn, (numeric, optional) The number of block transactions of the last assembled block (only present if a block was ever assembled)\n" + " \"difficulty\" : xxx.xxxxx (numeric) The current difficulty\n" + " \"networkhashps\" : nnn, (numeric) The network hashes per second\n" + " \"pooledtx\" : n (numeric) The size of the mempool\n" + " \"chain\" : \"xxxx\", (string) current network name (main, test, regtest)\n" + " \"warnings\" : \"...\" (string) any network and blockchain warnings\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("getmininginfo", "") + + HelpExampleRpc("getmininginfo", "") + }, + }.Check(request); LOCK(cs_main); @@ -451,24 +443,22 @@ static UniValue getmininginfo(const JSONRPCRequest& request) // NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts static UniValue prioritisetransaction(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 2) - throw std::runtime_error( - RPCHelpMan{"prioritisetransaction", - "Accepts the transaction into mined blocks at a higher (or lower) priority\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."}, - }, - RPCResult{ - RPCResult::Type::BOOL, "", "Returns true"}, - RPCExamples{ - HelpExampleCli("prioritisetransaction", "\"txid\" 10000") - + HelpExampleRpc("prioritisetransaction", "\"txid\", 10000") - }, - }.ToString()); + RPCHelpMan{"prioritisetransaction", + "Accepts the transaction into mined blocks at a higher (or lower) priority\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."}, + }, + RPCResult{ + RPCResult::Type::BOOL, "", "Returns true"}, + RPCExamples{ + HelpExampleCli("prioritisetransaction", "\"txid\" 10000") + + HelpExampleRpc("prioritisetransaction", "\"txid\", 10000") + }, + }.Check(request); LOCK(cs_main); @@ -510,99 +500,97 @@ static std::string gbt_vb_name(const Consensus::DeploymentPos pos) { static UniValue getblocktemplate(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 1) - throw std::runtime_error( - RPCHelpMan{"getblocktemplate", - "\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n" - "It returns data needed to construct a block to work on.\n" - "For full specification, see BIPs 22, 23, and 9:\n" - " https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki\n" - " https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki\n" - " https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n", + RPCHelpMan{"getblocktemplate", + "\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n" + "It returns data needed to construct a block to work on.\n" + "For full specification, see BIPs 22, 23, and 9:\n" + " https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki\n" + " 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, /* 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, /* 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", { - {"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, RPCArg::Optional::OMITTED, "client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'"}, - }, - }, - {"rules", RPCArg::Type::ARR, /* default_val */ "", "A list of strings", - { - {"support", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported softfork deployment"}, - }, - }, + {"support", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'"}, + }, + }, + {"rules", RPCArg::Type::ARR, /* default_val */ "", "A list of strings", + { + {"support", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported softfork deployment"}, + }, }, - "\"template_request\""}, - }, - RPCResult{ - "{\n" - " \"capabilities\" : [ \"capability\", ... ], (array of strings) specific client side supported features\n" - " \"version\" : n, (numeric) The preferred block version\n" - " \"rules\" : [ \"rulename\", ... ], (array of strings) specific block rules that are to be enforced\n" - " \"vbavailable\" : { (json object) set of pending, supported versionbit (BIP 9) softfork deployments\n" - " \"rulename\" : bitnumber (numeric) identifies the bit number as indicating acceptance and readiness for the named softfork rule\n" - " ,...\n" - " },\n" - " \"vbrequired\" : n, (numeric) bit mask of versionbits the server requires set in submissions\n" - " \"previousblockhash\" : \"xxxx\", (string) The hash of current highest block\n" - " \"transactions\" : [ (json array) contents of non-coinbase transactions that should be included in the next block\n" - " {\n" - " \"data\" : \"xxxx\", (string) transaction data encoded in hexadecimal (byte-for-byte)\n" - " \"hash\" : \"xxxx\", (string) hash/id encoded in little-endian hexadecimal\n" - " \"depends\" : [ (json array) array of numbers \n" - " n (numeric) transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is\n" - " ,...\n" - " ],\n" - " \"fee\" : n, (numeric) difference in value between transaction inputs and outputs (in duffs); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one\n" - " \"sigops\" : n, (numeric) total number of SigOps, as counted for purposes of block limits; if key is not present, sigop count is unknown and clients MUST NOT assume there aren't any\n" - " }\n" - " ,...\n" - " ],\n" - " \"coinbaseaux\" : { ... }, (json object) data that should be included in the coinbase's scriptSig content\n" - " \"coinbasevalue\" : n, (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in duffs)\n" - " \"coinbasetxn\" : { ... }, (json object) information for coinbase transaction\n" - " \"target\" : \"xxxx\", (string) The hash target\n" - " \"mintime\" : xxx, (numeric) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT)\n" - " \"mutable\" : [ (array of string) list of ways the block template may be changed \n" - " \"value\" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'\n" - " ,...\n" - " ],\n" - " \"noncerange\" : \"00000000ffffffff\",(string) A range of valid nonces\n" - " \"sigoplimit\" : n, (numeric) limit of sigops in blocks\n" - " \"sizelimit\" : n, (numeric) limit of block size\n" - " \"curtime\" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)\n" - " \"bits\" : \"xxxxxxxx\", (string) compressed target of next block\n" - " \"previousbits\" : \"xxxxxxxx\", (string) compressed target of current highest block\n" - " \"height\" : n (numeric) The height of the next block\n" - " \"masternode\" : [ (json array) required masternode payments that must be included in the next block\n" - " {\n" - " \"payee\" : \"xxxx\", (string) payee address\n" - " \"script\" : \"xxxx\", (string) payee scriptPubKey\n" - " \"amount\" : n (numeric) required amount to pay\n" - " }\n" - " },\n" - " \"masternode_payments_started\" : true|false, (boolean) true, if masternode payments started\n" - " \"masternode_payments_enforced\" : true|false, (boolean) true, if masternode payments are enforced\n" - " \"superblock\" : [ (json array) required superblock payees that must be included in the next block\n" - " {\n" - " \"payee\" : \"xxxx\", (string) payee address\n" - " \"script\" : \"xxxx\", (string) payee scriptPubKey\n" - " \"amount\" : n (numeric) required amount to pay\n" - " }\n" - " ,...\n" - " ],\n" - " \"superblocks_started\" : true|false, (boolean) true, if superblock payments started\n" - " \"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" - }, - RPCExamples{ - HelpExampleCli("getblocktemplate", "") - + HelpExampleRpc("getblocktemplate", "") }, - }.ToString()); + "\"template_request\""}, + }, + RPCResult{ + "{\n" + " \"capabilities\" : [ \"capability\", ... ], (array of strings) specific client side supported features\n" + " \"version\" : n, (numeric) The preferred block version\n" + " \"rules\" : [ \"rulename\", ... ], (array of strings) specific block rules that are to be enforced\n" + " \"vbavailable\" : { (json object) set of pending, supported versionbit (BIP 9) softfork deployments\n" + " \"rulename\" : bitnumber (numeric) identifies the bit number as indicating acceptance and readiness for the named softfork rule\n" + " ,...\n" + " },\n" + " \"vbrequired\" : n, (numeric) bit mask of versionbits the server requires set in submissions\n" + " \"previousblockhash\" : \"xxxx\", (string) The hash of current highest block\n" + " \"transactions\" : [ (json array) contents of non-coinbase transactions that should be included in the next block\n" + " {\n" + " \"data\" : \"xxxx\", (string) transaction data encoded in hexadecimal (byte-for-byte)\n" + " \"hash\" : \"xxxx\", (string) hash/id encoded in little-endian hexadecimal\n" + " \"depends\" : [ (json array) array of numbers \n" + " n (numeric) transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is\n" + " ,...\n" + " ],\n" + " \"fee\" : n, (numeric) difference in value between transaction inputs and outputs (in duffs); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one\n" + " \"sigops\" : n, (numeric) total number of SigOps, as counted for purposes of block limits; if key is not present, sigop count is unknown and clients MUST NOT assume there aren't any\n" + " }\n" + " ,...\n" + " ],\n" + " \"coinbaseaux\" : { ... }, (json object) data that should be included in the coinbase's scriptSig content\n" + " \"coinbasevalue\" : n, (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in duffs)\n" + " \"coinbasetxn\" : { ... }, (json object) information for coinbase transaction\n" + " \"target\" : \"xxxx\", (string) The hash target\n" + " \"mintime\" : xxx, (numeric) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT)\n" + " \"mutable\" : [ (array of string) list of ways the block template may be changed \n" + " \"value\" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'\n" + " ,...\n" + " ],\n" + " \"noncerange\" : \"00000000ffffffff\",(string) A range of valid nonces\n" + " \"sigoplimit\" : n, (numeric) limit of sigops in blocks\n" + " \"sizelimit\" : n, (numeric) limit of block size\n" + " \"curtime\" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)\n" + " \"bits\" : \"xxxxxxxx\", (string) compressed target of next block\n" + " \"previousbits\" : \"xxxxxxxx\", (string) compressed target of current highest block\n" + " \"height\" : n (numeric) The height of the next block\n" + " \"masternode\" : [ (json array) required masternode payments that must be included in the next block\n" + " {\n" + " \"payee\" : \"xxxx\", (string) payee address\n" + " \"script\" : \"xxxx\", (string) payee scriptPubKey\n" + " \"amount\" : n (numeric) required amount to pay\n" + " }\n" + " },\n" + " \"masternode_payments_started\" : true|false, (boolean) true, if masternode payments started\n" + " \"masternode_payments_enforced\" : true|false, (boolean) true, if masternode payments are enforced\n" + " \"superblock\" : [ (json array) required superblock payees that must be included in the next block\n" + " {\n" + " \"payee\" : \"xxxx\", (string) payee address\n" + " \"script\" : \"xxxx\", (string) payee scriptPubKey\n" + " \"amount\" : n (numeric) required amount to pay\n" + " }\n" + " ,...\n" + " ],\n" + " \"superblocks_started\" : true|false, (boolean) true, if superblock payments started\n" + " \"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" + }, + RPCExamples{ + HelpExampleCli("getblocktemplate", "") + + HelpExampleRpc("getblocktemplate", "") + }, + }.Check(request); LOCK(cs_main); @@ -941,22 +929,19 @@ class submitblock_StateCatcher : public CValidationInterface static UniValue submitblock(const JSONRPCRequest& request) { // We allow 2 arguments for compliance with BIP22. Argument 2 is ignored. - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"submitblock", - "\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, 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."}, - }, - RPCResult{RPCResult::Type::NONE, "", "Returns JSON Null when valid, a string according to BIP22 otherwise"}, - RPCExamples{ - HelpExampleCli("submitblock", "\"mydata\"") - + HelpExampleRpc("submitblock", "\"mydata\"") - }, - }.ToString()); - } + RPCHelpMan{"submitblock", + "\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, 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."}, + }, + RPCResult{RPCResult::Type::NONE, "", "Returns JSON Null when valid, a string according to BIP22 otherwise"}, + RPCExamples{ + HelpExampleCli("submitblock", "\"mydata\"") + + HelpExampleRpc("submitblock", "\"mydata\"") + }, + }.Check(request); std::shared_ptr blockptr = std::make_shared(); CBlock& block = *blockptr; @@ -998,22 +983,19 @@ static UniValue submitblock(const JSONRPCRequest& request) static UniValue submitheader(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"submitheader", - "\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, RPCArg::Optional::NO, "the hex-encoded block header data"}, - }, - RPCResult{ - RPCResult::Type::NONE, "", "None"}, - RPCExamples{ - HelpExampleCli("submitheader", "\"aabbcc\"") + - HelpExampleRpc("submitheader", "\"aabbcc\"") - }, - }.ToString()); - } + RPCHelpMan{"submitheader", + "\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, RPCArg::Optional::NO, "the hex-encoded block header data"}, + }, + RPCResult{ + RPCResult::Type::NONE, "", "None"}, + RPCExamples{ + HelpExampleCli("submitheader", "\"aabbcc\"") + + HelpExampleRpc("submitheader", "\"aabbcc\"") + }, + }.Check(request); CBlockHeader h; if (!DecodeHexBlockHeader(h, request.params[0].get_str())) { @@ -1037,42 +1019,40 @@ static UniValue submitheader(const JSONRPCRequest& request) static UniValue estimatesmartfee(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"estimatesmartfee", - "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n" - "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, 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" - " target, but is not as responsive to short term drops in the\n" - " prevailing fee market. Must be one of:\n" - " \"UNSET\"\n" - " \"ECONOMICAL\"\n" - " \"CONSERVATIVE\""}, - }, - RPCResult{ - RPCResult::Type::OBJ, "", "", + RPCHelpMan{"estimatesmartfee", + "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n" + "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, 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" + " target, but is not as responsive to short term drops in the\n" + " prevailing fee market. Must be one of:\n" + " \"UNSET\"\n" + " \"ECONOMICAL\"\n" + " \"CONSERVATIVE\""}, + }, + RPCResult{ + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::NUM, "feerate", /* optional */ true, "estimate fee rate in " + CURRENCY_UNIT + "/kB (only present if no errors were encountered)"}, + {RPCResult::Type::ARR, "errors", "Errors encountered during processing", { - {RPCResult::Type::NUM, "feerate", /* optional */ true, "estimate fee rate in " + CURRENCY_UNIT + "/kB (only present if no errors were encountered)"}, - {RPCResult::Type::ARR, "errors", "Errors encountered during processing", - { - {RPCResult::Type::STR, "", "error"}, - }}, - {RPCResult::Type::NUM, "blocks", "block number where estimate was found\n" - "The request target will be clamped between 2 and the highest target\n" - "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."}, + {RPCResult::Type::STR, "", "error"}, }}, - RPCExamples{ - HelpExampleCli("estimatesmartfee", "6") - }, - }.ToString()); + {RPCResult::Type::NUM, "blocks", "block number where estimate was found\n" + "The request target will be clamped between 2 and the highest target\n" + "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."}, + }}, + RPCExamples{ + HelpExampleCli("estimatesmartfee", "6") + }, + }.Check(request); RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR}); RPCTypeCheckArgument(request.params[0], UniValue::VNUM); @@ -1103,48 +1083,46 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request) static UniValue estimaterawfee(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"estimaterawfee", - "\nWARNING: This interface is unstable and may disappear or change!\n" - "\nWARNING: This is an advanced API call that is tightly coupled to the specific\n" - " implementation of fee estimation. The parameters it can be called with\n" - " and the results it returns will change if the internal implementation changes.\n" - "\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, 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."}, - }, - 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" - " \"decay\" : x.x, (numeric) exponential decay (per block) for historical moving average of confirmation data\n" - " \"scale\" : x, (numeric) The resolution of confirmation targets at this time horizon\n" - " \"pass\" : { (json object, optional) information about the lowest range of feerates to succeed in meeting the threshold\n" - " \"startrange\" : x.x, (numeric) start of feerate range\n" - " \"endrange\" : x.x, (numeric) end of feerate range\n" - " \"withintarget\" : x.x, (numeric) number of txs over history horizon in the feerate range that were confirmed within target\n" - " \"totalconfirmed\" : x.x, (numeric) number of txs over history horizon in the feerate range that were confirmed at any point\n" - " \"inmempool\" : x.x, (numeric) current number of txs in mempool in the feerate range unconfirmed for at least target blocks\n" - " \"leftmempool\" : x.x, (numeric) number of txs over history horizon in the feerate range that left mempool unconfirmed after target\n" - " },\n" - " \"fail\" : { ... }, (json object, optional) information about the highest range of feerates to fail to meet the threshold\n" - " \"errors\" : [ str... ] (json array of strings, optional) Errors encountered during processing\n" - " },\n" - " \"medium\" : { ... }, (json object, optional) estimate for medium time horizon\n" - " \"long\" : { ... } (json object) estimate for long time horizon\n" - "}\n" - "\n" - "Results are returned for any horizon which tracks blocks up to the confirmation target.\n" - }, - RPCExamples{ - HelpExampleCli("estimaterawfee", "6 0.9") - }, - }.ToString()); + RPCHelpMan{"estimaterawfee", + "\nWARNING: This interface is unstable and may disappear or change!\n" + "\nWARNING: This is an advanced API call that is tightly coupled to the specific\n" + " implementation of fee estimation. The parameters it can be called with\n" + " and the results it returns will change if the internal implementation changes.\n" + "\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, 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."}, + }, + 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" + " \"decay\" : x.x, (numeric) exponential decay (per block) for historical moving average of confirmation data\n" + " \"scale\" : x, (numeric) The resolution of confirmation targets at this time horizon\n" + " \"pass\" : { (json object, optional) information about the lowest range of feerates to succeed in meeting the threshold\n" + " \"startrange\" : x.x, (numeric) start of feerate range\n" + " \"endrange\" : x.x, (numeric) end of feerate range\n" + " \"withintarget\" : x.x, (numeric) number of txs over history horizon in the feerate range that were confirmed within target\n" + " \"totalconfirmed\" : x.x, (numeric) number of txs over history horizon in the feerate range that were confirmed at any point\n" + " \"inmempool\" : x.x, (numeric) current number of txs in mempool in the feerate range unconfirmed for at least target blocks\n" + " \"leftmempool\" : x.x, (numeric) number of txs over history horizon in the feerate range that left mempool unconfirmed after target\n" + " },\n" + " \"fail\" : { ... }, (json object, optional) information about the highest range of feerates to fail to meet the threshold\n" + " \"errors\" : [ str... ] (json array of strings, optional) Errors encountered during processing\n" + " },\n" + " \"medium\" : { ... }, (json object, optional) estimate for medium time horizon\n" + " \"long\" : { ... } (json object) estimate for long time horizon\n" + "}\n" + "\n" + "Results are returned for any horizon which tracks blocks up to the confirmation target.\n" + }, + RPCExamples{ + HelpExampleCli("estimaterawfee", "6 0.9") + }, + }.Check(request); 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 28a6a38ad7cd..3df88005cf3f 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -38,27 +38,25 @@ static UniValue debug(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"debug", - "Change debug category on the fly. Specify single category or use '+' to specify many.\n" - "The valid debug categories are: " + ListLogCategories() + ".\n" - "libevent logging is configured on startup and cannot be modified by this RPC during runtime.\n" - "There are also a few meta-categories:\n" - " - \"all\", \"1\" and \"\" activate all categories at once;\n" - " - \"dash\" activates all Dash-specific categories at once;\n" - " - \"none\" (or \"0\") deactivates all categories at once.\n" - "Note: If specified category doesn't match any of the above, no error is thrown.\n", - { - {"category", RPCArg::Type::STR, RPCArg::Optional::NO, "The name of the debug category to turn on."}, - }, - RPCResult { - " result (string) \"Debug mode: \" followed by the specified category.\n" - }, - RPCExamples { - HelpExampleCli("debug", "dash") - + HelpExampleRpc("debug", "dash+net") - }}.ToString()); + RPCHelpMan{"debug", + "Change debug category on the fly. Specify single category or use '+' to specify many.\n" + "The valid debug categories are: " + ListLogCategories() + ".\n" + "libevent logging is configured on startup and cannot be modified by this RPC during runtime.\n" + "There are also a few meta-categories:\n" + " - \"all\", \"1\" and \"\" activate all categories at once;\n" + " - \"dash\" activates all Dash-specific categories at once;\n" + " - \"none\" (or \"0\") deactivates all categories at once.\n" + "Note: If specified category doesn't match any of the above, no error is thrown.\n", + { + {"category", RPCArg::Type::STR, RPCArg::Optional::NO, "The name of the debug category to turn on."}, + }, + RPCResult { + " result (string) \"Debug mode: \" followed by the specified category.\n" + }, + RPCExamples { + HelpExampleCli("debug", "dash") + + HelpExampleRpc("debug", "dash+net") + }}.Check(request); std::string strMode = request.params[0].get_str(); LogInstance().DisableCategory(BCLog::ALL); @@ -77,16 +75,14 @@ static UniValue debug(const JSONRPCRequest& request) static UniValue mnsync(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"mnsync", - "Returns the sync status, updates to the next step or resets it entirely.\n", - { - {"mode", RPCArg::Type::STR, RPCArg::Optional::NO, "[status|next|reset]"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"mnsync", + "Returns the sync status, updates to the next step or resets it entirely.\n", + { + {"mode", RPCArg::Type::STR, RPCArg::Optional::NO, "[status|next|reset]"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); std::string strMode = request.params[0].get_str(); @@ -200,26 +196,24 @@ static UniValue spork(const JSONRPCRequest& request) static UniValue validateaddress(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"validateaddress", - "\nReturn information about the given dash address.\n", - { - {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The dash address to validate"}, - }, - 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" - }, - RPCExamples{ - HelpExampleCli("validateaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"") - + HelpExampleRpc("validateaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"") - }, - }.ToString()); + RPCHelpMan{"validateaddress", + "\nReturn information about the given dash address.\n", + { + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The dash address to validate"}, + }, + 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" + }, + RPCExamples{ + HelpExampleCli("validateaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"") + + HelpExampleRpc("validateaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"") + }, + }.Check(request); CTxDestination dest = DecodeDestination(request.params[0].get_str()); bool isValid = IsValidDestination(dest); @@ -242,34 +236,29 @@ static UniValue validateaddress(const JSONRPCRequest& request) static UniValue createmultisig(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 2 || request.params.size() > 2) - { - std::string msg = - RPCHelpMan{"createmultisig", - "\nCreates a multi-signature address with n signature of m keys required.\n" - "It returns a json object with the address and redeemScript.\n", + RPCHelpMan{"createmultisig", + "\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, 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.", { - {"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, RPCArg::Optional::OMITTED, "The hex-encoded public key"}, - }}, - }, - 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" - }, - 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); - } + {"key", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "The hex-encoded public key"}, + }}, + }, + 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" + }, + 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\\\"]\"") + }, + }.Check(request); int required = request.params[0].get_int(); @@ -297,29 +286,26 @@ static UniValue createmultisig(const JSONRPCRequest& request) UniValue getdescriptorinfo(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"getdescriptorinfo", - {"\nAnalyses a descriptor.\n"}, + RPCHelpMan{"getdescriptorinfo", + {"\nAnalyses a descriptor.\n"}, + { + {"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor"}, + }, + RPCResult{ + RPCResult::Type::OBJ, "", "", { - {"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor"}, - }, - RPCResult{ - RPCResult::Type::OBJ, "", "", - { - {RPCResult::Type::STR, "descriptor", "The descriptor in canonical form, without private keys"}, - {RPCResult::Type::STR, "checksum", "The checksum for the input descriptor"}, - {RPCResult::Type::BOOL, "isrange", "Whether the descriptor is ranged"}, - {RPCResult::Type::BOOL, "issolvable", "Whether the descriptor is solvable"}, - {RPCResult::Type::BOOL, "hasprivatekeys", "Whether the input descriptor contained at least one private key"}, - } - }, - RPCExamples{ - "\nAnalyse a descriptor\n" - + HelpExampleCli("getdescriptorinfo", "\"pkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)\"") + {RPCResult::Type::STR, "descriptor", "The descriptor in canonical form, without private keys"}, + {RPCResult::Type::STR, "checksum", "The checksum for the input descriptor"}, + {RPCResult::Type::BOOL, "isrange", "Whether the descriptor is ranged"}, + {RPCResult::Type::BOOL, "issolvable", "Whether the descriptor is solvable"}, + {RPCResult::Type::BOOL, "hasprivatekeys", "Whether the input descriptor contained at least one private key"}, } - }.ToString()); - } + }, + RPCExamples{ + "\nAnalyse a descriptor\n" + + HelpExampleCli("getdescriptorinfo", "\"pkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)\"") + } + }.Check(request); RPCTypeCheck(request.params, {UniValue::VSTR}); @@ -341,33 +327,30 @@ UniValue getdescriptorinfo(const JSONRPCRequest& request) UniValue deriveaddresses(const JSONRPCRequest& request) { - if (request.fHelp || request.params.empty() || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"deriveaddresses", - "\nDerives one or more addresses corresponding to an output descriptor.\n" - "Examples of output descriptors are:\n" - " pkh() P2PKH outputs for the given pubkey\n" - " sh(multi(,,,...)) P2SH-multisig outputs for the given threshold and pubkeys\n" - " raw() Outputs whose scriptPubKey equals the specified hex scripts\n" - "\nIn the above, either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n" - "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n" - "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n", - { - {"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor"}, - {"range", RPCArg::Type::RANGE, RPCArg::Optional::OMITTED_NAMED_ARG, "If a ranged descriptor is used, this specifies the end or the range (in [begin,end] notation) to derive."}, - }, - RPCResult{ - "\"address\" (json array) A json array of the derived addresses\n" - " [\n" - " ...\n" - " ]\n" - }, - RPCExamples{ - "\nFirst three receive addresses\n" - + HelpExampleCli("deriveaddresses", "\"pkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu\" \"[0,2]\"") - } - }.ToString()); - } + RPCHelpMan{"deriveaddresses", + "\nDerives one or more addresses corresponding to an output descriptor.\n" + "Examples of output descriptors are:\n" + " pkh() P2PKH outputs for the given pubkey\n" + " sh(multi(,,,...)) P2SH-multisig outputs for the given threshold and pubkeys\n" + " raw() Outputs whose scriptPubKey equals the specified hex scripts\n" + "\nIn the above, either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n" + "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n" + "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n", + { + {"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor"}, + {"range", RPCArg::Type::RANGE, RPCArg::Optional::OMITTED_NAMED_ARG, "If a ranged descriptor is used, this specifies the end or the range (in [begin,end] notation) to derive."}, + }, + RPCResult{ + "\"address\" (json array) A json array of the derived addresses\n" + " [\n" + " ...\n" + " ]\n" + }, + RPCExamples{ + "\nFirst three receive addresses\n" + + HelpExampleCli("deriveaddresses", "\"pkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu\" \"[0,2]\"") + } + }.Check(request); RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType()}); // Range argument is checked later const std::string desc_str = request.params[0].get_str(); @@ -423,29 +406,27 @@ UniValue deriveaddresses(const JSONRPCRequest& request) static UniValue verifymessage(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 3) - throw std::runtime_error( - RPCHelpMan{"verifymessage", - "\nVerify a signed message\n", - { - {"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{ - RPCResult::Type::BOOL, "", "If the signature is verified or not." - }, - RPCExamples{ - "\nUnlock the wallet for 30 seconds\n" - + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + - "\nCreate the signature\n" - + HelpExampleCli("signmessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"my message\"") + - "\nVerify the signature\n" - + HelpExampleCli("verifymessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"signature\" \"my message\"") + - "\nAs a JSON-RPC call\n" - + HelpExampleRpc("verifymessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", \"signature\", \"my message\"") - }, - }.ToString()); + RPCHelpMan{"verifymessage", + "\nVerify a signed message\n", + { + {"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{ + RPCResult::Type::BOOL, "", "If the signature is verified or not." + }, + RPCExamples{ + "\nUnlock the wallet for 30 seconds\n" + + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + + "\nCreate the signature\n" + + HelpExampleCli("signmessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"my message\"") + + "\nVerify the signature\n" + + HelpExampleCli("verifymessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\" \"signature\" \"my message\"") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("verifymessage", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", \"signature\", \"my message\"") + }, + }.Check(request); LOCK(cs_main); @@ -482,26 +463,24 @@ static UniValue verifymessage(const JSONRPCRequest& request) static UniValue signmessagewithprivkey(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 2) - throw std::runtime_error( - RPCHelpMan{"signmessagewithprivkey", - "\nSign a message with the private key of an address\n", - { - {"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{ - RPCResult::Type::STR, "signature", "The signature of the message encoded in base 64" - }, - 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()); + RPCHelpMan{"signmessagewithprivkey", + "\nSign a message with the private key of an address\n", + { + {"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{ + RPCResult::Type::STR, "signature", "The signature of the message encoded in base 64" + }, + 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\"") + }, + }.Check(request); std::string strPrivkey = request.params[0].get_str(); std::string strMessage = request.params[1].get_str(); @@ -524,18 +503,15 @@ static UniValue signmessagewithprivkey(const JSONRPCRequest& request) static UniValue setmocktime(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"setmocktime", - "\nSet the local time to given timestamp (-regtest only)\n", - { - {"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, "Unix seconds-since-epoch timestamp\n" - " Pass 0 to go back to using the system time."}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{""}, - }.ToString() - ); + RPCHelpMan{"setmocktime", + "\nSet the local time to given timestamp (-regtest only)\n", + { + {"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, "Unix seconds-since-epoch timestamp\n" + " Pass 0 to go back to using the system time."}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{""}, + }.Check(request); if (!Params().MineBlocksOnDemand()) throw std::runtime_error("setmocktime for regression testing (-regtest mode) only"); @@ -555,18 +531,16 @@ static UniValue setmocktime(const JSONRPCRequest& request) static UniValue mnauth(const JSONRPCRequest& request) { - if (request.fHelp || (request.params.size() != 3)) - throw std::runtime_error( - RPCHelpMan{"mnauth", - "\nOverride MNAUTH processing results for the specified node with a user provided data (-regtest only).\n", - { - {"nodeId", RPCArg::Type::NUM, RPCArg::Optional::NO, "Internal peer id of the node the mock data gets added to."}, - {"proTxHash", RPCArg::Type::STR, RPCArg::Optional::NO, "The authenticated proTxHash as hex string."}, - {"publicKey", RPCArg::Type::STR, RPCArg::Optional::NO, "The authenticated public key as hex string."}, - }, - RPCResults{}, - RPCExamples{""}, - }.ToString()); + RPCHelpMan{"mnauth", + "\nOverride MNAUTH processing results for the specified node with a user provided data (-regtest only).\n", + { + {"nodeId", RPCArg::Type::NUM, RPCArg::Optional::NO, "Internal peer id of the node the mock data gets added to."}, + {"proTxHash", RPCArg::Type::STR, RPCArg::Optional::NO, "The authenticated proTxHash as hex string."}, + {"publicKey", RPCArg::Type::STR, RPCArg::Optional::NO, "The authenticated public key as hex string."}, + }, + RPCResults{}, + RPCExamples{""}, + }.Check(request); if (!Params().MineBlocksOnDemand()) throw std::runtime_error("mnauth for regression testing (-regtest mode) only"); @@ -663,35 +637,33 @@ static bool timestampSort(std::pair > addresses; @@ -735,34 +707,32 @@ static UniValue getaddressmempool(const JSONRPCRequest& request) static UniValue getaddressutxos(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"getaddressutxos", - "\nReturns all unspent outputs for an address (requires addressindex to be enabled).\n", + RPCHelpMan{"getaddressutxos", + "\nReturns all unspent outputs for an address (requires addressindex to be enabled).\n", + { + {"addresses", RPCArg::Type::ARR, /* default */ "", "", { - {"addresses", RPCArg::Type::ARR, /* default */ "", "", - { - {"address", RPCArg::Type::STR, /* default */ "", "The base58check encoded address"}, - }, - }, - }, - RPCResult{ - "[\n" - " {\n" - " \"address\" (string) The address base58check encoded\n" - " \"txid\" (string) The output txid\n" - " \"outputIndex\" (number) The output index\n" - " \"script\" (string) The script hex-encoded\n" - " \"satoshis\" (number) The number of duffs of the output\n" - " \"height\" (number) The block height\n" - " }\n" - "]\n" - }, - RPCExamples{ - HelpExampleCli("getaddressutxos", "'{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}'") - + HelpExampleRpc("getaddressutxos", "{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}") + {"address", RPCArg::Type::STR, /* default */ "", "The base58check encoded address"}, }, - }.ToString()); + }, + }, + RPCResult{ + "[\n" + " {\n" + " \"address\" (string) The address base58check encoded\n" + " \"txid\" (string) The output txid\n" + " \"outputIndex\" (number) The output index\n" + " \"script\" (string) The script hex-encoded\n" + " \"satoshis\" (number) The number of duffs of the output\n" + " \"height\" (number) The block height\n" + " }\n" + "]\n" + }, + RPCExamples{ + HelpExampleCli("getaddressutxos", "'{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}'") + + HelpExampleRpc("getaddressutxos", "{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}") + }, + }.Check(request); std::vector > addresses; @@ -803,34 +773,32 @@ static UniValue getaddressutxos(const JSONRPCRequest& request) static UniValue getaddressdeltas(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1 || !request.params[0].isObject()) - throw std::runtime_error( - RPCHelpMan{"getaddressdeltas", - "\nReturns all changes for an address (requires addressindex to be enabled).\n", + RPCHelpMan{"getaddressdeltas", + "\nReturns all changes for an address (requires addressindex to be enabled).\n", + { + {"addresses", RPCArg::Type::ARR, /* default */ "", "", { - {"addresses", RPCArg::Type::ARR, /* default */ "", "", - { - {"address", RPCArg::Type::STR, /* default */ "", "The base58check encoded address"}, - }, - }, - }, - RPCResult{ - "[\n" - " {\n" - " \"satoshis\" (number) The difference of duffs\n" - " \"txid\" (string) The related txid\n" - " \"index\" (number) The related input or output index\n" - " \"blockindex\" (number) The related block index\n" - " \"height\" (number) The block height\n" - " \"address\" (string) The base58check encoded address\n" - " }\n" - "]\n" + {"address", RPCArg::Type::STR, /* default */ "", "The base58check encoded address"}, }, - RPCExamples{ - HelpExampleCli("getaddressdeltas", "'{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}'") - + HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}") - }, - }.ToString()); + }, + }, + RPCResult{ + "[\n" + " {\n" + " \"satoshis\" (number) The difference of duffs\n" + " \"txid\" (string) The related txid\n" + " \"index\" (number) The related input or output index\n" + " \"blockindex\" (number) The related block index\n" + " \"height\" (number) The block height\n" + " \"address\" (string) The base58check encoded address\n" + " }\n" + "]\n" + }, + RPCExamples{ + HelpExampleCli("getaddressdeltas", "'{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}'") + + HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}") + }, + }.Check(request); UniValue startValue = find_value(request.params[0].get_obj(), "start"); @@ -890,30 +858,28 @@ static UniValue getaddressdeltas(const JSONRPCRequest& request) static UniValue getaddressbalance(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"getaddressbalance", - "\nReturns the balance for an address(es) (requires addressindex to be enabled).\n", + RPCHelpMan{"getaddressbalance", + "\nReturns the balance for an address(es) (requires addressindex to be enabled).\n", + { + {"addresses", RPCArg::Type::ARR, /* default */ "", "", { - {"addresses", RPCArg::Type::ARR, /* default */ "", "", - { - {"address", RPCArg::Type::STR, /* default */ "", "The base58check encoded address"}, - }, - }, + {"address", RPCArg::Type::STR, /* default */ "", "The base58check encoded address"}, }, - RPCResult{ - "{\n" - " \"balance\" : xxxxx, (numeric) The current total balance in duffs\n" - " \"balance_immature\" : xxxxx, (numeric) The current immature balance in duffs\n" - " \"balance_spendable\" : xxxxx, (numeric) The current spendable balance in duffs\n" - " \"received\" : xxxxx (numeric) The total number of duffs received (including change)\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getaddressbalance", "'{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}'") - + HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}") - }, - }.ToString()); + }, + }, + RPCResult{ + "{\n" + " \"balance\" : xxxxx, (numeric) The current total balance in duffs\n" + " \"balance_immature\" : xxxxx, (numeric) The current immature balance in duffs\n" + " \"balance_spendable\" : xxxxx, (numeric) The current spendable balance in duffs\n" + " \"received\" : xxxxx (numeric) The total number of duffs received (including change)\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("getaddressbalance", "'{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}'") + + HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}") + }, + }.Check(request); std::vector > addresses; @@ -960,28 +926,26 @@ static UniValue getaddressbalance(const JSONRPCRequest& request) static UniValue getaddresstxids(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"getaddresstxids", - "\nReturns the txids for an address(es) (requires addressindex to be enabled).\n", + RPCHelpMan{"getaddresstxids", + "\nReturns the txids for an address(es) (requires addressindex to be enabled).\n", + { + {"addresses", RPCArg::Type::ARR, /* default */ "", "", { - {"addresses", RPCArg::Type::ARR, /* default */ "", "", - { - {"address", RPCArg::Type::STR, /* default */ "", "The base58check encoded address"}, - }, - }, - }, - RPCResult{ - "[\n" - " \"transactionid\" (string) The transaction id\n" - " ,...\n" - "]\n" - }, - RPCExamples{ - HelpExampleCli("getaddresstxids", "'{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}'") - + HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}") + {"address", RPCArg::Type::STR, /* default */ "", "The base58check encoded address"}, }, - }.ToString()); + }, + }, + RPCResult{ + "[\n" + " \"transactionid\" (string) The transaction id\n" + " ,...\n" + "]\n" + }, + RPCExamples{ + HelpExampleCli("getaddresstxids", "'{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}'") + + HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\"]}") + }, + }.Check(request); std::vector > addresses; @@ -1042,30 +1006,28 @@ static UniValue getaddresstxids(const JSONRPCRequest& request) static UniValue getspentinfo(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1 || !request.params[0].isObject()) - throw std::runtime_error( - RPCHelpMan{"getspentinfo", - "\nReturns the txid and index where an output is spent.\n", + RPCHelpMan{"getspentinfo", + "\nReturns the txid and index where an output is spent.\n", + { + {"request", RPCArg::Type::OBJ, /* default */ "", "", { - {"request", RPCArg::Type::OBJ, /* default */ "", "", - { - {"txid", RPCArg::Type::STR_HEX, /* default */ "", "The hex string of the txid"}, - {"index", RPCArg::Type::NUM, /* default */ "", "The start block height"}, - }, - }, + {"txid", RPCArg::Type::STR_HEX, /* default */ "", "The hex string of the txid"}, + {"index", RPCArg::Type::NUM, /* default */ "", "The start block height"}, }, - RPCResult{ - "{\n" - " \"txid\" (string) The transaction id\n" - " \"index\" (number) The spending input index\n" - " ,...\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getspentinfo", "'{\"txid\": \"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9\", \"index\": 0}'") - + HelpExampleRpc("getspentinfo", "{\"txid\": \"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9\", \"index\": 0}") - }, - }.ToString()); + }, + }, + RPCResult{ + "{\n" + " \"txid\" (string) The transaction id\n" + " \"index\" (number) The spending input index\n" + " ,...\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("getspentinfo", "'{\"txid\": \"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9\", \"index\": 0}'") + + HelpExampleRpc("getspentinfo", "{\"txid\": \"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9\", \"index\": 0}") + }, + }.Check(request); UniValue txidValue = find_value(request.params[0].get_obj(), "txid"); UniValue indexValue = find_value(request.params[0].get_obj(), "index"); @@ -1161,39 +1123,37 @@ static UniValue getmemoryinfo(const JSONRPCRequest& request) /* Please, avoid using the word "pool" here in the RPC interface or help, * as users will undoubtedly confuse it with the other "memory pool" */ - if (request.fHelp || request.params.size() > 1) - throw std::runtime_error( - RPCHelpMan{"getmemoryinfo", - "Returns an object containing information about memory usage.\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+)."}, - }, + RPCHelpMan{"getmemoryinfo", + "Returns an object containing information about memory usage.\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+)."}, + }, + { + RPCResult{"mode \"stats\"", + RPCResult::Type::OBJ, "", "", { - RPCResult{"mode \"stats\"", - RPCResult::Type::OBJ, "", "", - { - {RPCResult::Type::OBJ, "locked", "Information about locked memory manager", - { - {RPCResult::Type::NUM, "used", "Number of bytes used"}, - {RPCResult::Type::NUM, "free", "Number of bytes available in current arenas"}, - {RPCResult::Type::NUM, "total", "Total number of bytes managed"}, - {RPCResult::Type::NUM, "locked", "Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk."}, - {RPCResult::Type::NUM, "chunks_used", "Number allocated chunks"}, - {RPCResult::Type::NUM, "chunks_free", "Number unused chunks"}, - }}, - } - }, - RPCResult{"mode \"mallocinfo\"", - RPCResult::Type::STR, "", "\"...\"" - }, - }, - RPCExamples{ - HelpExampleCli("getmemoryinfo", "") - + HelpExampleRpc("getmemoryinfo", "") - }, - }.ToString()); + {RPCResult::Type::OBJ, "locked", "Information about locked memory manager", + { + {RPCResult::Type::NUM, "used", "Number of bytes used"}, + {RPCResult::Type::NUM, "free", "Number of bytes available in current arenas"}, + {RPCResult::Type::NUM, "total", "Total number of bytes managed"}, + {RPCResult::Type::NUM, "locked", "Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk."}, + {RPCResult::Type::NUM, "chunks_used", "Number allocated chunks"}, + {RPCResult::Type::NUM, "chunks_free", "Number unused chunks"}, + }}, + } + }, + RPCResult{"mode \"mallocinfo\"", + RPCResult::Type::STR, "", "\"...\"" + }, + }, + RPCExamples{ + HelpExampleCli("getmemoryinfo", "") + + HelpExampleRpc("getmemoryinfo", "") + }, + }.Check(request); std::string mode = request.params[0].isNull() ? "stats" : request.params[0].get_str(); if (mode == "stats") { @@ -1231,43 +1191,40 @@ static void EnableOrDisableLogCategories(UniValue cats, bool enable) { static UniValue logging(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 2) { - throw std::runtime_error( - RPCHelpMan{"logging", - "Gets and sets the logging configuration.\n" - "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n" - "When called with arguments, adds or removes categories from debug logging and return the lists above.\n" - "The arguments are evaluated in order \"include\", \"exclude\".\n" - "If an item is both included and excluded, it will thus end up being excluded.\n" - "The valid logging categories are: " + ListLogCategories() + "\n" - "In addition, the following are available as category names with special meanings:\n" - " - \"all\", \"1\" : represent all logging categories.\n" - " - \"dash\" activates all Dash-specific categories at once.\n" - "To deactivate all categories at once you can specify \"all\" in .\n" - " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n" - , + RPCHelpMan{"logging", + "Gets and sets the logging configuration.\n" + "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n" + "When called with arguments, adds or removes categories from debug logging and return the lists above.\n" + "The arguments are evaluated in order \"include\", \"exclude\".\n" + "If an item is both included and excluded, it will thus end up being excluded.\n" + "The valid logging categories are: " + ListLogCategories() + "\n" + "In addition, the following are available as category names with special meanings:\n" + " - \"all\", \"1\" : represent all logging categories.\n" + " - \"dash\" activates all Dash-specific categories at once.\n" + "To deactivate all categories at once you can specify \"all\" in .\n" + " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n" + , + { + {"include", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "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, RPCArg::Optional::OMITTED, "the valid logging category"}, - }}, - {"exclude", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of categories to remove debug logging", - { - {"exclude_category", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "the valid logging category"}, - }}, - }, - RPCResult{ - RPCResult::Type::OBJ_DYN, "", "keys are the logging categories, and values indicates its status", - { - {RPCResult::Type::BOOL, "category", "if being debug logged or not. false:inactive, true:active"}, - } - }, - RPCExamples{ - HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") - + HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"") - }, - }.ToString()); - } + {"include_category", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "the valid logging category"}, + }}, + {"exclude", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of categories to remove debug logging", + { + {"exclude_category", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "the valid logging category"}, + }}, + }, + RPCResult{ + RPCResult::Type::OBJ_DYN, "", "keys are the logging categories, and values indicates its status", + { + {RPCResult::Type::BOOL, "category", "if being debug logged or not. false:inactive, true:active"}, + } + }, + RPCExamples{ + HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") + + HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"") + }, + }.Check(request); uint64_t original_log_categories = LogInstance().GetCategoryMask(); if (request.params[0].isArray()) { @@ -1304,18 +1261,15 @@ static UniValue logging(const JSONRPCRequest& request) static UniValue echo(const JSONRPCRequest& request) { - if (request.fHelp) - throw std::runtime_error( - RPCHelpMan{"echo|echojson ...", - "\nSimply echo back the input arguments. This command is for testing.\n" - "\nIt will return an internal bug report when exactly 100 arguments are passed.\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.", - {}, - RPCResult{RPCResult::Type::NONE, "", "Returns whatever was passed in"}, - RPCExamples{""}, - }.ToString() - ); + RPCHelpMan{"echo|echojson ...", + "\nSimply echo back the input arguments. This command is for testing.\n" + "\nIt will return an internal bug report when exactly 100 arguments are passed.\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.", + {}, + RPCResult{RPCResult::Type::NONE, "", "Returns whatever was passed in"}, + RPCExamples{""}, + }.Check(request); CHECK_NONFATAL(request.params.size() != 100); diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index f6ecaa4c9cf3..d9e334f1b533 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -30,19 +30,17 @@ 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", - {}, - RPCResult{ - RPCResult::Type::NUM, "", "The connection count" - }, - RPCExamples{ - HelpExampleCli("getconnectioncount", "") - + HelpExampleRpc("getconnectioncount", "") - }, - }.ToString()); + RPCHelpMan{"getconnectioncount", + "\nReturns the number of connections to other nodes.\n", + {}, + RPCResult{ + RPCResult::Type::NUM, "", "The connection count" + }, + RPCExamples{ + HelpExampleCli("getconnectioncount", "") + + HelpExampleRpc("getconnectioncount", "") + }, + }.Check(request); if(!g_rpc_node->connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); @@ -52,19 +50,17 @@ static UniValue getconnectioncount(const JSONRPCRequest& request) static UniValue ping(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 0) - throw std::runtime_error( - RPCHelpMan{"ping", - "\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", - {}, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - HelpExampleCli("ping", "") - + HelpExampleRpc("ping", "") - }, - }.ToString()); + RPCHelpMan{"ping", + "\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", + {}, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("ping", "") + + HelpExampleRpc("ping", "") + }, + }.Check(request); if(!g_rpc_node->connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); @@ -78,75 +74,73 @@ static UniValue ping(const JSONRPCRequest& request) 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", - {}, - RPCResult{ - "[\n" - " {\n" - " \"id\" : n, (numeric) Peer index\n" - " \"addr\" : \"host:port\", (string) The IP address and port of the peer\n" - " \"addrbind\" : \"ip:port\", (string) Bind address of the connection to the peer\n" - " \"addrlocal\" : \"ip:port\", (string) Local address as reported by the peer\n" - " \"mapped_as\" : \"mapped_as\", (string) The AS in the BGP route to the peer used for diversifying peer selection\n" - " \"services\" : \"xxxxxxxxxxxxxxxx\", (string) The services offered\n" - " \"verified_proregtx_hash\" : h, (hex) Only present when the peer is a masternode and successfully\n" - " authenticated via MNAUTH. In this case, this field contains the\n" - " protx hash of the masternode\n" - " \"verified_pubkey_hash\" : h, (hex) Only present when the peer is a masternode and successfully\n" - " authenticated via MNAUTH. In this case, this field contains the\n" - " hash of the masternode's operator public key\n" - " \"servicesnames\" : [ (json array) the services offered, in human-readable form\n" - " \"SERVICE_NAME\", (string) the service name if it is recognised\n" - " ...\n" - " ],\n" - " \"relaytxes\" : true|false, (boolean) Whether peer has asked us to relay transactions to it\n" - " \"lastsend\" : ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n" - " \"lastrecv\" : ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n" - " \"bytessent\" : n, (numeric) The total bytes sent\n" - " \"bytesrecv\" : n, (numeric) The total bytes received\n" - " \"conntime\" : ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT)\n" - " \"timeoffset\" : ttt, (numeric) The time offset in seconds\n" - " \"pingtime\" : n, (numeric) ping time (if available)\n" - " \"minping\" : n, (numeric) minimum observed ping time (if any at all)\n" - " \"pingwait\" : n, (numeric) ping wait (if non-zero)\n" - " \"version\" : v, (numeric) The peer version, such as 70001\n" - " \"subver\" : \"/Dash Core:x.x.x/\", (string) The string version\n" - " \"inbound\" : true|false, (boolean) Inbound (true) or Outbound (false)\n" - " \"addnode\" : true|false, (boolean) Whether connection was due to addnode/-connect or if it was an automatic/inbound connection\n" - " \"masternode\" : true|false, (boolean) Whether connection was due to masternode connection attempt\n" - " \"startingheight\" : n, (numeric) The starting height (block) of the peer\n" - " \"banscore\" : n, (numeric) The ban score\n" - " \"synced_headers\" : n, (numeric) The last header we have in common with this peer\n" - " \"synced_blocks\" : n, (numeric) The last block we have in common with this peer\n" - " \"inflight\" : [\n" - " n, (numeric) The heights of blocks we're currently asking from this peer\n" - " ...\n" - " ],\n" - " \"whitelisted\" : true|false, (boolean) Whether the peer is whitelisted\n" - " \"bytessent_per_msg\" : {\n" - " \"msg\" : n, (numeric) The total bytes sent aggregated by message type\n" - " When a message type is not listed in this json object, the bytes sent are 0.\n" - " Only known message types can appear as keys in the object.\n" - " ...\n" - " },\n" - " \"bytesrecv_per_msg\" : {\n" - " \"msg\" : n, (numeric) The total bytes received aggregated by message type\n" - " When a message type is not listed in this json object, the bytes received are 0.\n" - " Only known message types can appear as keys in the object and all bytes received of unknown message types are listed under '"+NET_MESSAGE_COMMAND_OTHER+"'.\n" - " ...\n" - " }\n" - " }\n" - " ,...\n" - "]\n" - }, - RPCExamples{ - HelpExampleCli("getpeerinfo", "") - + HelpExampleRpc("getpeerinfo", "") - }, - }.ToString()); + RPCHelpMan{"getpeerinfo", + "\nReturns data about each connected network node as a json array of objects.\n", + {}, + RPCResult{ + "[\n" + " {\n" + " \"id\" : n, (numeric) Peer index\n" + " \"addr\" : \"host:port\", (string) The IP address and port of the peer\n" + " \"addrbind\" : \"ip:port\", (string) Bind address of the connection to the peer\n" + " \"addrlocal\" : \"ip:port\", (string) Local address as reported by the peer\n" + " \"mapped_as\" : \"mapped_as\", (string) The AS in the BGP route to the peer used for diversifying peer selection\n" + " \"services\" : \"xxxxxxxxxxxxxxxx\", (string) The services offered\n" + " \"verified_proregtx_hash\" : h, (hex) Only present when the peer is a masternode and successfully\n" + " authenticated via MNAUTH. In this case, this field contains the\n" + " protx hash of the masternode\n" + " \"verified_pubkey_hash\" : h, (hex) Only present when the peer is a masternode and successfully\n" + " authenticated via MNAUTH. In this case, this field contains the\n" + " hash of the masternode's operator public key\n" + " \"servicesnames\" : [ (json array) the services offered, in human-readable form\n" + " \"SERVICE_NAME\", (string) the service name if it is recognised\n" + " ...\n" + " ],\n" + " \"relaytxes\" : true|false, (boolean) Whether peer has asked us to relay transactions to it\n" + " \"lastsend\" : ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n" + " \"lastrecv\" : ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n" + " \"bytessent\" : n, (numeric) The total bytes sent\n" + " \"bytesrecv\" : n, (numeric) The total bytes received\n" + " \"conntime\" : ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT)\n" + " \"timeoffset\" : ttt, (numeric) The time offset in seconds\n" + " \"pingtime\" : n, (numeric) ping time (if available)\n" + " \"minping\" : n, (numeric) minimum observed ping time (if any at all)\n" + " \"pingwait\" : n, (numeric) ping wait (if non-zero)\n" + " \"version\" : v, (numeric) The peer version, such as 70001\n" + " \"subver\" : \"/Dash Core:x.x.x/\", (string) The string version\n" + " \"inbound\" : true|false, (boolean) Inbound (true) or Outbound (false)\n" + " \"addnode\" : true|false, (boolean) Whether connection was due to addnode/-connect or if it was an automatic/inbound connection\n" + " \"masternode\" : true|false, (boolean) Whether connection was due to masternode connection attempt\n" + " \"startingheight\" : n, (numeric) The starting height (block) of the peer\n" + " \"banscore\" : n, (numeric) The ban score\n" + " \"synced_headers\" : n, (numeric) The last header we have in common with this peer\n" + " \"synced_blocks\" : n, (numeric) The last block we have in common with this peer\n" + " \"inflight\" : [\n" + " n, (numeric) The heights of blocks we're currently asking from this peer\n" + " ...\n" + " ],\n" + " \"whitelisted\" : true|false, (boolean) Whether the peer is whitelisted\n" + " \"bytessent_per_msg\" : {\n" + " \"msg\" : n, (numeric) The total bytes sent aggregated by message type\n" + " When a message type is not listed in this json object, the bytes sent are 0.\n" + " Only known message types can appear as keys in the object.\n" + " ...\n" + " },\n" + " \"bytesrecv_per_msg\" : {\n" + " \"msg\" : n, (numeric) The total bytes received aggregated by message type\n" + " When a message type is not listed in this json object, the bytes received are 0.\n" + " Only known message types can appear as keys in the object and all bytes received of unknown message types are listed under '"+NET_MESSAGE_COMMAND_OTHER+"'.\n" + " ...\n" + " }\n" + " }\n" + " ,...\n" + "]\n" + }, + RPCExamples{ + HelpExampleCli("getpeerinfo", "") + + HelpExampleRpc("getpeerinfo", "") + }, + }.Check(request); if(!g_rpc_node->connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); @@ -244,24 +238,21 @@ static UniValue addnode(const JSONRPCRequest& request) std::string strCommand; if (!request.params[1].isNull()) strCommand = request.params[1].get_str(); - if (request.fHelp || request.params.size() != 2 || - (strCommand != "onetry" && strCommand != "add" && strCommand != "remove")) - throw std::runtime_error( - RPCHelpMan{"addnode", - "\nAttempts to add or remove a node from the addnode list.\n" - "Or try a connection to a node once.\n" - "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, 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"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - HelpExampleCli("addnode", "\"192.168.0.6:9999\" \"onetry\"") - + HelpExampleRpc("addnode", "\"192.168.0.6:9999\", \"onetry\"") - }, - }.ToString()); + RPCHelpMan{"addnode", + "\nAttempts to add or remove a node from the addnode list.\n" + "Or try a connection to a node once.\n" + "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, 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"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("addnode", "\"192.168.0.6:9999\" \"onetry\"") + + HelpExampleRpc("addnode", "\"192.168.0.6:9999\", \"onetry\"") + }, + }.Check(request); if(!g_rpc_node->connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); @@ -291,24 +282,22 @@ static UniValue addnode(const JSONRPCRequest& request) static UniValue disconnectnode(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() == 0 || request.params.size() >= 3) - throw std::runtime_error( - RPCHelpMan{"disconnectnode", - "\nImmediately disconnects from the specified peer node.\n" - "\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, /* 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)"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - HelpExampleCli("disconnectnode", "\"192.168.0.6:9999\"") - + HelpExampleCli("disconnectnode", "\"\" 1") - + HelpExampleRpc("disconnectnode", "\"192.168.0.6:9999\"") - + HelpExampleRpc("disconnectnode", "\"\", 1") - }, - }.ToString()); + RPCHelpMan{"disconnectnode", + "\nImmediately disconnects from the specified peer node.\n" + "\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, /* 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)"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("disconnectnode", "\"192.168.0.6:9999\"") + + HelpExampleCli("disconnectnode", "\"\" 1") + + HelpExampleRpc("disconnectnode", "\"192.168.0.6:9999\"") + + HelpExampleRpc("disconnectnode", "\"\", 1") + }, + }.Check(request); if(!g_rpc_node->connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); @@ -337,35 +326,33 @@ static UniValue disconnectnode(const JSONRPCRequest& request) static UniValue getaddednodeinfo(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 1) - throw std::runtime_error( - RPCHelpMan{"getaddednodeinfo", - "\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, /* default */ "all nodes", "If provided, return information about this specific node, otherwise all nodes are returned."}, - }, - RPCResult{ - "[\n" - " {\n" - " \"addednode\" : \"192.168.0.201\", (string) The node IP address or name (as provided to addnode)\n" - " \"connected\" : true|false, (boolean) If connected\n" - " \"addresses\" : [ (list of objects) Only when connected = true\n" - " {\n" - " \"address\" : \"192.168.0.201:9999\", (string) The dash server IP and port we're connected to\n" - " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n" - " }\n" - " ]\n" - " }\n" - " ,...\n" - "]\n" - }, - RPCExamples{ - HelpExampleCli("getaddednodeinfo", "") - + HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") - + HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"") - }, - }.ToString()); + RPCHelpMan{"getaddednodeinfo", + "\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, /* default */ "all nodes", "If provided, return information about this specific node, otherwise all nodes are returned."}, + }, + RPCResult{ + "[\n" + " {\n" + " \"addednode\" : \"192.168.0.201\", (string) The node IP address or name (as provided to addnode)\n" + " \"connected\" : true|false, (boolean) If connected\n" + " \"addresses\" : [ (list of objects) Only when connected = true\n" + " {\n" + " \"address\" : \"192.168.0.201:9999\", (string) The dash server IP and port we're connected to\n" + " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n" + " }\n" + " ]\n" + " }\n" + " ,...\n" + "]\n" + }, + RPCExamples{ + HelpExampleCli("getaddednodeinfo", "") + + HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") + + HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"") + }, + }.Check(request); if(!g_rpc_node->connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); @@ -408,34 +395,32 @@ static UniValue getaddednodeinfo(const JSONRPCRequest& request) static UniValue getnettotals(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 0) - throw std::runtime_error( - RPCHelpMan{"getnettotals", - "\nReturns information about network traffic, including bytes in, bytes out,\n" - "and current time.\n", - {}, - RPCResult{ - RPCResult::Type::OBJ, "", "", - { - {RPCResult::Type::NUM, "totalbytesrecv", "Total bytes received"}, - {RPCResult::Type::NUM, "totalbytessent", "Total bytes sent"}, - {RPCResult::Type::NUM_TIME, "timemillis", "Current UNIX time in milliseconds"}, - {RPCResult::Type::OBJ, "uploadtarget", "", - { - {RPCResult::Type::NUM, "timeframe", "Length of the measuring timeframe in seconds"}, - {RPCResult::Type::NUM, "target", "Target in bytes"}, - {RPCResult::Type::BOOL, "target_reached", "True if target is reached"}, - {RPCResult::Type::BOOL, "serve_historical_blocks", "True if serving historical blocks"}, - {RPCResult::Type::NUM, "bytes_left_in_cycle", "Bytes left in current time cycle"}, - {RPCResult::Type::NUM, "time_left_in_cycle", "Seconds left in current time cycle"}, - }}, - } - }, - RPCExamples{ - HelpExampleCli("getnettotals", "") - + HelpExampleRpc("getnettotals", "") - }, - }.ToString()); + RPCHelpMan{"getnettotals", + "\nReturns information about network traffic, including bytes in, bytes out,\n" + "and current time.\n", + {}, + RPCResult{ + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::NUM, "totalbytesrecv", "Total bytes received"}, + {RPCResult::Type::NUM, "totalbytessent", "Total bytes sent"}, + {RPCResult::Type::NUM_TIME, "timemillis", "Current UNIX time in milliseconds"}, + {RPCResult::Type::OBJ, "uploadtarget", "", + { + {RPCResult::Type::NUM, "timeframe", "Length of the measuring timeframe in seconds"}, + {RPCResult::Type::NUM, "target", "Target in bytes"}, + {RPCResult::Type::BOOL, "target_reached", "True if target is reached"}, + {RPCResult::Type::BOOL, "serve_historical_blocks", "True if serving historical blocks"}, + {RPCResult::Type::NUM, "bytes_left_in_cycle", "Bytes left in current time cycle"}, + {RPCResult::Type::NUM, "time_left_in_cycle", "Seconds left in current time cycle"}, + }}, + } + }, + RPCExamples{ + HelpExampleCli("getnettotals", "") + + HelpExampleRpc("getnettotals", "") + }, + }.Check(request); if(!g_rpc_node->connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); @@ -478,55 +463,53 @@ static UniValue GetNetworksInfo() 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", - {}, - 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" - " \"subversion\" : \"/Dash Core:x.x.x.x/\", (string) the server subversion string\n" - " \"protocolversion\" : xxxxx, (numeric) the protocol version\n" - " \"localservices\" : \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n" - " \"localservicesnames\" : [ (json array) the services we offer to the network, in human-readable form\n" - " \"SERVICE_NAME\", (string) the service name\n" - " ...\n" - " ],\n" - " \"localrelay\" : true|false, (boolean) true if transaction relay is requested from peers\n" - " \"timeoffset\" : xxxxx, (numeric) the time offset\n" - " \"connections\" : xxxxx, (numeric) the number of connections\n" - " \"networkactive\" : true|false, (boolean) whether p2p networking is enabled\n" - " \"socketevents\" : \"xxx/\", (string) the socket events mode, either kqueue, epoll, poll or select\n" - " \"networks\" : [ (json array) information per network\n" - " {\n" - " \"name\" : \"xxx\", (string) network (ipv4, ipv6 or onion)\n" - " \"limited\" : true|false, (boolean) is the network limited using -onlynet?\n" - " \"reachable\" : true|false, (boolean) is the network reachable?\n" - " \"proxy\" : \"host:port\" (string) the proxy that is used for this network, or empty if none\n" - " \"proxy_randomize_credentials\" : true|false, (string) Whether randomized credentials are used\n" - " }\n" - " ,...\n" - " ],\n" - " \"relayfee\" : x.xxxxxxxx, (numeric) minimum relay fee for transactions in " + CURRENCY_UNIT + "/kB\n" - " \"incrementalfee\" : x.xxxxxxxx, (numeric) minimum fee increment for mempool limiting in " + CURRENCY_UNIT + "/kB\n" - " \"localaddresses\" : [ (json array) list of local addresses\n" - " {\n" - " \"address\" : \"xxxx\", (string) network address\n" - " \"port\" : xxx, (numeric) network port\n" - " \"score\" : xxx (numeric) relative score\n" - " }\n" - " ,...\n" - " ]\n" - " \"warnings\" : \"...\" (string) any network and blockchain warnings\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getnetworkinfo", "") - + HelpExampleRpc("getnetworkinfo", "") - }, - }.ToString()); + RPCHelpMan{"getnetworkinfo", + "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" + " \"subversion\" : \"/Dash Core:x.x.x.x/\", (string) the server subversion string\n" + " \"protocolversion\" : xxxxx, (numeric) the protocol version\n" + " \"localservices\" : \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n" + " \"localservicesnames\" : [ (json array) the services we offer to the network, in human-readable form\n" + " \"SERVICE_NAME\", (string) the service name\n" + " ...\n" + " ],\n" + " \"localrelay\" : true|false, (boolean) true if transaction relay is requested from peers\n" + " \"timeoffset\" : xxxxx, (numeric) the time offset\n" + " \"connections\" : xxxxx, (numeric) the number of connections\n" + " \"networkactive\" : true|false, (boolean) whether p2p networking is enabled\n" + " \"socketevents\" : \"xxx/\", (string) the socket events mode, either kqueue, epoll, poll or select\n" + " \"networks\" : [ (json array) information per network\n" + " {\n" + " \"name\" : \"xxx\", (string) network (ipv4, ipv6 or onion)\n" + " \"limited\" : true|false, (boolean) is the network limited using -onlynet?\n" + " \"reachable\" : true|false, (boolean) is the network reachable?\n" + " \"proxy\" : \"host:port\" (string) the proxy that is used for this network, or empty if none\n" + " \"proxy_randomize_credentials\" : true|false, (string) Whether randomized credentials are used\n" + " }\n" + " ,...\n" + " ],\n" + " \"relayfee\" : x.xxxxxxxx, (numeric) minimum relay fee for transactions in " + CURRENCY_UNIT + "/kB\n" + " \"incrementalfee\" : x.xxxxxxxx, (numeric) minimum fee increment for mempool limiting in " + CURRENCY_UNIT + "/kB\n" + " \"localaddresses\" : [ (json array) list of local addresses\n" + " {\n" + " \"address\" : \"xxxx\", (string) network address\n" + " \"port\" : xxx, (numeric) network port\n" + " \"score\" : xxx (numeric) relative score\n" + " }\n" + " ,...\n" + " ]\n" + " \"warnings\" : \"...\" (string) any network and blockchain warnings\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("getnetworkinfo", "") + + HelpExampleRpc("getnetworkinfo", "") + }, + }.Check(request); LOCK(cs_main); UniValue obj(UniValue::VOBJ); @@ -665,11 +648,9 @@ static UniValue setban(const JSONRPCRequest& request) 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", - {}, + RPCHelpMan{"listbanned", + "\nList all banned IPs/Subnets.\n", + {}, RPCResult{RPCResult::Type::ARR, "", "", { {RPCResult::Type::OBJ, "", "", @@ -680,11 +661,11 @@ static UniValue listbanned(const JSONRPCRequest& request) {RPCResult::Type::STR, "ban_reason", ""}, }}, }}, - RPCExamples{ - HelpExampleCli("listbanned", "") - + HelpExampleRpc("listbanned", "") - }, - }.ToString()); + RPCExamples{ + HelpExampleCli("listbanned", "") + + HelpExampleRpc("listbanned", "") + }, + }.Check(request); if(!g_rpc_node->banman) { throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded"); @@ -711,17 +692,15 @@ static UniValue listbanned(const JSONRPCRequest& request) static UniValue clearbanned(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 0) - throw std::runtime_error( - RPCHelpMan{"clearbanned", - "\nClear all banned IPs.\n", - {}, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - HelpExampleCli("clearbanned", "") - + HelpExampleRpc("clearbanned", "") - }, - }.ToString()); + RPCHelpMan{"clearbanned", + "\nClear all banned IPs.\n", + {}, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("clearbanned", "") + + HelpExampleRpc("clearbanned", "") + }, + }.Check(request); if (!g_rpc_node->banman) { throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded"); } @@ -733,18 +712,14 @@ static UniValue clearbanned(const JSONRPCRequest& request) static UniValue setnetworkactive(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"setnetworkactive", - "\nDisable/enable all p2p network activity.\n", - { - {"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, "true to enable networking, false to disable"}, - }, - RPCResult{RPCResult::Type::BOOL, "", "The value that was passed in"}, - RPCExamples{""}, - }.ToString() - ); - } + RPCHelpMan{"setnetworkactive", + "\nDisable/enable all p2p network activity.\n", + { + {"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, "true to enable networking, false to disable"}, + }, + RPCResult{RPCResult::Type::BOOL, "", "The value that was passed in"}, + RPCExamples{""}, + }.Check(request); if (!g_rpc_node->connman) { throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); @@ -757,30 +732,27 @@ static UniValue setnetworkactive(const JSONRPCRequest& request) static UniValue getnodeaddresses(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 1) { - throw std::runtime_error( - RPCHelpMan{"getnodeaddresses", - "\nReturn known addresses which can potentially be used to find new nodes in the network\n", - { - {"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" - " {\n" - " \"time\" : ttt, (numeric) Timestamp in seconds since epoch (Jan 1 1970 GMT) keeping track of when the node was last seen\n" - " \"services\" : n, (numeric) The services offered\n" - " \"address\" : \"host\", (string) The address of the node\n" - " \"port\" : n (numeric) The port of the node\n" - " }\n" - " ,....\n" - "]\n" - }, - RPCExamples{ - HelpExampleCli("getnodeaddresses", "8") - + HelpExampleRpc("getnodeaddresses", "8") - }, - }.ToString()); - } + RPCHelpMan{"getnodeaddresses", + "\nReturn known addresses which can potentially be used to find new nodes in the network\n", + { + {"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" + " {\n" + " \"time\" : ttt, (numeric) Timestamp in seconds since epoch (Jan 1 1970 GMT) keeping track of when the node was last seen\n" + " \"services\" : n, (numeric) The services offered\n" + " \"address\" : \"host\", (string) The address of the node\n" + " \"port\" : n (numeric) The port of the node\n" + " }\n" + " ,....\n" + "]\n" + }, + RPCExamples{ + HelpExampleCli("getnodeaddresses", "8") + + HelpExampleRpc("getnodeaddresses", "8") + }, + }.Check(request); if (!g_rpc_node->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 a1285a81802a..c9574ddb13da 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -114,9 +114,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) static UniValue getrawtransaction(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) - throw std::runtime_error( - RPCHelpMan{ + RPCHelpMan{ "getrawtransaction", "\nReturn the raw transaction data.\n" @@ -195,7 +193,7 @@ static UniValue getrawtransaction(const JSONRPCRequest& request) + HelpExampleCli("getrawtransaction", "\"mytxid\" false \"myblockhash\"") + HelpExampleCli("getrawtransaction", "\"mytxid\" true \"myblockhash\"") }, - }.ToString()); + }.Check(request); bool in_active_chain = true; uint256 hash = ParseHashV(request.params[0], "parameter 1"); @@ -259,32 +257,29 @@ static UniValue getrawtransaction(const JSONRPCRequest& request) static UniValue gettxoutproof(const JSONRPCRequest& request) { - if (request.fHelp || (request.params.size() != 1 && request.params.size() != 2)) - throw std::runtime_error( - RPCHelpMan{"gettxoutproof", - "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n" - "\nNOTE: By default this function only works sometimes. This is when there is an\n" - "unspent output in the utxo for this transaction. To make it always work,\n" - "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", + RPCHelpMan{"gettxoutproof", + "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n" + "\nNOTE: By default this function only works sometimes. This is when there is an\n" + "unspent output in the utxo for this transaction. To make it always work,\n" + "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, RPCArg::Optional::NO, "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, RPCArg::Optional::OMITTED, "A transaction hash"}, - }, - }, - {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED_NAMED_ARG, "If specified, looks for txid in the block with this hash"}, + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A transaction hash"}, }, - RPCResult{ - RPCResult::Type::STR, "data", "A string that is a serialized, hex-encoded data for the proof." }, - RPCExamples{ - HelpExampleCli("gettxoutproof", "'[\"mytxid\",...]'") - + HelpExampleCli("gettxoutproof", "'[\"mytxid\",...]' \"blockhash\"") - + HelpExampleRpc("gettxoutproof", "[\"mytxid\",...], \"blockhash\"") - }, - }.ToString() - ); + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED_NAMED_ARG, "If specified, looks for txid in the block with this hash"}, + }, + RPCResult{ + RPCResult::Type::STR, "data", "A string that is a serialized, hex-encoded data for the proof." + }, + RPCExamples{ + HelpExampleCli("gettxoutproof", "'[\"mytxid\",...]'") + + HelpExampleCli("gettxoutproof", "'[\"mytxid\",...]' \"blockhash\"") + + HelpExampleRpc("gettxoutproof", "[\"mytxid\",...], \"blockhash\"") + }, + }.Check(request); std::set setTxids; uint256 oneTxid; @@ -361,26 +356,23 @@ static UniValue gettxoutproof(const JSONRPCRequest& request) static UniValue verifytxoutproof(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"verifytxoutproof", - "\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, RPCArg::Optional::NO, "The hex-encoded proof generated by gettxoutproof"}, - }, - RPCResult{ - RPCResult::Type::ARR, "", "", - { - {RPCResult::Type::STR_HEX, "txid", "The txid(s) which the proof commits to, or empty array if the proof can not be validated."}, - } - }, - RPCExamples{ - HelpExampleCli("verifytxoutproof", "\"proof\"") - + HelpExampleRpc("gettxoutproof", "\"proof\"") - }, - }.ToString() - ); + RPCHelpMan{"verifytxoutproof", + "\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, RPCArg::Optional::NO, "The hex-encoded proof generated by gettxoutproof"}, + }, + RPCResult{ + RPCResult::Type::ARR, "", "", + { + {RPCResult::Type::STR_HEX, "txid", "The txid(s) which the proof commits to, or empty array if the proof can not be validated."}, + } + }, + RPCExamples{ + HelpExampleCli("verifytxoutproof", "\"proof\"") + + HelpExampleRpc("gettxoutproof", "\"proof\"") + }, + }.Check(request); CDataStream ssMB(ParseHexV(request.params[0], "proof"), SER_NETWORK, PROTOCOL_VERSION); CMerkleBlock merkleBlock; @@ -412,56 +404,53 @@ static UniValue verifytxoutproof(const JSONRPCRequest& request) static UniValue createrawtransaction(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) { - throw std::runtime_error( - RPCHelpMan{"createrawtransaction", - "\nCreate a transaction spending the given inputs and creating new outputs.\n" - "Outputs can be addresses or data.\n" - "Returns hex-encoded raw transaction.\n" - "Note that the transaction's inputs are not signed, and\n" - "it is not stored in the wallet or transmitted to the network.\n", + RPCHelpMan{"createrawtransaction", + "\nCreate a transaction spending the given inputs and creating new outputs.\n" + "Outputs can be addresses or data.\n" + "Returns hex-encoded raw transaction.\n" + "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, RPCArg::Optional::NO, "A json array of json objects", { - {"inputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of json objects", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", - { - {"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"}, - }, - }, + {"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, RPCArg::Optional::NO, "a json array with outputs (key-value pairs), where none of the keys are duplicated.\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.", + }, + }, + {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "a json array with outputs (key-value pairs), where none of the keys are duplicated.\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, RPCArg::Optional::OMITTED, "", { - {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", - { - {"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, RPCArg::Optional::OMITTED, "", - { - {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data"}, - }, - }, + {"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, RPCArg::Optional::OMITTED, "", + { + {"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, /* default */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"}, - }, - RPCResult{ - RPCResult::Type::STR_HEX, "transaction", "hex string of the transaction" }, - 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()); - } + {"locktime", RPCArg::Type::NUM, /* default */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"}, + }, + RPCResult{ + RPCResult::Type::STR_HEX, "transaction", "hex string of the transaction" + }, + 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\\\"}]\"") + }, + }.Check(request); RPCTypeCheck(request.params, { UniValue::VARR, @@ -477,9 +466,7 @@ static UniValue createrawtransaction(const JSONRPCRequest& request) static UniValue decoderawtransaction(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"decoderawtransaction", + RPCHelpMan{"decoderawtransaction", "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n", { {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction hex string"}, @@ -528,7 +515,7 @@ static UniValue decoderawtransaction(const JSONRPCRequest& request) HelpExampleCli("decoderawtransaction", "\"hexstring\"") + HelpExampleRpc("decoderawtransaction", "\"hexstring\"") }, - }.ToString()); + }.Check(request); RPCTypeCheck(request.params, {UniValue::VSTR}); @@ -555,7 +542,7 @@ static std::string GetAllOutputTypes() static UniValue decodescript(const JSONRPCRequest& request) { - const RPCHelpMan help{"decodescript", + RPCHelpMan{"decodescript", "\nDecode a hex-encoded script.\n", { {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded script"}, @@ -576,11 +563,7 @@ static UniValue decodescript(const JSONRPCRequest& request) HelpExampleCli("decodescript", "\"hexstring\"") + HelpExampleRpc("decodescript", "\"hexstring\"") }, - }; - - if (request.fHelp || !help.IsValidNumArgs(request.params.size())) { - throw std::runtime_error(help.ToString()); - } + }.Check(request); RPCTypeCheck(request.params, {UniValue::VSTR}); @@ -609,26 +592,24 @@ static UniValue decodescript(const JSONRPCRequest& request) static UniValue combinerawtransaction(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"combinerawtransaction", - "\nCombine multiple partially signed transactions into one transaction.\n" - "The combined transaction may be another partially signed transaction or a \n" - "fully signed transaction.", + RPCHelpMan{"combinerawtransaction", + "\nCombine multiple partially signed transactions into one transaction.\n" + "The combined transaction may be another partially signed transaction or a \n" + "fully signed transaction.", + { + {"txs", RPCArg::Type::ARR, RPCArg::Optional::NO, "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, RPCArg::Optional::OMITTED, "A hex-encoded raw transaction"}, - }, - }, + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A hex-encoded raw transaction"}, }, - RPCResult{ - RPCResult::Type::STR, "", "The hex-encoded raw transaction with signature(s)" }, - RPCExamples{ - HelpExampleCli("combinerawtransaction", R"('["myhex1", "myhex2", "myhex3"]')") - }, - }.ToString()); + }, + RPCResult{ + RPCResult::Type::STR, "", "The hex-encoded raw transaction with signature(s)" + }, + RPCExamples{ + HelpExampleCli("combinerawtransaction", R"('["myhex1", "myhex2", "myhex3"]')") + }, + }.Check(request); UniValue txs = request.params[0].get_array(); @@ -693,66 +674,64 @@ static UniValue combinerawtransaction(const JSONRPCRequest& request) static UniValue signrawtransactionwithkey(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) - throw std::runtime_error( - RPCHelpMan{"signrawtransactionwithkey", - "\nSign inputs for raw transaction (serialized, hex-encoded).\n" - "The second argument is an array of base58-encoded private\n" - "keys that will be the only keys used to sign the transaction.\n" - "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", + RPCHelpMan{"signrawtransactionwithkey", + "\nSign inputs for raw transaction (serialized, hex-encoded).\n" + "The second argument is an array of base58-encoded private\n" + "keys that will be the only keys used to sign the transaction.\n" + "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, RPCArg::Optional::NO, "The transaction hex string"}, + {"privkeys", RPCArg::Type::ARR, RPCArg::Optional::NO, "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, RPCArg::Optional::OMITTED, "private key in base58-encoding"}, - }, - }, - {"prevtxs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of previous dependent transaction outputs", + {"privatekey", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "private key in base58-encoding"}, + }, + }, + {"prevtxs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of previous dependent transaction outputs", + { + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", - { - {"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, RPCArg::Optional::OMITTED, "(required for P2SH or P2WSH) redeem script"}, - {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "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, RPCArg::Optional::OMITTED, "(required for P2SH or P2WSH) redeem script"}, + {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The amount spent"}, }, }, - {"sighashtype", RPCArg::Type::STR, /* default */ "ALL", "The signature hash type. Must be one of:\n" - " \"ALL\"\n" - " \"NONE\"\n" - " \"SINGLE\"\n" - " \"ALL|ANYONECANPAY\"\n" - " \"NONE|ANYONECANPAY\"\n" - " \"SINGLE|ANYONECANPAY\"\n" - }, }, - RPCResult{ - RPCResult::Type::OBJ, "", "", + }, + {"sighashtype", RPCArg::Type::STR, /* default */ "ALL", "The signature hash type. Must be one of:\n" + " \"ALL\"\n" + " \"NONE\"\n" + " \"SINGLE\"\n" + " \"ALL|ANYONECANPAY\"\n" + " \"NONE|ANYONECANPAY\"\n" + " \"SINGLE|ANYONECANPAY\"\n" + }, + }, + RPCResult{ + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::STR_HEX, "hex", "The hex-encoded raw transaction with signature(s)"}, + {RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"}, + {RPCResult::Type::ARR, "errors", "Script verification errors (if there are any)", + { + {RPCResult::Type::OBJ, "", "", { - {RPCResult::Type::STR_HEX, "hex", "The hex-encoded raw transaction with signature(s)"}, - {RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"}, - {RPCResult::Type::ARR, "errors", "Script verification errors (if there are any)", - { - {RPCResult::Type::OBJ, "", "", - { - {RPCResult::Type::STR_HEX, "txid", "The hash of the referenced, previous transaction"}, - {RPCResult::Type::NUM, "vout", "The index of the output to spent and used as input"}, - {RPCResult::Type::STR_HEX, "scriptSig", "The hex-encoded signature script"}, - {RPCResult::Type::NUM, "sequence", "Script sequence number"}, - {RPCResult::Type::STR, "error", "Verification or signing error related to the input"}, - }}, - }}, - } - }, - RPCExamples{ - HelpExampleCli("signrawtransactionwithkey", "\"myhex\" \"[\\\"key1\\\",\\\"key2\\\"]\"") - + HelpExampleRpc("signrawtransactionwithkey", "\"myhex\", \"[\\\"key1\\\",\\\"key2\\\"]\"") - }, - }.ToString()); + {RPCResult::Type::STR_HEX, "txid", "The hash of the referenced, previous transaction"}, + {RPCResult::Type::NUM, "vout", "The index of the output to spent and used as input"}, + {RPCResult::Type::STR_HEX, "scriptSig", "The hex-encoded signature script"}, + {RPCResult::Type::NUM, "sequence", "Script sequence number"}, + {RPCResult::Type::STR, "error", "Verification or signing error related to the input"}, + }}, + }}, + } + }, + RPCExamples{ + HelpExampleCli("signrawtransactionwithkey", "\"myhex\" \"[\\\"key1\\\",\\\"key2\\\"]\"") + + HelpExampleRpc("signrawtransactionwithkey", "\"myhex\", \"[\\\"key1\\\",\\\"key2\\\"]\"") + }, + }.Check(request); RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VARR, UniValue::VSTR}, true); @@ -784,7 +763,7 @@ static UniValue signrawtransactionwithkey(const JSONRPCRequest& request) UniValue sendrawtransaction(const JSONRPCRequest& request) { - const RPCHelpMan help{"sendrawtransaction", "\nSubmit a raw transaction (serialized, hex-encoded) to local node and network.\n" + RPCHelpMan{"sendrawtransaction", "\nSubmit a raw transaction (serialized, hex-encoded) to local node and network.\n" "\nNote that the transaction will be sent unconditionally to all peers, so using this\n" "for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n" "nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n" @@ -808,11 +787,7 @@ UniValue sendrawtransaction(const JSONRPCRequest& request) "\nAs a JSON-RPC call\n" + HelpExampleRpc("sendrawtransaction", "\"signedhex\"") }, - }; - - if (request.fHelp || !help.IsValidNumArgs(request.params.size())) { - throw std::runtime_error(help.ToString()); - } + }.Check(request); RPCTypeCheck(request.params, { UniValue::VSTR, @@ -851,7 +826,7 @@ UniValue sendrawtransaction(const JSONRPCRequest& request) static UniValue testmempoolaccept(const JSONRPCRequest& request) { - const RPCHelpMan help{"testmempoolaccept", + RPCHelpMan{"testmempoolaccept", "\nReturns result of mempool acceptance tests indicating if raw transaction (serialized, hex-encoded) would be accepted by mempool.\n" "\nThis checks if the transaction violates the consensus or policy rules.\n" "\nSee sendrawtransaction call.\n", @@ -885,11 +860,7 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request) "\nAs a JSON-RPC call\n" + HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]") }, - }; - - if (request.fHelp || !help.IsValidNumArgs(request.params.size())) { - throw std::runtime_error(help.ToString()); - } + }.Check(request); RPCTypeCheck(request.params, { UniValue::VARR, @@ -966,85 +937,83 @@ static std::string WriteHDKeypath(std::vector& keypath) UniValue decodepsbt(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"decodepsbt", - "\nReturn a JSON object representing the serialized, base64-encoded partially signed Dash transaction.\n", - { - {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "The PSBT base64 string"}, - }, - RPCResult{ - "{\n" - " \"tx\" : { (json object) The decoded network-serialized unsigned transaction.\n" - " ... The layout is the same as the output of decoderawtransaction.\n" - " },\n" - " \"unknown\" : { (json object) The unknown global fields\n" - " \"key\" : \"value\" (key-value pair) An unknown key-value pair\n" - " ...\n" - " },\n" - " \"inputs\" : [ (array of json objects)\n" - " {\n" - " \"non_witness_utxo\" : { (json object, optional) Decoded network transaction for non-witness UTXOs\n" - " ...\n" - " },\n" - " \"partial_signatures\" : { (json object, optional)\n" - " \"pubkey\" : \"signature\", (string) The public key and signature that corresponds to it.\n" - " ,...\n" - " }\n" - " \"sighash\" : \"type\", (string, optional) The sighash type to be used\n" - " \"redeem_script\" : { (json object, optional)\n" - " \"asm\" : \"asm\", (string) The asm\n" - " \"hex\" : \"hex\", (string) The hex\n" - " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n" - " }\n" - " \"bip32_derivs\" : { (json object, optional)\n" - " \"pubkey\" : { (json object, optional) The public key with the derivation path as the value.\n" - " \"master_fingerprint\" : \"fingerprint\" (string) The fingerprint of the master key\n" - " \"path\" : \"path\", (string) The path\n" - " }\n" - " ,...\n" - " }\n" - " \"final_scriptsig\" : { (json object, optional)\n" - " \"asm\" : \"asm\", (string) The asm\n" - " \"hex\" : \"hex\", (string) The hex\n" - " }\n" - " \"unknown\" : { (json object) The unknown global fields\n" - " \"key\" : \"value\" (key-value pair) An unknown key-value pair\n" - " ...\n" - " },\n" - " }\n" - " ,...\n" - " ]\n" - " \"outputs\" : [ (array of json objects)\n" - " {\n" - " \"redeem_script\" : { (json object, optional)\n" - " \"asm\" : \"asm\", (string) The asm\n" - " \"hex\" : \"hex\", (string) The hex\n" - " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n" - " }\n" - " \"bip32_derivs\" : [ (array of json objects, optional)\n" - " {\n" - " \"pubkey\" : \"pubkey\", (string) The public key this path corresponds to\n" - " \"master_fingerprint\" : \"fingerprint\" (string) The fingerprint of the master key\n" - " \"path\" : \"path\", (string) The path\n" - " }\n" - " }\n" - " ,...\n" - " ],\n" - " \"unknown\" : { (json object) The unknown global fields\n" - " \"key\" : \"value\" (key-value pair) An unknown key-value pair\n" - " ...\n" - " },\n" - " }\n" - " ,...\n" - " ]\n" - " \"fee\" : fee (numeric, optional) The transaction fee paid if all UTXOs slots in the PSBT have been filled.\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("decodepsbt", "\"psbt\"") - }, - }.ToString()); + RPCHelpMan{"decodepsbt", + "\nReturn a JSON object representing the serialized, base64-encoded partially signed Dash transaction.\n", + { + {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "The PSBT base64 string"}, + }, + RPCResult{ + "{\n" + " \"tx\" : { (json object) The decoded network-serialized unsigned transaction.\n" + " ... The layout is the same as the output of decoderawtransaction.\n" + " },\n" + " \"unknown\" : { (json object) The unknown global fields\n" + " \"key\" : \"value\" (key-value pair) An unknown key-value pair\n" + " ...\n" + " },\n" + " \"inputs\" : [ (array of json objects)\n" + " {\n" + " \"non_witness_utxo\" : { (json object, optional) Decoded network transaction for non-witness UTXOs\n" + " ...\n" + " },\n" + " \"partial_signatures\" : { (json object, optional)\n" + " \"pubkey\" : \"signature\", (string) The public key and signature that corresponds to it.\n" + " ,...\n" + " }\n" + " \"sighash\" : \"type\", (string, optional) The sighash type to be used\n" + " \"redeem_script\" : { (json object, optional)\n" + " \"asm\" : \"asm\", (string) The asm\n" + " \"hex\" : \"hex\", (string) The hex\n" + " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n" + " }\n" + " \"bip32_derivs\" : { (json object, optional)\n" + " \"pubkey\" : { (json object, optional) The public key with the derivation path as the value.\n" + " \"master_fingerprint\" : \"fingerprint\" (string) The fingerprint of the master key\n" + " \"path\" : \"path\", (string) The path\n" + " }\n" + " ,...\n" + " }\n" + " \"final_scriptsig\" : { (json object, optional)\n" + " \"asm\" : \"asm\", (string) The asm\n" + " \"hex\" : \"hex\", (string) The hex\n" + " }\n" + " \"unknown\" : { (json object) The unknown global fields\n" + " \"key\" : \"value\" (key-value pair) An unknown key-value pair\n" + " ...\n" + " },\n" + " }\n" + " ,...\n" + " ]\n" + " \"outputs\" : [ (array of json objects)\n" + " {\n" + " \"redeem_script\" : { (json object, optional)\n" + " \"asm\" : \"asm\", (string) The asm\n" + " \"hex\" : \"hex\", (string) The hex\n" + " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n" + " }\n" + " \"bip32_derivs\" : [ (array of json objects, optional)\n" + " {\n" + " \"pubkey\" : \"pubkey\", (string) The public key this path corresponds to\n" + " \"master_fingerprint\" : \"fingerprint\" (string) The fingerprint of the master key\n" + " \"path\" : \"path\", (string) The path\n" + " }\n" + " }\n" + " ,...\n" + " ],\n" + " \"unknown\" : { (json object) The unknown global fields\n" + " \"key\" : \"value\" (key-value pair) An unknown key-value pair\n" + " ...\n" + " },\n" + " }\n" + " ,...\n" + " ]\n" + " \"fee\" : fee (numeric, optional) The transaction fee paid if all UTXOs slots in the PSBT have been filled.\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("decodepsbt", "\"psbt\"") + }, + }.Check(request); RPCTypeCheck(request.params, {UniValue::VSTR}); @@ -1192,25 +1161,23 @@ UniValue decodepsbt(const JSONRPCRequest& request) UniValue combinepsbt(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"combinepsbt", - "\nCombine multiple partially signed Dash transactions into one transaction.\n" - "Implements the Combiner role.\n", + RPCHelpMan{"combinepsbt", + "\nCombine multiple partially signed Dash transactions into one transaction.\n" + "Implements the Combiner role.\n", + { + {"txs", RPCArg::Type::ARR, RPCArg::Optional::NO, "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, RPCArg::Optional::OMITTED, "A base64 string of a PSBT"}, - }, - }, + {"psbt", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "A base64 string of a PSBT"}, }, - RPCResult{ - RPCResult::Type::STR, "", "The base64-encoded partially signed transaction" - }, - RPCExamples{ - HelpExampleCli("combinepsbt", R"('["mybase64_1", "mybase64_2", "mybase64_3"]')") }, - }.ToString()); + }, + RPCResult{ + RPCResult::Type::STR, "", "The base64-encoded partially signed transaction" + }, + RPCExamples{ + HelpExampleCli("combinepsbt", R"('["mybase64_1", "mybase64_2", "mybase64_3"]')") + }, + }.Check(request); RPCTypeCheck(request.params, {UniValue::VARR}, true); @@ -1242,30 +1209,28 @@ UniValue combinepsbt(const JSONRPCRequest& request) UniValue finalizepsbt(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"finalizepsbt", - "Finalize the inputs of a PSBT. If the transaction is fully signed, it will produce a\n" - "network serialized transaction which can be broadcast with sendrawtransaction. Otherwise a PSBT will be\n" - "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, 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{ - "{\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" - }, - RPCExamples{ - HelpExampleCli("finalizepsbt", "\"psbt\"") - }, - }.ToString()); + RPCHelpMan{"finalizepsbt", + "Finalize the inputs of a PSBT. If the transaction is fully signed, it will produce a\n" + "network serialized transaction which can be broadcast with sendrawtransaction. Otherwise a PSBT will be\n" + "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, 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{ + "{\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" + }, + RPCExamples{ + HelpExampleCli("finalizepsbt", "\"psbt\"") + }, + }.Check(request); RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}, true); @@ -1301,49 +1266,47 @@ UniValue finalizepsbt(const JSONRPCRequest& request) UniValue createpsbt(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) - throw std::runtime_error( - RPCHelpMan{"createpsbt", - "\nCreates a transaction in the Partially Signed Transaction format.\n" - "Implements the Creator role.\n", + RPCHelpMan{"createpsbt", + "\nCreates a transaction in the Partially Signed Transaction format.\n" + "Implements the Creator role.\n", + { + {"inputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of json objects", { - {"inputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of json objects", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", - { - {"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 */ "depends on the value of 'locktime' argument", "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 */ "depends on the value of 'locktime' argument", "The sequence number"}, }, }, - {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "a json array with outputs (key-value pairs), where none of the keys are duplicated.\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.", + }, + }, + {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "a json array with outputs (key-value pairs), where none of the keys are duplicated.\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, RPCArg::Optional::OMITTED, "", { - {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", - { - {"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, RPCArg::Optional::OMITTED, "", - { - {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data"}, - }, - }, + {"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, RPCArg::Optional::OMITTED, "", + { + {"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, /* default */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"}, - }, - RPCResult{ - RPCResult::Type::STR, "", "The resulting raw transaction (base64-encoded string)" }, - RPCExamples{ - HelpExampleCli("createpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") }, - }.ToString()); + {"locktime", RPCArg::Type::NUM, /* default */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"}, + }, + RPCResult{ + RPCResult::Type::STR, "", "The resulting raw transaction (base64-encoded string)" + }, + RPCExamples{ + HelpExampleCli("createpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") + }, + }.Check(request); RPCTypeCheck(request.params, { @@ -1374,9 +1337,7 @@ UniValue createpsbt(const JSONRPCRequest& request) UniValue converttopsbt(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) - throw std::runtime_error( - RPCHelpMan{"converttopsbt", + RPCHelpMan{"converttopsbt", "\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", { @@ -1393,8 +1354,7 @@ UniValue converttopsbt(const JSONRPCRequest& request) "\nConvert the transaction to a PSBT\n" + HelpExampleCli("converttopsbt", "\"rawtransaction\"") }, - }.ToString()); - + }.Check(request); RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VBOOL}, true); @@ -1432,20 +1392,17 @@ UniValue converttopsbt(const JSONRPCRequest& request) UniValue utxoupdatepsbt(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"utxoupdatepsbt", - "\nUpdates a PSBT with UTXOs retrieved from the UTXO set or the mempool.\n", - { - {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "A base64 string of a PSBT"} - }, - RPCResult { - RPCResult::Type::STR, "", "The base64-encoded partially signed transaction with inputs updated" - }, - RPCExamples { - HelpExampleCli("utxoupdatepsbt", "\"psbt\"") - }}.ToString()); - } + RPCHelpMan{"utxoupdatepsbt", + "\nUpdates a PSBT with UTXOs retrieved from the UTXO set or the mempool.\n", + { + {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "A base64 string of a PSBT"} + }, + RPCResult { + RPCResult::Type::STR, "", "The base64-encoded partially signed transaction with inputs updated" + }, + RPCExamples { + HelpExampleCli("utxoupdatepsbt", "\"psbt\"") + }}.Check(request); RPCTypeCheck(request.params, {UniValue::VSTR}, true); @@ -1493,24 +1450,21 @@ UniValue utxoupdatepsbt(const JSONRPCRequest& request) UniValue joinpsbts(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error( - RPCHelpMan{"joinpsbts", - "\nJoins multiple distinct PSBTs with different inputs and outputs into one PSBT with inputs and outputs from all of the PSBTs\n" - "No input in any of the PSBTs can be in more than one of the PSBTs.\n", + RPCHelpMan{"joinpsbts", + "\nJoins multiple distinct PSBTs with different inputs and outputs into one PSBT with inputs and outputs from all of the PSBTs\n" + "No input in any of the PSBTs can be in more than one of the PSBTs.\n", + { + {"txs", RPCArg::Type::ARR, RPCArg::Optional::NO, "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, RPCArg::Optional::NO, "A base64 string of a PSBT"} - }} - }, - RPCResult { - RPCResult::Type::STR, "", "The base64-encoded partially signed transaction" - }, - RPCExamples { - HelpExampleCli("joinpsbts", "\"psbt\"") - }}.ToString()); - } + {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "A base64 string of a PSBT"} + }} + }, + RPCResult { + RPCResult::Type::STR, "", "The base64-encoded partially signed transaction" + }, + RPCExamples { + HelpExampleCli("joinpsbts", "\"psbt\"") + }}.Check(request); RPCTypeCheck(request.params, {UniValue::VARR}, true); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 16349d578c27..6827173d5319 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -152,20 +152,17 @@ void CRPCTable::InitPlatformRestrictions() UniValue help(const JSONRPCRequest& jsonRequest) { - if (jsonRequest.fHelp || jsonRequest.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"help", - "\nList all commands, or get help for a specified command.\n", - { - {"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{ - RPCResult::Type::STR, "", "The help text" - }, - RPCExamples{""}, - }.ToString() - ); + RPCHelpMan{"help", + "\nList all commands, or get help for a specified command.\n", + { + {"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{ + RPCResult::Type::STR, "", "The help text" + }, + RPCExamples{""}, + }.Check(jsonRequest); std::string strCommand, strSubCommand; if (jsonRequest.params.size() > 0) @@ -184,14 +181,12 @@ UniValue stop(const JSONRPCRequest& jsonRequest) // Also accept the hidden 'wait' integer argument (milliseconds) // For instance, 'stop 1000' makes the call wait 1 second before returning // to the client (intended for testing) - if (jsonRequest.fHelp || jsonRequest.params.size() > 1) - throw std::runtime_error( - RPCHelpMan{"stop", - "\nStop Dash Core server.", - {}, - RPCResult{RPCResult::Type::STR, "", "A string with the content '" + RESULT + "'"}, - RPCExamples{""}, - }.ToString()); + RPCHelpMan{"stop", + "\nStop Dash Core server.", + {}, + RPCResult{RPCResult::Type::STR, "", "A string with the content '" + RESULT + "'"}, + RPCExamples{""}, + }.Check(jsonRequest); // Event loop will exit after current HTTP requests have been handled, so // this reply will get back to the client. StartShutdown(); @@ -203,31 +198,27 @@ UniValue stop(const JSONRPCRequest& jsonRequest) 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", - {}, - RPCResult{ - RPCResult::Type::NUM, "", "The number of seconds that the server has been running" - }, - RPCExamples{ - HelpExampleCli("uptime", "") - + HelpExampleRpc("uptime", "") - }, - }.ToString()); + RPCHelpMan{"uptime", + "\nReturns the total uptime of the server.\n", + {}, + RPCResult{ + RPCResult::Type::NUM, "", "The number of seconds that the server has been running" + }, + RPCExamples{ + HelpExampleCli("uptime", "") + + HelpExampleRpc("uptime", "") + }, + }.Check(jsonRequest); return GetTime() - GetStartupTime(); } static UniValue getrpcinfo(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 0) { - throw std::runtime_error( - RPCHelpMan{"getrpcinfo", - "\nReturns details of the RPC server.\n", - {}, - RPCResult{ + RPCHelpMan{"getrpcinfo", + "\nReturns details of the RPC server.\n", + {}, + RPCResult{ "{\n" " \"active_commands\" (array) All active commands\n" " [\n" @@ -237,14 +228,10 @@ static UniValue getrpcinfo(const JSONRPCRequest& request) " },...\n" " ],\n" " \"logpath\": \"xxx\" (string) The complete file path to the debug log\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("getrpcinfo", "") + "}\n"}, + RPCExamples{HelpExampleCli("getrpcinfo", "") + HelpExampleRpc("getrpcinfo", "")}, - }.ToString() - ); - } + }.Check(request); LOCK(g_rpc_server_info.mutex); UniValue active_commands(UniValue::VARR); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 3e7c1cad5915..81bdec617c3d 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -70,32 +70,30 @@ static void RescanWallet(CWallet& wallet, const WalletRescanReserver& reserver, UniValue importprivkey(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) - 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" - "\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, 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"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - "\nDump a private key\n" - + HelpExampleCli("dumpprivkey", "\"myaddress\"") + - "\nImport the private key with rescan\n" - + HelpExampleCli("importprivkey", "\"mykey\"") + - "\nImport using a label and without rescan\n" - + HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") + - "\nImport using default blank label and without rescan\n" - + HelpExampleCli("importprivkey", "\"mykey\" \"\" false") + - "\nAs a JSON-RPC call\n" - + HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false") - }, - }.ToString()); + 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" + "\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, 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"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + "\nDump a private key\n" + + HelpExampleCli("dumpprivkey", "\"myaddress\"") + + "\nImport the private key with rescan\n" + + HelpExampleCli("importprivkey", "\"mykey\"") + + "\nImport using a label and without rescan\n" + + HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") + + "\nImport using default blank label and without rescan\n" + + HelpExampleCli("importprivkey", "\"mykey\" \"\" false") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false") + }, + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -169,9 +167,7 @@ UniValue importprivkey(const JSONRPCRequest& request) UniValue abortrescan(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() > 0) - throw std::runtime_error( - RPCHelpMan{"abortrescan", + RPCHelpMan{"abortrescan", "\nStops current wallet rescan triggered by an RPC call, e.g. by an importprivkey call.\n", {}, RPCResult{RPCResult::Type::BOOL, "", "Whether the abort was successful"}, @@ -183,7 +179,7 @@ UniValue abortrescan(const JSONRPCRequest& request) "\nAs a JSON-RPC call\n" + HelpExampleRpc("abortrescan", "") }, - }.ToString()); + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -234,32 +230,30 @@ static void ImportAddress(CWallet * const pwallet, const CTxDestination& dest, c 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" - "\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" - "Hint: use importmulti to import more than one address.\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, 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"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - 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()); + 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" + "\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" + "Hint: use importmulti to import more than one address.\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, 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"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + 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") + }, + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -323,18 +317,15 @@ UniValue importaddress(const JSONRPCRequest& request) UniValue importprunedfunds(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 2) - throw std::runtime_error( - 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, 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"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{""}, - }.ToString() - ); + 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, 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"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{""}, + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -385,20 +376,18 @@ UniValue importprunedfunds(const JSONRPCRequest& request) UniValue removeprunedfunds(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - 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, RPCArg::Optional::NO, "The hex-encoded id of the transaction you are deleting"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - RPCExamples{ - HelpExampleCli("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"") + - "\nAs a JSON-RPC call\n" - + HelpExampleRpc("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"") - }, - }.ToString()); + 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, RPCArg::Optional::NO, "The hex-encoded id of the transaction you are deleting"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"") + + "\nAs a JSON-RPC call\n" + + HelpExampleRpc("removeprunedfunds", "\"a8d0c0184dde994a09ec054286f1ce581bebf46446a512166eae7628734ea0a5\"") + }, + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -426,28 +415,26 @@ UniValue removeprunedfunds(const JSONRPCRequest& request) 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" - "Hint: use importmulti to import more than one public 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 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, 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"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - 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()); + 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" + "Hint: use importmulti to import more than one public 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 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, 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"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + 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") + }, + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -504,24 +491,22 @@ UniValue importpubkey(const JSONRPCRequest& request) UniValue importwallet(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"importwallet", - "\nImports keys from a wallet dump file (see dumpwallet). Requires a new wallet backup to include imported keys.\n" - "Note: Use \"getwalletinfo\" to query the scanning progress.\n", - { - {"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The wallet file"}, - }, - RPCResult{RPCResult::Type::NONE, "", ""}, - 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()); + RPCHelpMan{"importwallet", + "\nImports keys from a wallet dump file (see dumpwallet). Requires a new wallet backup to include imported keys.\n" + "Note: Use \"getwalletinfo\" to query the scanning progress.\n", + { + {"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The wallet file"}, + }, + RPCResult{RPCResult::Type::NONE, "", ""}, + 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\"") + }, + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -668,24 +653,22 @@ UniValue importwallet(const JSONRPCRequest& request) UniValue importelectrumwallet(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) - throw std::runtime_error( - RPCHelpMan{"importselectrumwallet", - "\nImports keys from an Electrum wallet export file (.csv or .json)\n", - { - {"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The Electrum wallet export file, should be in csv or json format"}, - {"index", RPCArg::Type::NUM, /* default */ "0", "Rescan the wallet for transactions starting from this block index"}, - }, - RPCResults{}, - RPCExamples{ - "\nImport the wallet\n" - + HelpExampleCli("importelectrumwallet", "\"test.csv\"") - + HelpExampleCli("importelectrumwallet", "\"test.json\"") + - "\nImport using the json rpc call\n" - + HelpExampleRpc("importelectrumwallet", "\"test.csv\"") - + HelpExampleRpc("importelectrumwallet", "\"test.json\"") - }, - }.ToString()); + RPCHelpMan{"importselectrumwallet", + "\nImports keys from an Electrum wallet export file (.csv or .json)\n", + { + {"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The Electrum wallet export file, should be in csv or json format"}, + {"index", RPCArg::Type::NUM, /* default */ "0", "Rescan the wallet for transactions starting from this block index"}, + }, + RPCResults{}, + RPCExamples{ + "\nImport the wallet\n" + + HelpExampleCli("importelectrumwallet", "\"test.csv\"") + + HelpExampleCli("importelectrumwallet", "\"test.json\"") + + "\nImport using the json rpc call\n" + + HelpExampleRpc("importelectrumwallet", "\"test.csv\"") + + HelpExampleRpc("importelectrumwallet", "\"test.json\"") + }, + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -818,23 +801,21 @@ UniValue importelectrumwallet(const JSONRPCRequest& request) UniValue dumpprivkey(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"dumpprivkey", - "\nReveals the private key corresponding to 'address'.\n" - "Then the importprivkey can be used with this output\n", - { - {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The dash address for the private key"}, - }, - RPCResult{ - RPCResult::Type::STR, "key", "The private key" - }, - RPCExamples{ - HelpExampleCli("dumpprivkey", "\"myaddress\"") - + HelpExampleCli("importprivkey", "\"mykey\"") - + HelpExampleRpc("dumpprivkey", "\"myaddress\"") - }, - }.ToString()); + RPCHelpMan{"dumpprivkey", + "\nReveals the private key corresponding to 'address'.\n" + "Then the importprivkey can be used with this output\n", + { + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The dash address for the private key"}, + }, + RPCResult{ + RPCResult::Type::STR, "key", "The private key" + }, + RPCExamples{ + HelpExampleCli("dumpprivkey", "\"myaddress\"") + + HelpExampleCli("importprivkey", "\"mykey\"") + + HelpExampleRpc("dumpprivkey", "\"myaddress\"") + }, + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -863,23 +844,21 @@ UniValue dumpprivkey(const JSONRPCRequest& request) UniValue dumphdinfo(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 0) - throw std::runtime_error( - RPCHelpMan{"dumphdinfo", - "Returns an object containing sensitive private info about this HD wallet.\n", - {}, - RPCResult{ - "{\n" - " \"hdseed\" : \"seed\", (string) The HD seed (bip32, in hex)\n" - " \"mnemonic\" : \"words\", (string) The mnemonic for this HD wallet (bip39, english words) \n" - " \"mnemonicpassphrase\" : \"passphrase\", (string) The mnemonic passphrase for this HD wallet (bip39)\n" - "}\n" - }, - RPCExamples{ - HelpExampleCli("dumphdinfo", "") - + HelpExampleRpc("dumphdinfo", "") - }, - }.ToString()); + RPCHelpMan{"dumphdinfo", + "Returns an object containing sensitive private info about this HD wallet.\n", + {}, + RPCResult{ + "{\n" + " \"hdseed\" : \"seed\", (string) The HD seed (bip32, in hex)\n" + " \"mnemonic\" : \"words\", (string) The mnemonic for this HD wallet (bip39, english words) \n" + " \"mnemonicpassphrase\" : \"passphrase\", (string) The mnemonic passphrase for this HD wallet (bip39)\n" + "}\n" + }, + RPCExamples{ + HelpExampleCli("dumphdinfo", "") + + HelpExampleRpc("dumphdinfo", "") + }, + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -910,28 +889,26 @@ UniValue dumphdinfo(const JSONRPCRequest& request) UniValue dumpwallet(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - RPCHelpMan{"dumpwallet", - "\nDumps all wallet keys in a human-readable format to a server-side file. This does not allow overwriting existing files.\n" - "Imported scripts are included in the dumpfile too, their corresponding addresses will be added automatically by importwallet.\n" - "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, RPCArg::Optional::NO, "The filename with path (either absolute or relative to dashd)"}, - }, - RPCResult{ - "{ (json object)\n" - " \"keys\" : { (numeric) 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" - }, - RPCExamples{ - HelpExampleCli("dumpwallet", "\"test\"") - + HelpExampleRpc("dumpwallet", "\"test\"") - }, - }.ToString()); + RPCHelpMan{"dumpwallet", + "\nDumps all wallet keys in a human-readable format to a server-side file. This does not allow overwriting existing files.\n" + "Imported scripts are included in the dumpfile too, their corresponding addresses will be added automatically by importwallet.\n" + "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, RPCArg::Optional::NO, "The filename with path (either absolute or relative to dashd)"}, + }, + RPCResult{ + "{ (json object)\n" + " \"keys\" : { (numeric) 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" + }, + RPCExamples{ + HelpExampleCli("dumpwallet", "\"test\"") + + HelpExampleRpc("dumpwallet", "\"test\"") + }, + }.Check(request); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -1447,69 +1424,66 @@ static int64_t GetImportTimestamp(const UniValue& data, int64_t now) 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)), optionally rescanning the blockchain from the earliest creation time of the imported scripts. Requires a new wallet backup.\n" - "If an address/script is imported without all of the private keys required to spend from that address, it will be watchonly. The 'watchonly' option must be set to true in this case or a warning will be returned.\n" - "Conversely, if all the private keys are provided and the address/script is spendable, the watchonly option must be set to false, or a warning will be returned.\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", + RPCHelpMan{"importmulti", + "\nImport addresses/scripts (with private or public keys, redeem script (P2SH)), optionally rescanning the blockchain from the earliest creation time of the imported scripts. Requires a new wallet backup.\n" + "If an address/script is imported without all of the private keys required to spend from that address, it will be watchonly. The 'watchonly' option must be set to true in this case or a warning will be returned.\n" + "Conversely, if all the private keys are provided and the address/script is spendable, the watchonly option must be set to false, or a warning will be returned.\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, RPCArg::Optional::NO, "Data to be imported", { - {"requests", RPCArg::Type::ARR, RPCArg::Optional::NO, "Data to be imported", + {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", + {"desc", RPCArg::Type::STR, /* default */ "", "Descriptor to import. If using descriptor, do not also provide address/scriptPubKey, scripts, or pubkeys" + }, + {"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 */ "", {"\"