diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -96,15 +96,15 @@ "Pass in [height] to estimate the network speed at the " "time when a certain block was found.\n", { - {"nblocks", RPCArg::Type::NUM, true}, - {"height", RPCArg::Type::NUM, true}, + {"nblocks", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "120", + "The number of blocks, or -1 for blocks since last " + "difficulty change."}, + {"height", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "-1", + "To estimate at the time of the given height."}, }} - .ToString() + - "\nArguments:\n" - "1. nblocks (numeric, optional, default=120) The number of " - "blocks, or -1 for blocks since last difficulty change.\n" - "2. height (numeric, optional, default=-1) To estimate at the " - "time of the given height.\n" + .ToStringWithArgs() + "\nResult:\n" "x (numeric) Hashes per second estimated\n" "\nExamples:\n" + @@ -190,22 +190,22 @@ 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, false}, - {"address", RPCArg::Type::STR, false}, - {"maxtries", RPCArg::Type::NUM, true}, - }} - .ToString() + - "\nArguments:\n" - "1. nblocks (numeric, required) How many blocks are generated " - "immediately.\n" - "2. address (string, required) The address to send the newly " - "generated bitcoin to.\n" - "3. maxtries (numeric, optional) How many iterations to try " - "(default = 1000000).\n" + RPCHelpMan{ + "generatetoaddress", + "\nMine blocks immediately to a specified address before the " + "RPC call returns)\n", + { + {"nblocks", RPCArg::Type::NUM, /* opt */ false, + /* default_val */ "", + "How many blocks are generated immediately."}, + {"address", RPCArg::Type::STR, /* opt */ false, + /* default_val */ "", + "The address to send the newly generated bitcoin to."}, + {"maxtries", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "1000000", + "How many iterations to try."}, + }} + .ToStringWithArgs() + "\nResult:\n" "[ blockhashes ] (array) hashes of blocks generated\n" "\nExamples:\n" @@ -241,7 +241,7 @@ "\nReturns a json object containing mining-related " "information.", {}} - .ToString() + + .ToStringWithArgs() + "\nResult:\n" "{\n" " \"blocks\": nnn, (numeric) The current block\n" @@ -283,27 +283,30 @@ 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, false}, - {"dummy", RPCArg::Type::NUM, false}, - {"fee_delta", RPCArg::Type::NUM, false}, - }} - .ToString() + - "\nArguments:\n" - "1. \"txid\" (string, required) The transaction id.\n" - "2. dummy (numeric, optional) API-Compatibility for " - "previous API. Must be zero or null.\n" - " DEPRECATED. For forward compatibility use named " - "arguments and omit this parameter.\n" - "3. fee_delta (numeric, required) 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.\n" + RPCHelpMan{ + "prioritisetransaction", + "Accepts the transaction into mined blocks at a higher " + "(or lower) priority\n", + { + {"txid", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", "The transaction id."}, + {"dummy", RPCArg::Type::NUM, /* opt */ true, + /* default_val */ "null", + "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, /* opt */ false, + /* default_val */ "", + "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."}, + }} + .ToStringWithArgs() + "\nResult:\n" "true (boolean) Returns true\n" "\nExamples:\n" + @@ -374,35 +377,32 @@ { {"template_request", RPCArg::Type::OBJ, + /* opt */ true, + /* default_val */ "", + "A json object in the following spec", { - {"mode", RPCArg::Type::STR, true}, - {"capabilities", - RPCArg::Type::ARR, - { - {"support", RPCArg::Type::STR, true}, - }, - true}, + {"mode", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", + "This must be set to \"template\", \"proposal\" (see " + "BIP 23), or omitted"}, + { + "capabilities", + RPCArg::Type::ARR, + /* opt */ true, + /* default_val */ "", + "A list of strings", + { + {"support", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", + "client side supported feature, 'longpoll', " + "'coinbasetxn', 'coinbasevalue', 'proposal', " + "'serverlist', 'workid'"}, + }, + }, }, - true, "\"template_request\""}, }} - .ToString() + - "\nArguments:\n" - "1. template_request (json object, optional) A json object " - "in the following spec\n" - " {\n" - " \"mode\":\"template\" (string, optional) This must be " - "set to \"template\", \"proposal\" (see BIP 23), or omitted\n" - " \"capabilities\":[ (array, optional) A list of " - "strings\n" - " \"support\" (string) client side supported " - "feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', " - "'serverlist', 'workid'\n" - " ,...\n" - " ]\n" - " }\n" - "\n" - + .ToStringWithArgs() + "\nResult:\n" "{\n" " \"version\" : n, (numeric) The preferred " @@ -739,15 +739,15 @@ "See https://en.bitcoin.it/wiki/BIP_0022 for full " "specification.\n", { - {"hexdata", RPCArg::Type::STR_HEX, false}, - {"dummy", RPCArg::Type::STR, true}, + {"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, + /* default_val */ "", + "the hex-encoded block data to submit"}, + {"dummy", RPCArg::Type::STR, /* opt */ true, + /* default_val */ "", + "dummy value, for compatibility with BIP22. This " + "value is ignored."}, }} - .ToString() + - "\nArguments\n" - "1. \"hexdata\" (string, required) the hex-encoded block " - "data to submit\n" - "2. \"dummy\" (optional) dummy value, for compatibility " - "with BIP22. This value is ignored.\n" + .ToStringWithArgs() + "\nResult:\n" "\nExamples:\n" + HelpExampleCli("submitblock", "\"mydata\"") + @@ -806,17 +806,16 @@ 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, false}, - }} - .ToString() + - "\nArguments\n" - "1. \"hexdata\" (string, required) the " - "hex-encoded block header data\n" + 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, /* opt */ false, + /* default_val */ "", "the hex-encoded block header data"}, + }} + .ToStringWithArgs() + "\nResult:\n" "None" "\nExamples:\n" + @@ -858,7 +857,7 @@ "\nEstimates the approximate fee per kilobyte needed " "for a transaction\n", {}} - .ToString() + + .ToStringWithArgs() + "\nResult:\n" "n (numeric) estimated fee-per-kilobyte\n" "\nExample:\n" + diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -292,24 +292,23 @@ // Oneline summary ret += m_name; - bool is_optional{false}; + bool was_optional{false}; for (const auto &arg : m_args) { ret += " "; if (arg.m_optional) { - if (!is_optional) { + if (!was_optional) { ret += "( "; } - is_optional = true; + was_optional = true; } else { - // Currently we still support unnamed arguments, so any argument - // following an optional argument must also be optional If support - // for positional arguments is deprecated in the future, remove this - // line - assert(!is_optional); + if (was_optional) { + ret += ") "; + } + was_optional = false; } ret += arg.ToString(/* oneline */ true); } - if (is_optional) { + if (was_optional) { ret += " )"; } ret += "\n"; @@ -327,13 +326,8 @@ } // Push named argument name and description - const auto str_wrapper = (arg.m_type == RPCArg::Type::STR || - arg.m_type == RPCArg::Type::STR_HEX) - ? "\"" - : ""; sections.m_sections.emplace_back(std::to_string(i + 1) + ". " + - str_wrapper + arg.m_name + - str_wrapper, + arg.m_name, arg.ToDescriptionString()); sections.m_max_pad = std::max(sections.m_max_pad, sections.m_sections.back().m_left.size());