diff --git a/src/Makefile.am b/src/Makefile.am index 2b9f815fd9b2..78b2544d2f07 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -257,9 +257,10 @@ BITCOIN_CORE_H = \ rpc/client.h \ rpc/mining.h \ rpc/protocol.h \ - rpc/server.h \ rpc/rawtransaction_util.h \ rpc/register.h \ + rpc/request.h \ + rpc/server.h \ rpc/util.h \ saltedhasher.h \ scheduler.h \ @@ -292,6 +293,7 @@ BITCOIN_CORE_H = \ unordered_lru_cache.h \ util/bip32.h \ util/bytevectorhash.h \ + util/check.h \ util/error.h \ util/fees.h \ util/spanparsing.h \ @@ -678,7 +680,7 @@ libdash_util_a_SOURCES = \ interfaces/handler.cpp \ logging.cpp \ random.cpp \ - rpc/protocol.cpp \ + rpc/request.cpp \ stacktraces.cpp \ support/cleanse.cpp \ sync.cpp \ diff --git a/src/dash-cli.cpp b/src/dash-cli.cpp index 3d1ebce3a5fa..ac4a781e4f89 100644 --- a/src/dash-cli.cpp +++ b/src/dash-cli.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/src/rest.cpp b/src/rest.cpp index c985319f812d..834195393acd 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 08ba78b0b955..5d05d1bf7ea0 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -11,12 +11,12 @@ #include #include #include -#include #include #include #include -#include #include +#include +#include #include #include #include @@ -40,7 +40,6 @@ #include #include -#include #include #include @@ -67,7 +66,7 @@ extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& */ double GetDifficulty(const CBlockIndex* blockindex) { - assert(blockindex); + CHECK_NONFATAL(blockindex); int nShift = (blockindex->nBits >> 24) & 0xff; double dDiff = @@ -190,8 +189,7 @@ static UniValue getblockcount(const JSONRPCRequest& request) "The genesis block has height 0.\n", {}, RPCResult{ - "n (numeric) The current block count\n" - }, + RPCResult::Type::NUM, "", "The current block count"}, RPCExamples{ HelpExampleCli("getblockcount", "") + HelpExampleRpc("getblockcount", "") @@ -210,8 +208,7 @@ static UniValue getbestblockhash(const JSONRPCRequest& request) "\nReturns the hash of the best (tip) block in the most-work fully-validated chain.\n", {}, RPCResult{ - "\"hex\" (string) the block hash, hex-encoded\n" - }, + RPCResult::Type::STR_HEX, "", "the block hash, hex-encoded"}, RPCExamples{ HelpExampleCli("getbestblockhash", "") + HelpExampleRpc("getbestblockhash", "") @@ -278,11 +275,11 @@ static UniValue waitfornewblock(const JSONRPCRequest& request) {"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."}, }, RPCResult{ - "{ (json object)\n" - " \"hash\" : { (string) The blockhash\n" - " \"height\" : { (int) Block height\n" - "}\n" - }, + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::STR_HEX, "hash", "The blockhash"}, + {RPCResult::Type::NUM, "height", "Block height"}, + }}, RPCExamples{ HelpExampleCli("waitfornewblock", "1000") + HelpExampleRpc("waitfornewblock", "1000") @@ -320,11 +317,11 @@ static UniValue waitforblock(const JSONRPCRequest& request) {"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."}, }, RPCResult{ - "{ (json object)\n" - " \"hash\" : { (string) The blockhash\n" - " \"height\" : { (int) Block height\n" - "}\n" - }, + 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") @@ -366,11 +363,11 @@ static UniValue waitforblockheight(const JSONRPCRequest& request) {"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."}, }, RPCResult{ - "{ (json object)\n" - " \"hash\" : { (string) The blockhash\n" - " \"height\" : { (int) Block height\n" - "}\n" - }, + 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") @@ -425,8 +422,7 @@ static UniValue getdifficulty(const JSONRPCRequest& request) "\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n", {}, RPCResult{ - "n.nnn (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty.\n" - }, + RPCResult::Type::NUM, "", "the proof-of-work difficulty as a multiple of the minimum difficulty."}, RPCExamples{ HelpExampleCli("getdifficulty", "") + HelpExampleRpc("getdifficulty", "") @@ -458,10 +454,10 @@ static std::string EntryDescriptionString() " \"ancestor\" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) in " + CURRENCY_UNIT + "\n" " \"descendant\" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one) in " + CURRENCY_UNIT + "\n" " }\n" - " \"depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n" + " \"depends\" : [ (json array) unconfirmed transactions used as inputs for this transaction\n" " \"transactionid\", (string) parent transaction id\n" " ... ],\n" - " \"spentby\" : [ (array) unconfirmed transactions spending outputs from this transaction\n" + " \"spentby\" : [ (json array) unconfirmed transactions spending outputs from this transaction\n" " \"transactionid\", (string) child transaction id\n" " ... ]\n" " \"instantlock\" : true|false (boolean) True if this transaction was locked via InstantSend\n"; @@ -802,8 +798,7 @@ static UniValue getblockhash(const JSONRPCRequest& request) {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "The height index"}, }, RPCResult{ - "\"hash\" (string) The block hash\n" - }, + RPCResult::Type::STR_HEX, "", "The block hash"}, RPCExamples{ HelpExampleCli("getblockhash", "1000") + HelpExampleRpc("getblockhash", "1000") @@ -1093,12 +1088,11 @@ static UniValue getblock(const JSONRPCRequest& request) "If verbosity is 2, returns an Object with information about block and information about each transaction. \n", { {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, - {"verbosity", RPCArg::Type::NUM, /* default */ "1", "0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data"}, + {"verbosity|verbose", RPCArg::Type::NUM, /* default */ "1", "0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data"}, }, { RPCResult{"for verbosity = 0", - "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n" - }, + RPCResult::Type::STR_HEX, "", "A string that is serialized, hex-encoded data for block 'hash'"}, RPCResult{"for verbosity = 1", "{\n" " \"hash\" : \"hash\", (string) the block hash (same as provided)\n" @@ -1186,8 +1180,7 @@ static UniValue pruneblockchain(const JSONRPCRequest& request) " to prune blocks whose block time is at least 2 hours older than the provided timestamp."}, }, RPCResult{ - "n (numeric) Height of the last block pruned.\n" - }, + RPCResult::Type::NUM, "", "Height of the last block pruned"}, RPCExamples{ HelpExampleCli("pruneblockchain", "1000") + HelpExampleRpc("pruneblockchain", "1000") @@ -1227,7 +1220,7 @@ static UniValue pruneblockchain(const JSONRPCRequest& request) PruneBlockFilesManual(height); const CBlockIndex* block = ::ChainActive().Tip(); - assert(block); + CHECK_NONFATAL(block); while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) { block = block->pprev; } @@ -1243,17 +1236,17 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request) "Note this call may take some time.\n", {}, RPCResult{ - "{\n" - " \"height\":n, (numeric) The current block height (index)\n" - " \"bestblock\": \"hex\", (string) The hash of the block at the tip of the chain\n" - " \"transactions\": n, (numeric) The number of transactions with unspent outputs\n" - " \"txouts\": n, (numeric) The number of unspent transaction outputs\n" - " \"bogosize\": n, (numeric) A meaningless metric for UTXO set size\n" - " \"hash_serialized_2\": \"hash\", (string) The serialized hash\n" - " \"disk_size\": n, (numeric) The estimated size of the chainstate on disk\n" - " \"total_amount\": x.xxx (numeric) The total amount\n" - "}\n" - }, + 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"}, + {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", "") @@ -1294,7 +1287,7 @@ static UniValue gettxout(const JSONRPCRequest& request) }, RPCResult{ "{\n" - " \"bestblock\": \"hash\", (string) The hash of the block at the tip of the chain\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" @@ -1376,8 +1369,7 @@ static UniValue verifychain(const JSONRPCRequest& request) {"nblocks", RPCArg::Type::NUM, /* default */ strprintf("%d, 0=all", nCheckDepth), "The number of blocks to check."}, }, RPCResult{ - "true|false (boolean) Verified or not\n" - }, + RPCResult::Type::BOOL, "", "Verified or not"}, RPCExamples{ HelpExampleCli("verifychain", "") + HelpExampleRpc("verifychain", "") @@ -1475,43 +1467,43 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) {}, RPCResult{ "{\n" - " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest) and\n" + " \"chain\" : \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest) and\n" " devnet or devnet- for \"-devnet\" and \"-devnet=\" respectively\n" - " \"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, (bool) (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\": [ (array) status of softforks in progress\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\": { (object) progress toward rejecting pre-softfork blocks\n" - " \"status\": xx, (boolean) true if threshold reached\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\": { (object) status of BIP9 softforks in progress\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\": { (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" + " \"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" @@ -1543,7 +1535,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) obj.pushKV("pruned", fPruneMode); if (fPruneMode) { const CBlockIndex* block = tip; - assert(block); + CHECK_NONFATAL(block); while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) { block = block->pprev; } @@ -1604,22 +1596,22 @@ static UniValue getchaintips(const JSONRPCRequest& request) RPCResult{ "[\n" " {\n" - " \"height\": xxxx, (numeric) height of the chain tip\n" - " \"hash\": \"xxxx\", (string) block hash of the tip\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" + " \"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" + " \"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" + " \"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" @@ -1751,14 +1743,14 @@ static UniValue getmempoolinfo(const JSONRPCRequest& request) {}, 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" + " \"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{ @@ -1903,14 +1895,14 @@ static UniValue getchaintxstats(const JSONRPCRequest& request) }, 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" + " \"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{ @@ -1937,7 +1929,7 @@ static UniValue getchaintxstats(const JSONRPCRequest& request) } } - assert(pindex != nullptr); + CHECK_NONFATAL(pindex != nullptr); if (request.params[0].isNull()) { blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1)); @@ -2043,37 +2035,37 @@ static UniValue getblockstats(const JSONRPCRequest& request) }, RPCResult{ "{ (json object)\n" - " \"avgfee\": xxxxx, (numeric) Average fee in the block\n" - " \"avgfeerate\": xxxxx, (numeric) Average feerate (in duffs per byte)\n" - " \"avgtxsize\": xxxxx, (numeric) Average transaction size\n" - " \"blockhash\": xxxxx, (string) The block hash (to check for potential reorgs)\n" - " \"feerate_percentiles\": [ (array of numeric) Feerates at the 10th, 25th, 50th, 75th, and 90th percentile weight unit (in duffs per byte)\n" + " \"avgfee\" : xxxxx, (numeric) Average fee in the block\n" + " \"avgfeerate\" : xxxxx, (numeric) Average feerate (in duffs per byte)\n" + " \"avgtxsize\" : xxxxx, (numeric) Average transaction size\n" + " \"blockhash\" : xxxxx, (string) The block hash (to check for potential reorgs)\n" + " \"feerate_percentiles\" : [ (array of numeric) Feerates at the 10th, 25th, 50th, 75th, and 90th percentile weight unit (in duffs per byte)\n" " \"10th_percentile_feerate\", (numeric) The 10th percentile feerate\n" " \"25th_percentile_feerate\", (numeric) The 25th percentile feerate\n" " \"50th_percentile_feerate\", (numeric) The 50th percentile feerate\n" " \"75th_percentile_feerate\", (numeric) The 75th percentile feerate\n" " \"90th_percentile_feerate\", (numeric) The 90th percentile feerate\n" " ],\n" - " \"height\": xxxxx, (numeric) The height of the block\n" - " \"ins\": xxxxx, (numeric) The number of inputs (excluding coinbase)\n" - " \"maxfee\": xxxxx, (numeric) Maximum fee in the block\n" - " \"maxfeerate\": xxxxx, (numeric) Maximum feerate (in duffs per byte)\n" - " \"maxtxsize\": xxxxx, (numeric) Maximum transaction size\n" - " \"medianfee\": xxxxx, (numeric) Truncated median fee in the block\n" - " \"mediantime\": xxxxx, (numeric) The block median time past\n" - " \"mediantxsize\": xxxxx, (numeric) Truncated median transaction size\n" - " \"minfee\": xxxxx, (numeric) Minimum fee in the block\n" - " \"minfeerate\": xxxxx, (numeric) Minimum feerate (in duffs per byte)\n" - " \"mintxsize\": xxxxx, (numeric) Minimum transaction size\n" - " \"outs\": xxxxx, (numeric) The number of outputs\n" - " \"subsidy\": xxxxx, (numeric) The block subsidy\n" - " \"time\": xxxxx, (numeric) The block time\n" - " \"total_out\": xxxxx, (numeric) Total amount in all outputs (excluding coinbase and thus reward [ie subsidy + totalfee])\n" - " \"total_size\": xxxxx, (numeric) Total size of all non-coinbase transactions\n" - " \"totalfee\": xxxxx, (numeric) The fee total\n" - " \"txs\": xxxxx, (numeric) The number of transactions (excluding coinbase)\n" - " \"utxo_increase\": xxxxx, (numeric) The increase/decrease in the number of unspent outputs\n" - " \"utxo_size_inc\": xxxxx, (numeric) The increase/decrease in size for the utxo index (not discounting op_return and similar)\n" + " \"height\" : xxxxx, (numeric) The height of the block\n" + " \"ins\" : xxxxx, (numeric) The number of inputs (excluding coinbase)\n" + " \"maxfee\" : xxxxx, (numeric) Maximum fee in the block\n" + " \"maxfeerate\" : xxxxx, (numeric) Maximum feerate (in duffs per byte)\n" + " \"maxtxsize\" : xxxxx, (numeric) Maximum transaction size\n" + " \"medianfee\" : xxxxx, (numeric) Truncated median fee in the block\n" + " \"mediantime\" : xxxxx, (numeric) The block median time past\n" + " \"mediantxsize\" : xxxxx, (numeric) Truncated median transaction size\n" + " \"minfee\" : xxxxx, (numeric) Minimum fee in the block\n" + " \"minfeerate\" : xxxxx, (numeric) Minimum feerate (in duffs per byte)\n" + " \"mintxsize\" : xxxxx, (numeric) Minimum transaction size\n" + " \"outs\" : xxxxx, (numeric) The number of outputs\n" + " \"subsidy\" : xxxxx, (numeric) The block subsidy\n" + " \"time\" : xxxxx, (numeric) The block time\n" + " \"total_out\" : xxxxx, (numeric) Total amount in all outputs (excluding coinbase and thus reward [ie subsidy + totalfee])\n" + " \"total_size\" : xxxxx, (numeric) Total size of all non-coinbase transactions\n" + " \"totalfee\" : xxxxx, (numeric) The fee total\n" + " \"txs\" : xxxxx, (numeric) The number of transactions (excluding coinbase)\n" + " \"utxo_increase\" : xxxxx, (numeric) The increase/decrease in the number of unspent outputs\n" + " \"utxo_size_inc\" : xxxxx, (numeric) The increase/decrease in size for the utxo index (not discounting op_return and similar)\n" "}\n" }, RPCExamples{ @@ -2119,7 +2111,7 @@ static UniValue getblockstats(const JSONRPCRequest& request) } } - assert(pindex != nullptr); + CHECK_NONFATAL(pindex != nullptr); std::set stats; if (!request.params[1].isNull()) { @@ -2208,7 +2200,7 @@ static UniValue getblockstats(const JSONRPCRequest& request) } CAmount txfee = tx_total_in - tx_total_out; - assert(MoneyRange(txfee)); + CHECK_NONFATAL(MoneyRange(txfee)); if (do_medianfee) { fee_array.push_back(txfee); } @@ -2448,7 +2440,7 @@ class CoinsViewScanReserver explicit CoinsViewScanReserver() : m_could_reserve(false) {} bool reserve() { - assert (!m_could_reserve); + CHECK_NONFATAL(!m_could_reserve); std::lock_guard lock(g_utxosetscan); if (g_scan_in_progress) { return false; @@ -2503,24 +2495,26 @@ UniValue scantxoutset(const JSONRPCRequest& request) "[scanobjects,...]"}, }, RPCResult{ - "{\n" - " \"success\": true|false, (boolean) Whether the scan was completed\n" - " \"txouts\": n, (numeric) The number of unspent transaction outputs scanned\n" - " \"height\": n, (numeric) The current block height (index)\n" - " \"bestblock\": \"hex\", (string) The hash of the block at the tip of the chain\n" - " \"unspents\": [\n" - " {\n" - " \"txid\": \"hash\", (string) The transaction id\n" - " \"vout\": n, (numeric) The vout value\n" - " \"scriptPubKey\": \"script\", (string) The script key\n" - " \"desc\": \"descriptor\", (string) A specialized descriptor for the matched scriptPubKey\n" - " \"amount\": x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " of the unspent output\n" - " \"height\": n, (numeric) Height of the unspent transaction output\n" - " }\n" - " ,...],\n" - " \"total_amount\": x.xxx, (numeric) The total amount of all found unspent outputs in " + CURRENCY_UNIT + "\n" - "]\n" - }, + 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::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_AMOUNT, "total_amount", "The total amount of all found unspent outputs in " + CURRENCY_UNIT}, + }}, RPCExamples{""}, }.ToString() ); @@ -2613,9 +2607,9 @@ UniValue scantxoutset(const JSONRPCRequest& request) LOCK(cs_main); ::ChainstateActive().ForceFlushStateToDisk(); pcursor = std::unique_ptr(::ChainstateActive().CoinsDB().Cursor()); - assert(pcursor); + CHECK_NONFATAL(pcursor); tip = ::ChainActive().Tip(); - assert(tip); + CHECK_NONFATAL(tip); } bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins); result.pushKV("success", res); diff --git a/src/rpc/coinjoin.cpp b/src/rpc/coinjoin.cpp index 58c011593790..aee9aa9f1bfc 100644 --- a/src/rpc/coinjoin.cpp +++ b/src/rpc/coinjoin.cpp @@ -18,11 +18,6 @@ #ifdef ENABLE_WALLET static UniValue coinjoin(const JSONRPCRequest& request) { - std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - CWallet* const pwallet = wallet.get(); - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; - if (request.fHelp || request.params.size() != 1) throw std::runtime_error( RPCHelpMan{"coinjoin", @@ -37,6 +32,10 @@ static UniValue coinjoin(const JSONRPCRequest& request) RPCExamples{""}, }.ToString()); + std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); + if (!wallet) return NullUniValue; + CWallet* const pwallet = wallet.get(); + if (fMasternodeMode) throw JSONRPCError(RPC_INTERNAL_ERROR, "Client-side mixing is not supported on masternodes"); @@ -103,36 +102,36 @@ static UniValue getcoinjoininfo(const JSONRPCRequest& request) RPCResults{ {"for regular nodes", "{\n" - " \"enabled\": true|false, (bool) Whether mixing functionality is enabled\n" - " \"multisession\": true|false, (bool) Whether CoinJoin Multisession option is enabled\n" - " \"max_sessions\": xxx, (numeric) How many parallel mixing sessions can there be at once\n" - " \"max_rounds\": xxx, (numeric) How many rounds to mix\n" - " \"max_amount\": xxx, (numeric) Target CoinJoin balance in " + CURRENCY_UNIT + "\n" - " \"denoms_goal\": xxx, (numeric) How many inputs of each denominated amount to target\n" - " \"denoms_hardcap\": xxx, (numeric) Maximum limit of how many inputs of each denominated amount to create\n" - " \"queue_size\": xxx, (numeric) How many queues there are currently on the network\n" - " \"running\": true|false, (bool) Whether mixing is currently running\n" - " \"sessions\": (array of json objects)\n" + " \"enabled\" : true|false, (boolean) Whether mixing functionality is enabled\n" + " \"multisession\" : true|false, (boolean) Whether CoinJoin Multisession option is enabled\n" + " \"max_sessions\" : xxx, (numeric) How many parallel mixing sessions can there be at once\n" + " \"max_rounds\" : xxx, (numeric) How many rounds to mix\n" + " \"max_amount\" : xxx, (numeric) Target CoinJoin balance in " + CURRENCY_UNIT + "\n" + " \"denoms_goal\" : xxx, (numeric) How many inputs of each denominated amount to target\n" + " \"denoms_hardcap\" : xxx, (numeric) Maximum limit of how many inputs of each denominated amount to create\n" + " \"queue_size\" : xxx, (numeric) How many queues there are currently on the network\n" + " \"running\" : true|false, (boolean) Whether mixing is currently running\n" + " \"sessions\" : (array of json objects)\n" " [\n" " {\n" - " \"protxhash\": \"...\", (string) The ProTxHash of the masternode\n" - " \"outpoint\": \"txid-index\", (string) The outpoint of the masternode\n" - " \"service\": \"host:port\", (string) The IP address and port of the masternode\n" - " \"denomination\": xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n" - " \"state\": \"...\", (string) Current state of the mixing session\n" - " \"entries_count\": xxx, (numeric) The number of entries in the mixing session\n" + " \"protxhash\" : \"...\", (string) The ProTxHash of the masternode\n" + " \"outpoint\" : \"txid-index\", (string) The outpoint of the masternode\n" + " \"service\" : \"host:port\", (string) The IP address and port of the masternode\n" + " \"denomination\" : xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n" + " \"state\" : \"...\", (string) Current state of the mixing session\n" + " \"entries_count\" : xxx, (numeric) The number of entries in the mixing session\n" " }\n" " ,...\n" " ],\n" - " \"keys_left\": xxx, (numeric) How many new keys are left since last automatic backup\n" - " \"warnings\": \"...\" (string) Warnings if any\n" + " \"keys_left\" : xxx, (numeric) How many new keys are left since last automatic backup\n" + " \"warnings\" : \"...\" (string) Warnings if any\n" "}\n" }, {"for masternodes", "{\n" - " \"queue_size\": xxx, (numeric) How many queues there are currently on the network\n" - " \"denomination\": xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n" - " \"state\": \"...\", (string) Current state of the mixing session\n" - " \"entries_count\": xxx, (numeric) The number of entries in the mixing session\n" + " \"queue_size\" : xxx, (numeric) How many queues there are currently on the network\n" + " \"denomination\" : xxx, (numeric) The denomination of the mixing session in " + CURRENCY_UNIT + "\n" + " \"state\" : \"...\", (string) Current state of the mixing session\n" + " \"entries_count\" : xxx, (numeric) The number of entries in the mixing session\n" "}\n" }}, RPCExamples{ diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index b43e2b432025..295d24f910ea 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -24,23 +24,22 @@ #include #endif // ENABLE_WALLET -static void gobject_count_help() +static void gobject_count_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject count", - "Count governance objects and votes\n", - { - {"mode", RPCArg::Type::STR, /* default */ "json", "Output format: json (\"json\") or string in free form (\"all\")"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject count", + "Count governance objects and votes\n", + { + {"mode", RPCArg::Type::STR, /* default */ "json", "Output format: json (\"json\") or string in free form (\"all\")"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_count(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() > 2) - gobject_count_help(); + gobject_count_help(request); std::string strMode{"json"}; @@ -49,28 +48,27 @@ static UniValue gobject_count(const JSONRPCRequest& request) } if (strMode != "json" && strMode != "all") - gobject_count_help(); + gobject_count_help(request); return strMode == "json" ? governance.ToJson() : governance.ToString(); } -static void gobject_deserialize_help() +static void gobject_deserialize_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan {"gobject deserialize", - "Deserialize governance object from hex string to JSON\n", - { - {"hex_data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string form"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan {"gobject deserialize", + "Deserialize governance object from hex string to JSON\n", + { + {"hex_data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string form"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_deserialize(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() != 2) - gobject_deserialize_help(); + gobject_deserialize_help(request); std::string strHex = request.params[1].get_str(); @@ -83,23 +81,22 @@ static UniValue gobject_deserialize(const JSONRPCRequest& request) return u.write().c_str(); } -static void gobject_check_help() +static void gobject_check_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject check", - "Validate governance object data (proposal only)\n", - { - {"hex_data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string format"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject check", + "Validate governance object data (proposal only)\n", + { + {"hex_data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string format"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_check(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() != 2) - gobject_check_help(); + gobject_check_help(request); // ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS @@ -132,35 +129,33 @@ static UniValue gobject_check(const JSONRPCRequest& request) } #ifdef ENABLE_WALLET -static void gobject_prepare_help(CWallet* const pwallet) +static void gobject_prepare_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject prepare", - "Prepare governance object by signing and creating tx\n" - + HelpRequiringPassphrase(pwallet) + "\n", - { - {"parent-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the parent object, \"0\" is root"}, - {"revision", RPCArg::Type::NUM, RPCArg::Optional::NO, "object revision in the system"}, - {"time", RPCArg::Type::NUM, RPCArg::Optional::NO, "time this object was created"}, - {"data-hex", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string form"}, - {"use-IS", RPCArg::Type::BOOL, /* default */ "false", "Deprecated and ignored"}, - {"outputHash", RPCArg::Type::STR_HEX, /* default */ "", "the single output to submit the proposal fee from"}, - {"outputIndex", RPCArg::Type::NUM, /* default */ "", "The output index."}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject prepare", + "Prepare governance object by signing and creating tx\n" + + HelpRequiringPassphrase() + "\n", + { + {"parent-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the parent object, \"0\" is root"}, + {"revision", RPCArg::Type::NUM, RPCArg::Optional::NO, "object revision in the system"}, + {"time", RPCArg::Type::NUM, RPCArg::Optional::NO, "time this object was created"}, + {"data-hex", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string form"}, + {"use-IS", RPCArg::Type::BOOL, /* default */ "false", "Deprecated and ignored"}, + {"outputHash", RPCArg::Type::STR_HEX, /* default */ "", "the single output to submit the proposal fee from"}, + {"outputIndex", RPCArg::Type::NUM, /* default */ "", "The output index."}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_prepare(const JSONRPCRequest& request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); + if (!wallet) return NullUniValue; CWallet* const pwallet = wallet.get(); - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6 && request.params.size() != 8)) - gobject_prepare_help(pwallet); + gobject_prepare_help(request); EnsureWalletIsUnlocked(pwallet); @@ -260,31 +255,29 @@ static UniValue gobject_prepare(const JSONRPCRequest& request) return tx->GetHash().ToString(); } -static void gobject_list_prepared_help(CWallet* const pwallet) +static void gobject_list_prepared_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject list-prepared", - "Returns a list of governance objects prepared by this wallet with \"gobject prepare\" sorted by their creation time.\n" - + HelpRequiringPassphrase(pwallet) + "\n", - { - {"count", RPCArg::Type::NUM, /* default */ "10", "Maximum number of objects to return."}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject list-prepared", + "Returns a list of governance objects prepared by this wallet with \"gobject prepare\" sorted by their creation time.\n" + + HelpRequiringPassphrase() + "\n", + { + {"count", RPCArg::Type::NUM, /* default */ "10", "Maximum number of objects to return."}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_list_prepared(const JSONRPCRequest& request) { - std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - CWallet* const pwallet = wallet.get(); - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; - if (request.fHelp || (request.params.size() > 2)) { - gobject_list_prepared_help(pwallet); + gobject_list_prepared_help(request); } + std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); + if (!wallet) return NullUniValue; + CWallet* const pwallet = wallet.get(); + EnsureWalletIsUnlocked(pwallet); int64_t nCount = request.params.size() > 1 ? ParseInt64V(request.params[1], "count") : 10; @@ -312,27 +305,26 @@ static UniValue gobject_list_prepared(const JSONRPCRequest& request) } #endif // ENABLE_WALLET -static void gobject_submit_help() +static void gobject_submit_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject submit", - "Submit governance object to network\n", - { - {"parent-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the parent object, \"0\" is root"}, - {"revision", RPCArg::Type::NUM, RPCArg::Optional::NO, "object revision in the system"}, - {"time", RPCArg::Type::NUM, RPCArg::Optional::NO, "time this object was created"}, - {"data-hex", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string form"}, - {"fee-txid", RPCArg::Type::STR_HEX, /* default */ "", "fee-tx id, required for all objects except triggers"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject submit", + "Submit governance object to network\n", + { + {"parent-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the parent object, \"0\" is root"}, + {"revision", RPCArg::Type::NUM, RPCArg::Optional::NO, "object revision in the system"}, + {"time", RPCArg::Type::NUM, RPCArg::Optional::NO, "time this object was created"}, + {"data-hex", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "data in hex string form"}, + {"fee-txid", RPCArg::Type::STR_HEX, /* default */ "", "fee-tx id, required for all objects except triggers"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_submit(const JSONRPCRequest& request) { if (request.fHelp || ((request.params.size() < 5) || (request.params.size() > 6))) - gobject_submit_help(); + gobject_submit_help(request); if(!masternodeSync.IsBlockchainSynced()) { throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Must wait for client to sync with masternode network. Try again in a minute or so."); @@ -430,25 +422,24 @@ static UniValue gobject_submit(const JSONRPCRequest& request) return govobj.GetHash().ToString(); } -static void gobject_vote_conf_help() +static void gobject_vote_conf_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject vote-conf", - "Vote on a governance object by masternode configured in dash.conf\n", - { - {"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the governance object"}, - {"vote", RPCArg::Type::STR, RPCArg::Optional::NO, "vote, possible values: [funding|valid|delete|endorsed]"}, - {"vote-outcome", RPCArg::Type::STR, RPCArg::Optional::NO, "vote outcome, possible values: [yes|no|abstain]"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject vote-conf", + "Vote on a governance object by masternode configured in dash.conf\n", + { + {"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the governance object"}, + {"vote", RPCArg::Type::STR, RPCArg::Optional::NO, "vote, possible values: [funding|valid|delete|endorsed]"}, + {"vote-outcome", RPCArg::Type::STR, RPCArg::Optional::NO, "vote outcome, possible values: [yes|no|abstain]"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_vote_conf(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() != 4) - gobject_vote_conf_help(); + gobject_vote_conf_help(request); uint256 hash; @@ -604,31 +595,29 @@ static UniValue VoteWithMasternodes(const std::map& keys, } #ifdef ENABLE_WALLET -static void gobject_vote_many_help(CWallet* const pwallet) +static void gobject_vote_many_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject vote-many", - "Vote on a governance object by all masternodes for which the voting key is present in the local wallet\n" - + HelpRequiringPassphrase(pwallet) + "\n", - { - {"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the governance object"}, - {"vote", RPCArg::Type::STR, RPCArg::Optional::NO, "vote, possible values: [funding|valid|delete|endorsed]"}, - {"vote-outcome", RPCArg::Type::STR, RPCArg::Optional::NO, "vote outcome, possible values: [yes|no|abstain]"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject vote-many", + "Vote on a governance object by all masternodes for which the voting key is present in the local wallet\n" + + HelpRequiringPassphrase() + "\n", + { + {"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the governance object"}, + {"vote", RPCArg::Type::STR, RPCArg::Optional::NO, "vote, possible values: [funding|valid|delete|endorsed]"}, + {"vote-outcome", RPCArg::Type::STR, RPCArg::Optional::NO, "vote outcome, possible values: [yes|no|abstain]"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_vote_many(const JSONRPCRequest& request) { + if (request.fHelp || request.params.size() != 4) + gobject_vote_many_help(request); + std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); + if (!wallet) return NullUniValue; CWallet* const pwallet = wallet.get(); - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; - - if (request.fHelp || request.params.size() != 4) - gobject_vote_many_help(pwallet); uint256 hash = ParseHashV(request.params[1], "Object hash"); std::string strVoteSignal = request.params[2].get_str(); @@ -661,32 +650,30 @@ static UniValue gobject_vote_many(const JSONRPCRequest& request) return VoteWithMasternodes(votingKeys, hash, eVoteSignal, eVoteOutcome); } -static void gobject_vote_alias_help(CWallet* const pwallet) +static void gobject_vote_alias_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject vote-alias", - "Vote on a governance object by masternode's voting key (if present in local wallet)\n" - + HelpRequiringPassphrase(pwallet) + "\n", - { - {"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the governance object"}, - {"vote", RPCArg::Type::STR, RPCArg::Optional::NO, "vote, possible values: [funding|valid|delete|endorsed]"}, - {"vote-outcome", RPCArg::Type::STR, RPCArg::Optional::NO, "vote outcome, possible values: [yes|no|abstain]"}, - {"protx-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "masternode's proTxHash"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject vote-alias", + "Vote on a governance object by masternode's voting key (if present in local wallet)\n" + + HelpRequiringPassphrase() + "\n", + { + {"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "hash of the governance object"}, + {"vote", RPCArg::Type::STR, RPCArg::Optional::NO, "vote, possible values: [funding|valid|delete|endorsed]"}, + {"vote-outcome", RPCArg::Type::STR, RPCArg::Optional::NO, "vote outcome, possible values: [yes|no|abstain]"}, + {"protx-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "masternode's proTxHash"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_vote_alias(const JSONRPCRequest& request) { + if (request.fHelp || request.params.size() != 5) + gobject_vote_alias_help(request); + std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); + if (!wallet) return NullUniValue; CWallet* const pwallet = wallet.get(); - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; - - if (request.fHelp || request.params.size() != 5) - gobject_vote_alias_help(pwallet); uint256 hash = ParseHashV(request.params[1], "Object hash"); std::string strVoteSignal = request.params[2].get_str(); @@ -782,24 +769,23 @@ static UniValue ListObjects(const std::string& strCachedSignal, const std::strin return objResult; } -static void gobject_list_help() +static void gobject_list_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject list", - "List governance objects (can be filtered by signal and/or object type)\n", - { - {"signal", RPCArg::Type::STR, /* default */ "valid", "cached signal, possible values: [valid|funding|delete|endorsed|all]"}, - {"type", RPCArg::Type::STR, /* default */ "all", "object type, possible values: [proposals|triggers|all]"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject list", + "List governance objects (can be filtered by signal and/or object type)\n", + { + {"signal", RPCArg::Type::STR, /* default */ "valid", "cached signal, possible values: [valid|funding|delete|endorsed|all]"}, + {"type", RPCArg::Type::STR, /* default */ "all", "object type, possible values: [proposals|triggers|all]"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_list(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() > 3) - gobject_list_help(); + gobject_list_help(request); std::string strCachedSignal = "valid"; if (!request.params[1].isNull()) { @@ -818,24 +804,23 @@ static UniValue gobject_list(const JSONRPCRequest& request) return ListObjects(strCachedSignal, strType, 0); } -static void gobject_diff_help() +static void gobject_diff_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject diff", - "List differences since last diff or list\n", - { - {"signal", RPCArg::Type::STR, /* default */ "valid", "cached signal, possible values: [valid|funding|delete|endorsed|all]"}, - {"type", RPCArg::Type::STR, /* default */ "all", "object type, possible values: [proposals|triggers|all]"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject diff", + "List differences since last diff or list\n", + { + {"signal", RPCArg::Type::STR, /* default */ "valid", "cached signal, possible values: [valid|funding|delete|endorsed|all]"}, + {"type", RPCArg::Type::STR, /* default */ "all", "object type, possible values: [proposals|triggers|all]"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_diff(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() > 3) - gobject_diff_help(); + gobject_diff_help(request); std::string strCachedSignal = "valid"; if (!request.params[1].isNull()) { @@ -854,23 +839,22 @@ static UniValue gobject_diff(const JSONRPCRequest& request) return ListObjects(strCachedSignal, strType, governance.GetLastDiffTime()); } -static void gobject_get_help() +static void gobject_get_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject get", - "Get governance object by hash\n", - { - {"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "object id"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject get", + "Get governance object by hash\n", + { + {"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "object id"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_get(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() != 2) - gobject_get_help(); + gobject_get_help(request); // COLLECT VARIABLES FROM OUR USER uint256 hash = ParseHashV(request.params[1], "GovObj hash"); @@ -946,25 +930,24 @@ static UniValue gobject_get(const JSONRPCRequest& request) return objResult; } -static void gobject_getcurrentvotes_help() +static void gobject_getcurrentvotes_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"gobject getcurrentvotes", - "Get only current (tallying) votes for a governance object hash (does not include old votes)\n", - { - {"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "object id"}, - {"txid", RPCArg::Type::STR_HEX, /* default */ "", "masternode collateral txid"}, - {"vout", RPCArg::Type::STR, /* default */ "", "masternode collateral output index, required if presents"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"gobject getcurrentvotes", + "Get only current (tallying) votes for a governance object hash (does not include old votes)\n", + { + {"governance-hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "object id"}, + {"txid", RPCArg::Type::STR_HEX, /* default */ "", "masternode collateral txid"}, + {"vout", RPCArg::Type::STR, /* default */ "", "masternode collateral output index, required if presents"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue gobject_getcurrentvotes(const JSONRPCRequest& request) { if (request.fHelp || (request.params.size() != 2 && request.params.size() != 4)) - gobject_getcurrentvotes_help(); + gobject_getcurrentvotes_help(request); // COLLECT PARAMETERS FROM USER @@ -1003,34 +986,33 @@ static UniValue gobject_getcurrentvotes(const JSONRPCRequest& request) [[ noreturn ]] static void gobject_help() { - throw std::runtime_error( - RPCHelpMan {"gobject", - "Set of commands to manage governance objects.\n" - "\nAvailable commands:\n" - " check - Validate governance object data (proposal only)\n" + RPCHelpMan {"gobject", + "Set of commands to manage governance objects.\n" + "\nAvailable commands:\n" + " check - Validate governance object data (proposal only)\n" #ifdef ENABLE_WALLET - " prepare - Prepare governance object by signing and creating tx\n" - " list-prepared - Returns a list of governance objects prepared by this wallet with \"gobject prepare\"\n" + " prepare - Prepare governance object by signing and creating tx\n" + " list-prepared - Returns a list of governance objects prepared by this wallet with \"gobject prepare\"\n" #endif // ENABLE_WALLET - " submit - Submit governance object to network\n" - " deserialize - Deserialize governance object from hex string to JSON\n" - " count - Count governance objects and votes (additional param: 'json' or 'all', default: 'json')\n" - " get - Get governance object by hash\n" - " getcurrentvotes - Get only current (tallying) votes for a governance object hash (does not include old votes)\n" - " list - List governance objects (can be filtered by signal and/or object type)\n" - " diff - List differences since last diff\n" + " submit - Submit governance object to network\n" + " deserialize - Deserialize governance object from hex string to JSON\n" + " count - Count governance objects and votes (additional param: 'json' or 'all', default: 'json')\n" + " get - Get governance object by hash\n" + " getcurrentvotes - Get only current (tallying) votes for a governance object hash (does not include old votes)\n" + " list - List governance objects (can be filtered by signal and/or object type)\n" + " diff - List differences since last diff\n" #ifdef ENABLE_WALLET - " vote-alias - Vote on a governance object by masternode proTxHash\n" + " vote-alias - Vote on a governance object by masternode proTxHash\n" #endif // ENABLE_WALLET - " vote-conf - Vote on a governance object by masternode configured in dash.conf\n" + " vote-conf - Vote on a governance object by masternode configured in dash.conf\n" #ifdef ENABLE_WALLET - " vote-many - Vote on a governance object by all masternodes for which the voting key is in the wallet\n" + " vote-many - Vote on a governance object by all masternodes for which the voting key is in the wallet\n" #endif // ENABLE_WALLET - , - {}, - RPCResults{}, - RPCExamples{""} - }.ToString()); + , + {}, + RPCResults{}, + RPCExamples{""} + }.Throw(); } static UniValue gobject(const JSONRPCRequest& request) @@ -1181,11 +1163,11 @@ static UniValue getgovernanceinfo(const JSONRPCRequest& request) {}, RPCResult{ "{\n" - " \"governanceminquorum\": xxxxx, (numeric) the absolute minimum number of votes needed to trigger a governance action\n" - " \"proposalfee\": xxx.xx, (numeric) the collateral transaction fee which must be paid to create a proposal in " + CURRENCY_UNIT + "\n" - " \"superblockcycle\": xxxxx, (numeric) the number of blocks between superblocks\n" - " \"lastsuperblock\": xxxxx, (numeric) the block number of the last superblock\n" - " \"nextsuperblock\": xxxxx, (numeric) the block number of the next superblock\n" + " \"governanceminquorum\" : xxxxx, (numeric) the absolute minimum number of votes needed to trigger a governance action\n" + " \"proposalfee\" : xxx.xx, (numeric) the collateral transaction fee which must be paid to create a proposal in " + CURRENCY_UNIT + "\n" + " \"superblockcycle\" : xxxxx, (numeric) the number of blocks between superblocks\n" + " \"lastsuperblock\" : xxxxx, (numeric) the block number of the last superblock\n" + " \"nextsuperblock\" : xxxxx, (numeric) the block number of the next superblock\n" "}\n" }, RPCExamples{ diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index f97b2e9af4df..f66d36fe0720 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -25,40 +25,39 @@ static UniValue masternodelist(const JSONRPCRequest& request); -static void masternode_list_help() +static void masternode_list_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"masternodelist", - "Get a list of masternodes in different modes. This call is identical to 'masternode list' call.\n" - "Available modes:\n" - " addr - Print ip address associated with a masternode (can be additionally filtered, partial match)\n" - " full - Print info in format 'status payee lastpaidtime lastpaidblock IP'\n" - " (can be additionally filtered, partial match)\n" - " info - Print info in format 'status payee IP'\n" - " (can be additionally filtered, partial match)\n" - " json - Print info in JSON format (can be additionally filtered, partial match)\n" - " lastpaidblock - Print the last block height a node was paid on the network\n" - " lastpaidtime - Print the last time a node was paid on the network\n" - " owneraddress - Print the masternode owner Dash address\n" - " payee - Print the masternode payout Dash address (can be additionally filtered,\n" - " partial match)\n" - " pubKeyOperator - Print the masternode operator public key\n" - " status - Print masternode status: ENABLED / POSE_BANNED\n" - " (can be additionally filtered, partial match)\n" - " votingaddress - Print the masternode voting Dash address\n", - { - {"mode", RPCArg::Type::STR, /* default */ "json", "The mode to run list in"}, - {"filter", RPCArg::Type::STR, /* default */ "", "Filter results. Partial match by outpoint by default in all modes, additional matches in some modes are also available"}, - }, - RPCResults{}, - RPCExamples{""}, - }.ToString()); + RPCHelpMan{"masternodelist", + "Get a list of masternodes in different modes. This call is identical to 'masternode list' call.\n" + "Available modes:\n" + " addr - Print ip address associated with a masternode (can be additionally filtered, partial match)\n" + " full - Print info in format 'status payee lastpaidtime lastpaidblock IP'\n" + " (can be additionally filtered, partial match)\n" + " info - Print info in format 'status payee IP'\n" + " (can be additionally filtered, partial match)\n" + " json - Print info in JSON format (can be additionally filtered, partial match)\n" + " lastpaidblock - Print the last block height a node was paid on the network\n" + " lastpaidtime - Print the last time a node was paid on the network\n" + " owneraddress - Print the masternode owner Dash address\n" + " payee - Print the masternode payout Dash address (can be additionally filtered,\n" + " partial match)\n" + " pubKeyOperator - Print the masternode operator public key\n" + " status - Print masternode status: ENABLED / POSE_BANNED\n" + " (can be additionally filtered, partial match)\n" + " votingaddress - Print the masternode voting Dash address\n", + { + {"mode", RPCArg::Type::STR, /* default */ "json", "The mode to run list in"}, + {"filter", RPCArg::Type::STR, /* default */ "", "Filter results. Partial match by outpoint by default in all modes, additional matches in some modes are also available"}, + }, + RPCResults{}, + RPCExamples{""}, + }.Check(request); } static UniValue masternode_list(const JSONRPCRequest& request) { if (request.fHelp) - masternode_list_help(); + masternode_list_help(request); JSONRPCRequest newRequest = request; newRequest.params.setArray(); // forward params but skip "list" @@ -68,23 +67,22 @@ static UniValue masternode_list(const JSONRPCRequest& request) return masternodelist(newRequest); } -static void masternode_connect_help() +static void masternode_connect_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"masternode connect", - "Connect to given masternode\n", - { - {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address of the masternode to connect"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"masternode connect", + "Connect to given masternode\n", + { + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address of the masternode to connect"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue masternode_connect(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() < 2) - masternode_connect_help(); + masternode_connect_help(request); std::string strAddress = request.params[1].get_str(); @@ -100,21 +98,20 @@ static UniValue masternode_connect(const JSONRPCRequest& request) return "successfully connected"; } -static void masternode_count_help() +static void masternode_count_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"masternode count", - "Get information about number of masternodes.\n", - {}, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"masternode count", + "Get information about number of masternodes.\n", + {}, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue masternode_count(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() > 1) - masternode_count_help(); + masternode_count_help(request); auto mnList = deterministicMNManager->GetListAtChainTip(); int total = mnList.GetAllMNsCount(); @@ -148,74 +145,69 @@ static UniValue GetNextMasternodeForPayment(int heightShift) return obj; } -static void masternode_winner_help() +static void masternode_winner_help(const JSONRPCRequest& request) { if (!IsDeprecatedRPCEnabled("masternode_winner")) { throw std::runtime_error("DEPRECATED: set -deprecatedrpc=masternode_winner to enable it"); } - throw std::runtime_error( - RPCHelpMan{"masternode winner", - "Print info on next masternode winner to vote for\n", - {}, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"masternode winner", + "Print info on next masternode winner to vote for\n", + {}, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue masternode_winner(const JSONRPCRequest& request) { if (request.fHelp || !IsDeprecatedRPCEnabled("masternode_winner")) - masternode_winner_help(); + masternode_winner_help(request); return GetNextMasternodeForPayment(10); } -static void masternode_current_help() +static void masternode_current_help(const JSONRPCRequest& request) { if (!IsDeprecatedRPCEnabled("masternode_current")) { throw std::runtime_error("DEPRECATED: set -deprecatedrpc=masternode_current to enable it"); } - throw std::runtime_error( - RPCHelpMan{"masternode current", - "Print info on current masternode winner to be paid the next block (calculated locally)\n", - {}, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"masternode current", + "Print info on current masternode winner to be paid the next block (calculated locally)\n", + {}, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue masternode_current(const JSONRPCRequest& request) { if (request.fHelp || !IsDeprecatedRPCEnabled("masternode_current")) - masternode_current_help(); + masternode_current_help(request); return GetNextMasternodeForPayment(1); } #ifdef ENABLE_WALLET -static void masternode_outputs_help() +static void masternode_outputs_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"masternode outputs", - "Print masternode compatible outputs\n", - {}, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"masternode outputs", + "Print masternode compatible outputs\n", + {}, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue masternode_outputs(const JSONRPCRequest& request) { - std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - CWallet* const pwallet = wallet.get(); - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) - return NullUniValue; - if (request.fHelp) - masternode_outputs_help(); + masternode_outputs_help(request); + std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); + if (!wallet) return NullUniValue; + CWallet* const pwallet = wallet.get(); // Find possible candidates std::vector vPossibleCoins; @@ -236,21 +228,20 @@ static UniValue masternode_outputs(const JSONRPCRequest& request) #endif // ENABLE_WALLET -static void masternode_status_help() +static void masternode_status_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"masternode status", - "Print masternode status information\n", - {}, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"masternode status", + "Print masternode status information\n", + {}, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue masternode_status(const JSONRPCRequest& request) { if (request.fHelp) - masternode_status_help(); + masternode_status_help(request); if (!fMasternodeMode) throw JSONRPCError(RPC_INTERNAL_ERROR, "This is not a masternode"); @@ -286,12 +277,12 @@ static std::string GetRequiredPaymentsString(int nBlockHeight, const CDeterminis if (payee) { CTxDestination dest; if (!ExtractDestination(payee->pdmnState->scriptPayout, dest)) { - assert(false); + CHECK_NONFATAL(false); } strPayments = EncodeDestination(dest); if (payee->nOperatorReward != 0 && payee->pdmnState->scriptOperatorPayout != CScript()) { if (!ExtractDestination(payee->pdmnState->scriptOperatorPayout, dest)) { - assert(false); + CHECK_NONFATAL(false); } strPayments += ", " + EncodeDestination(dest); } @@ -316,24 +307,23 @@ static std::string GetRequiredPaymentsString(int nBlockHeight, const CDeterminis return strPayments; } -static void masternode_winners_help() +static void masternode_winners_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"masternode winners", - "Print list of masternode winners\n", - { - {"count", RPCArg::Type::NUM, /* default */ "", "number of last winners to return"}, - {"filter", RPCArg::Type::STR, /* default */ "", "filter for returned winners"}, - }, - RPCResults{}, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"masternode winners", + "Print list of masternode winners\n", + { + {"count", RPCArg::Type::NUM, /* default */ "", "number of last winners to return"}, + {"filter", RPCArg::Type::STR, /* default */ "", "filter for returned winners"}, + }, + RPCResults{}, + RPCExamples{""} + }.Check(request); } static UniValue masternode_winners(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() > 3) - masternode_winners_help(); + masternode_winners_help(request); const CBlockIndex* pindexTip{nullptr}; { @@ -375,45 +365,44 @@ static UniValue masternode_winners(const JSONRPCRequest& request) return obj; } -static void masternode_payments_help() +static void masternode_payments_help(const JSONRPCRequest& request) { - throw std::runtime_error( - RPCHelpMan{"masternode payments", - "\nReturns an array of deterministic masternodes and their payments for the specified block\n", - { - {"blockhash", RPCArg::Type::STR_HEX, /* default */ "tip", "The hash of the starting block"}, - {"count", RPCArg::Type::NUM, /* default */ "1", "The number of blocks to return. Will return previous blocks if is negative. Both 1 and -1 correspond to the chain tip."}, - }, - RPCResult { - " [ (array) Blocks\n" - " {\n" - " \"height\" : n, (numeric) The height of the block\n" - " \"blockhash\" : \"hash\", (string) The hash of the block\n" - " \"amount\": n (numeric) Amount received in this block by all masternodes\n" - " \"masternodes\": [ (array) Masternodes that received payments in this block\n" - " {\n" - " \"proTxHash\": \"xxxx\", (string) The hash of the corresponding ProRegTx\n" - " \"amount\": n (numeric) Amount received by this masternode\n" - " \"payees\": [ (array) Payees who received a share of this payment\n" - " {\n" - " \"address\" : \"xxx\", (string) Payee address\n" - " \"script\" : \"xxx\", (string) Payee scriptPubKey\n" - " \"amount\": n (numeric) Amount received by this payee\n" - " },...\n" - " ]\n" - " },...\n" - " ]\n" - " },...\n" - " ]" - }, - RPCExamples{""} - }.ToString()); + RPCHelpMan{"masternode payments", + "\nReturns an array of deterministic masternodes and their payments for the specified block\n", + { + {"blockhash", RPCArg::Type::STR_HEX, /* default */ "tip", "The hash of the starting block"}, + {"count", RPCArg::Type::NUM, /* default */ "1", "The number of blocks to return. Will return previous blocks if is negative. Both 1 and -1 correspond to the chain tip."}, + }, + RPCResult { + " [ (json array) Blocks\n" + " {\n" + " \"height\" : n, (numeric) The height of the block\n" + " \"blockhash\" : \"hash\", (string) The hash of the block\n" + " \"amount\" : n (numeric) Amount received in this block by all masternodes\n" + " \"masternodes\" : [ (json array) Masternodes that received payments in this block\n" + " {\n" + " \"proTxHash\" : \"xxxx\", (string) The hash of the corresponding ProRegTx\n" + " \"amount\" : n (numeric) Amount received by this masternode\n" + " \"payees\" : [ (json array) Payees who received a share of this payment\n" + " {\n" + " \"address\" : \"xxx\", (string) Payee address\n" + " \"script\" : \"xxx\", (string) Payee scriptPubKey\n" + " \"amount\" : n (numeric) Amount received by this payee\n" + " },...\n" + " ]\n" + " },...\n" + " ]\n" + " },...\n" + " ]" + }, + RPCExamples{""} + }.Check(request); } static UniValue masternode_payments(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() > 3) { - masternode_payments_help(); + masternode_payments_help(request); } CBlockIndex* pindex{nullptr}; @@ -522,26 +511,25 @@ static UniValue masternode_payments(const JSONRPCRequest& request) [[ noreturn ]] static void masternode_help() { - throw std::runtime_error( - RPCHelpMan{"masternode", - "Set of commands to execute masternode related actions\n" - "\nAvailable commands:\n" - " count - Get information about number of masternodes\n" - " current - DEPRECATED Print info on current masternode winner to be paid the next block (calculated locally)\n" + RPCHelpMan{"masternode", + "Set of commands to execute masternode related actions\n" + "\nAvailable commands:\n" + " count - Get information about number of masternodes\n" + " current - DEPRECATED Print info on current masternode winner to be paid the next block (calculated locally)\n" #ifdef ENABLE_WALLET - " outputs - Print masternode compatible outputs\n" + " outputs - Print masternode compatible outputs\n" #endif // ENABLE_WALLET - " status - Print masternode status information\n" - " list - Print list of all known masternodes (see masternodelist for more info)\n" - " payments - Return information about masternode payments in a mined block\n" - " winner - DEPRECATED Print info on next masternode winner to vote for\n" - " winners - Print list of masternode winners\n", - { - {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "The command to execute"}, - }, - RPCResults{}, - RPCExamples{""}, - }.ToString()); + " status - Print masternode status information\n" + " list - Print list of all known masternodes (see masternodelist for more info)\n" + " payments - Return information about masternode payments in a mined block\n" + " winner - DEPRECATED Print info on next masternode winner to vote for\n" + " winners - Print list of masternode winners\n", + { + {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "The command to execute"}, + }, + RPCResults{}, + RPCExamples{""}, + }.Throw(); } static UniValue masternode(const JSONRPCRequest& request) @@ -597,7 +585,7 @@ static UniValue masternodelist(const JSONRPCRequest& request) strMode != "payee" && strMode != "pubkeyoperator" && strMode != "status")) { - masternode_list_help(); + masternode_list_help(request); } UniValue obj(UniValue::VOBJ); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 0918a53db425..378b4afa7fe8 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -93,8 +93,7 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request) {"height", RPCArg::Type::NUM, /* default */ "-1", "To estimate at the time of the given height."}, }, RPCResult{ - "x (numeric) Hashes per second estimated\n" - }, + RPCResult::Type::NUM, "", "Hashes per second estimated"}, RPCExamples{ HelpExampleCli("getnetworkhashps", "") + HelpExampleRpc("getnetworkhashps", "") @@ -166,8 +165,10 @@ static UniValue generatetoaddress(const JSONRPCRequest& request) {"maxtries", RPCArg::Type::NUM, /* default */ "1000000", "How many iterations to try."}, }, RPCResult{ - "[ blockhashes ] (array) hashes of blocks generated\n" - }, + RPCResult::Type::ARR, "", "hashes of blocks generated", + { + {RPCResult::Type::STR_HEX, "", "blockhash"}, + }}, RPCExamples{ "\nGenerate 11 blocks to myaddress\n" + HelpExampleCli("generatetoaddress", "11 \"myaddress\"") @@ -206,14 +207,14 @@ static UniValue getmininginfo(const JSONRPCRequest& request) {}, 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 as defined in BIP70 (main, test, regtest)\n" - " \"warnings\": \"...\" (string) any network and blockchain warnings\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 as defined in BIP70 (main, test, regtest)\n" + " \"warnings\" : \"...\" (string) any network and blockchain warnings\n" "}\n" }, RPCExamples{ @@ -253,8 +254,7 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request) " considers the transaction as it would have paid a higher (or lower) fee."}, }, RPCResult{ - "true (boolean) Returns true\n" - }, + RPCResult::Type::BOOL, "", "Returns true"}, RPCExamples{ HelpExampleCli("prioritisetransaction", "\"txid\" 10000") + HelpExampleRpc("prioritisetransaction", "\"txid\", 10000") @@ -338,15 +338,15 @@ static UniValue getblocktemplate(const JSONRPCRequest& request) " },\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\" : [ (array) contents of non-coinbase transactions that should be included in the next 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\" : [ (array) array of numbers \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" + " \"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" @@ -367,20 +367,20 @@ static UniValue getblocktemplate(const JSONRPCRequest& request) " \"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\" : [ (array) required masternode payments that must be included in 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" + " \"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\" : [ (array) required superblock payees that must be included in the next block\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" + " \"amount\" : n (numeric) required amount to pay\n" " }\n" " ,...\n" " ],\n" @@ -549,7 +549,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request) // Need to update only after we know CreateNewBlock succeeded pindexPrev = pindexPrevNew; } - assert(pindexPrev); + CHECK_NONFATAL(pindexPrev); CBlock* pblock = &pblocktemplate->block; // pointer for convenience const Consensus::Params& consensusParams = Params().GetConsensus(); @@ -798,8 +798,7 @@ static UniValue submitheader(const JSONRPCRequest& request) {"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded block header data"}, }, RPCResult{ - "None" - }, + RPCResult::Type::NONE, "", "None"}, RPCExamples{ HelpExampleCli("submitheader", "\"aabbcc\"") + HelpExampleRpc("submitheader", "\"aabbcc\"") @@ -848,17 +847,19 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request) " \"CONSERVATIVE\""}, }, RPCResult{ - "{\n" - " \"feerate\" : x.x, (numeric, optional) estimate fee rate in " + CURRENCY_UNIT + "/kB\n" - " \"errors\": [ str... ] (json array of strings, optional) Errors encountered during processing\n" - " \"blocks\" : n (numeric) block number where estimate was found\n" - "}\n" - "\n" + 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::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.\n" - }, + "have been observed to make an estimate for any number of blocks."}, + }}, RPCExamples{ HelpExampleCli("estimatesmartfee", "6") }, @@ -923,7 +924,7 @@ static UniValue estimaterawfee(const JSONRPCRequest& request) " \"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" + " \"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" diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index b0151dc7ec36..8db23379dafc 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -15,8 +15,9 @@ #include #include