diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -88,28 +88,26 @@ static UniValue getnetworkhashps(const Config &config, 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{"x (numeric) Hashes per second estimated\n"}, - 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{"x (numeric) Hashes per second estimated\n"}, + RPCExamples{HelpExampleCli("getnetworkhashps", "") + + HelpExampleRpc("getnetworkhashps", "")}, + } + .Check(request); LOCK(cs_main); return GetNetworkHashPS( @@ -188,31 +186,27 @@ static UniValue generatetoaddress(const Config &config, 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 bitcoin to."}, - {"maxtries", RPCArg::Type::NUM, /* default */ "1000000", - "How many iterations to try."}, - }, - RPCResult{ - "[ blockhashes ] (array) hashes of blocks generated\n"}, - RPCExamples{ - "\nGenerate 11 blocks to myaddress\n" + - HelpExampleCli("generatetoaddress", "11 \"myaddress\"") + - "If you are running the bitcoin core wallet, you can get a new " - "address to send the newly generated bitcoin to with:\n" + - HelpExampleCli("getnewaddress", "")}, - } - .ToString()); - } + 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 bitcoin to."}, + {"maxtries", RPCArg::Type::NUM, /* default */ "1000000", + "How many iterations to try."}, + }, + RPCResult{"[ blockhashes ] (array) hashes of blocks generated\n"}, + RPCExamples{ + "\nGenerate 11 blocks to myaddress\n" + + HelpExampleCli("generatetoaddress", "11 \"myaddress\"") + + "If you are running the bitcoin core wallet, you can get a new " + "address to send the newly generated bitcoin to with:\n" + + HelpExampleCli("getnewaddress", "")}, + } + .Check(request); int nGenerate = request.params[0].get_int(); uint64_t nMaxTries = 1000000; @@ -236,37 +230,33 @@ static UniValue getmininginfo(const Config &config, 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 as defined in BIP70 (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 as " + "defined in BIP70 (main, test, regtest)\n" + " \"warnings\": \"...\" (string) any network and " + "blockchain warnings\n" + "}\n"}, + RPCExamples{HelpExampleCli("getmininginfo", "") + + HelpExampleRpc("getmininginfo", "")}, + } + .Check(request); LOCK(cs_main); @@ -291,37 +281,30 @@ // 22) in using satoshi amounts static UniValue prioritisetransaction(const Config &config, const JSONRPCRequest &request) { - if (request.fHelp || request.params.size() != 3) { - 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."}, - {"dummy", RPCArg::Type::NUM, - RPCArg::Optional::OMITTED_NAMED_ARG, - "API-Compatibility for previous API. Must be zero or " - "null.\n" - " DEPRECATED. For forward compatibility " - "use named arguments and omit this parameter."}, - {"fee_delta", RPCArg::Type::NUM, RPCArg::Optional::NO, - "The fee value (in satoshis) to add (or subtract, if " - "negative).\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{"true (boolean) Returns true\n"}, - RPCExamples{ - HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000") + - HelpExampleRpc("prioritisetransaction", - "\"txid\", 0.0, 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."}, + {"dummy", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, + "API-Compatibility for previous API. Must be zero or null.\n" + " DEPRECATED. For forward compatibility " + "use named arguments and omit this parameter."}, + {"fee_delta", RPCArg::Type::NUM, RPCArg::Optional::NO, + "The fee value (in satoshis) to add (or subtract, if negative).\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{"true (boolean) Returns true\n"}, + RPCExamples{ + HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000") + + HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")}, + } + .Check(request); LOCK(cs_main); @@ -364,129 +347,124 @@ static UniValue getblocktemplate(const Config &config, 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, 9, and 145:\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, - "{}", - "A json object in the following spec", + 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, 9, and 145:\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, + "{}", + "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"}, { - {"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", { - "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'"}, - }, + {"support", RPCArg::Type::STR, + RPCArg::Optional::OMITTED, + "client side supported feature, 'longpoll', " + "'coinbasetxn', 'coinbasevalue', 'proposal', " + "'serverlist', 'workid'"}, }, }, - "\"template_request\""}, - }, - RPCResult{ - "{\n" - " \"version\" : n, (numeric) The preferred " - "block version\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" - " {\n" - " \"data\" : \"xxxx\", (string) " - "transaction data encoded in hexadecimal (byte-for-byte)\n" - " \"txid\" : \"xxxx\", (string) " - "transaction id encoded in little-endian hexadecimal\n" - " \"hash\" : \"xxxx\", (string) hash " - "encoded in little-endian hexadecimal (including witness " - "data)\n" - " \"depends\" : [ (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 " - "satoshis); 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 " - "SigOps count, as counted for purposes of block limits; if key " - "is not present, sigop count is unknown and clients MUST NOT " - "assume it is zero\n" - " }\n" - " ,...\n" - " ],\n" - " \"coinbaseaux\" : { (json object) data that " - "should be included in the coinbase's scriptSig content\n" - " \"flags\" : \"xx\" (string) key name " - "is to be ignored, and value included in scriptSig\n" - " },\n" - " \"coinbasevalue\" : n, (numeric) maximum " - "allowable input to coinbase transaction, including the " - "generation award and transaction fees (in satoshis)\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" - " \"height\" : n (numeric) The height of " - "the next block\n" - "}\n"}, - RPCExamples{HelpExampleCli("getblocktemplate", "") + - HelpExampleRpc("getblocktemplate", "")}, - } - .ToString()); - } + }, + "\"template_request\""}, + }, + RPCResult{ + "{\n" + " \"version\" : n, (numeric) The preferred " + "block version\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" + " {\n" + " \"data\" : \"xxxx\", (string) transaction " + "data encoded in hexadecimal (byte-for-byte)\n" + " \"txid\" : \"xxxx\", (string) transaction id " + "encoded in little-endian hexadecimal\n" + " \"hash\" : \"xxxx\", (string) hash encoded " + "in little-endian hexadecimal\n" + " \"depends\" : [ (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 satoshis); 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 SigOps " + "count, as counted for purposes of block limits; if key is not " + "present, sigop count is unknown and clients MUST NOT assume it is " + "zero\n" + " }\n" + " ,...\n" + " ],\n" + " \"coinbaseaux\" : { (json object) data that " + "should be included in the coinbase's scriptSig content\n" + " \"flags\" : \"xx\" (string) key name is to " + "be ignored, and value included in scriptSig\n" + " },\n" + " \"coinbasevalue\" : n, (numeric) maximum allowable " + "input to coinbase transaction, including the generation award and " + "transaction fees (in satoshis)\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" + " \"height\" : n (numeric) The height of the " + "next block\n" + "}\n"}, + RPCExamples{HelpExampleCli("getblocktemplate", "") + + HelpExampleRpc("getblocktemplate", "")}, + } + .Check(request); LOCK(cs_main); @@ -740,26 +718,22 @@ static UniValue submitblock(const Config &config, 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."}, - }, - RPCResults{}, - 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."}, + }, + RPCResults{}, + RPCExamples{HelpExampleCli("submitblock", "\"mydata\"") + + HelpExampleRpc("submitblock", "\"mydata\"")}, + } + .Check(request); std::shared_ptr blockptr = std::make_shared(); CBlock &block = *blockptr; @@ -811,22 +785,20 @@ static UniValue submitheader(const Config &config, 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{"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{"None"}, + RPCExamples{HelpExampleCli("submitheader", "\"aabbcc\"") + + HelpExampleRpc("submitheader", "\"aabbcc\"")}, } + .Check(request); CBlockHeader h; if (!DecodeHexBlockHeader(h, request.params[0].get_str())) { @@ -856,17 +828,15 @@ static UniValue estimatefee(const Config &config, const JSONRPCRequest &request) { - if (request.fHelp || request.params.size() > 0) { - throw std::runtime_error(RPCHelpMan{ - "estimatefee", - "\nEstimates the approximate fee per kilobyte needed " - "for a transaction\n", - {}, - RPCResult{"n (numeric) estimated fee-per-kilobyte\n"}, - RPCExamples{HelpExampleCli("estimatefee", "")}, - } - .ToString()); - } + RPCHelpMan{ + "estimatefee", + "\nEstimates the approximate fee per kilobyte needed for a " + "transaction\n", + {}, + RPCResult{"n (numeric) estimated fee-per-kilobyte\n"}, + RPCExamples{HelpExampleCli("estimatefee", "")}, + } + .Check(request); return ValueFromAmount(g_mempool.estimateFee().GetFeePerK()); }