diff --git a/src/rpc/abc.cpp b/src/rpc/abc.cpp --- a/src/rpc/abc.cpp +++ b/src/rpc/abc.cpp @@ -39,8 +39,7 @@ "in the active chain or relayed. This discourages the propagation " "of blocks that you consider excessively large.", { - {"blockSize", RPCArg::Type::NUM, /* opt */ false, - /* default_value */ "", + {"blockSize", RPCArg::Type::NUM, RPCArg::Optional::NO, "Excessive block size in bytes. Must be greater than " + std::to_string(LEGACY_MAX_BLOCK_SIZE) + "."}, }, diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -38,10 +38,10 @@ "addavalanchepeer", "\nAdd a peer to the set of peer to poll for avalanche.\n", { - {"nodeid", RPCArg::Type::NUM, /* opt */ false, - /* default_value */ "", "Node to be added to avalanche."}, - {"publickey", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_value */ "", "The public key of the node."}, + {"nodeid", RPCArg::Type::NUM, RPCArg::Optional::NO, + "Node to be added to avalanche."}, + {"publickey", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "The public key of the node."}, }, RPCResults{}, RPCExamples{HelpExampleRpc("addavalanchepeer", "5")}, diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -229,8 +229,7 @@ "info about it.\n" "\nReturns the current block on timeout or exit.\n", { - {"timeout", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", + {"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no " "timeout."}, }, @@ -282,10 +281,9 @@ "info about it.\n" "\nReturns the current block on timeout or exit.\n", { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "Block hash to wait for."}, - {"timeout", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "Block hash to wait for."}, + {"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 " "indicates no timeout."}, }, @@ -345,10 +343,9 @@ "height and hash\nof the current tip.\n" "\nReturns the current block on timeout or exit.\n", { - {"height", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "Block height to wait for."}, - {"timeout", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", + {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, + "Block height to wait for."}, + {"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 " "indicates no timeout."}, }, @@ -565,8 +562,7 @@ "\nHint: use getmempoolentry to fetch a specific " "transaction from the mempool.\n", { - {"verbose", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", + {"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of " "transaction ids"}, }, @@ -604,11 +600,9 @@ "\nIf txid is in the mempool, returns all in-mempool " "ancestors.\n", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"}, - {"verbose", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", + {"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of " "transaction ids"}, }, @@ -683,11 +677,9 @@ "\nIf txid is in the mempool, returns all in-mempool " "descendants.\n", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"}, - {"verbose", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", + {"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of " "transaction ids"}, }, @@ -759,8 +751,7 @@ "getmempoolentry", "\nReturns mempool data for given transaction\n", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"}, }, RPCResult{"{ (json object)\n" + @@ -795,8 +786,8 @@ "\nReturns hash of block in best-block-chain at height " "provided.\n", { - {"height", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "The height index"}, + {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, + "The height index"}, }, RPCResult{"\"hash\" (string) The block hash\n"}, RPCExamples{HelpExampleCli("getblockhash", "1000") + @@ -827,10 +818,9 @@ "If verbose is true, returns an Object with information " "about blockheader .\n", { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The block hash"}, - {"verbose", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "The block hash"}, + {"verbose", RPCArg::Type::BOOL, /* default */ "true", "true for a json object, false for the hex-encoded data"}, }, { @@ -941,10 +931,9 @@ "If verbosity is 2, returns an Object with information about " "block and information about each transaction.\n", { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The block hash"}, - {"verbosity", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "1", + {"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"}, }, @@ -1051,8 +1040,7 @@ "pruneblockchain", "", { - {"height", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", + {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "The block height to prune up to. May be set to a discrete " "height, or a unix timestamp\n" " to prune blocks whose block time is at " @@ -1170,12 +1158,10 @@ "gettxout", "\nReturns details about an unspent transaction output.\n", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The transaction id"}, - {"n", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "vout number"}, - {"include_mempool", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "The transaction id"}, + {"n", RPCArg::Type::NUM, RPCArg::Optional::NO, "vout number"}, + {"include_mempool", RPCArg::Type::BOOL, /* default */ "true", "Whether to include the mempool. Note that an unspent " "output that is spent in the mempool won't appear."}, }, @@ -1264,11 +1250,11 @@ "verifychain", "\nVerifies blockchain database.\n", { - {"checklevel", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ strprintf("%d, range=0-4", nCheckLevel), + {"checklevel", RPCArg::Type::NUM, + /* default */ strprintf("%d, range=0-4", nCheckLevel), "How thorough the block verification is."}, - {"nblocks", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ strprintf("%d, 0=all", nCheckDepth), + {"nblocks", RPCArg::Type::NUM, + /* default */ strprintf("%d, 0=all", nCheckDepth), "The number of blocks to check."}, }, RPCResult{"true|false (boolean) Verified or not\n"}, @@ -1698,8 +1684,7 @@ "\nThe effects of preciousblock are not retained across " "restarts.\n", { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as precious"}, }, RPCResults{}, @@ -1739,8 +1724,7 @@ "work chain, it can effectively PUTS YOU OUT OF CONSENSUS.\n" "USE WITH CAUTION!\n", { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as invalid"}, }, RPCResults{}, @@ -1783,8 +1767,7 @@ "\nPermanently marks a block as invalid, as if it " "violated a consensus rule.\n", { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as invalid"}, }, RPCResults{}, @@ -1824,8 +1807,8 @@ "parkblock", "\nMarks a block as parked.\n", { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "the hash of the block to park"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "the hash of the block to park"}, }, RPCResults{}, RPCExamples{HelpExampleCli("parkblock", "\"blockhash\"") + @@ -1869,8 +1852,8 @@ "reconsider them for activation.\n" "This can be used to undo the effects of invalidateblock.\n", { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "the hash of the block to reconsider"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "the hash of the block to reconsider"}, }, RPCResults{}, RPCExamples{HelpExampleCli("reconsiderblock", "\"blockhash\"") + @@ -1909,8 +1892,8 @@ "reconsider them for activation.\n" "This can be used to undo the effects of parkblock.\n", { - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "the hash of the block to unpark"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "the hash of the block to unpark"}, }, RPCResults{}, RPCExamples{HelpExampleCli("unparkblock", "\"blockhash\"") + @@ -1950,11 +1933,9 @@ "\nCompute statistics about the total number and rate " "of transactions in the chain.\n", { - {"nblocks", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "one month", + {"nblocks", RPCArg::Type::NUM, /* default */ "one month", "Size of the window in number of blocks"}, - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, - /* default_val */ "chain tip", + {"blockhash", RPCArg::Type::STR_HEX, /* default */ "chain tip", "The hash of the block that ends the window."}, }, RPCResult{ @@ -2086,21 +2067,19 @@ { {"hash_or_height", RPCArg::Type::NUM, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "The block hash or height of the target block", "", {"", "string or numeric"}}, {"stats", RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "all values", + /* default */ "all values", "Values to plot (see result below)", { - {"height", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", "Selected statistic"}, - {"time", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", "Selected statistic"}, + {"height", RPCArg::Type::STR, RPCArg::Optional::OMITTED, + "Selected statistic"}, + {"time", RPCArg::Type::STR, RPCArg::Optional::OMITTED, + "Selected statistic"}, }, "stats"}, }, @@ -2508,8 +2487,7 @@ "For more information on output descriptors, see the " "documentation in the doc/descriptors.md file.\n", { - {"action", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"action", RPCArg::Type::STR, RPCArg::Optional::NO, "The action to execute\n" " \"start\" for " "starting a scan\n" @@ -2520,25 +2498,22 @@ "progress report (in %) of the current scan"}, {"scanobjects", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "Array of scan objects\n" " Every scan object is " "either a string descriptor or an object:", { - {"descriptor", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", "An output descriptor"}, + {"descriptor", RPCArg::Type::STR, + RPCArg::Optional::OMITTED, "An output descriptor"}, { "", RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", + RPCArg::Optional::OMITTED, "An object with output descriptor and metadata", { - {"desc", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "An output descriptor"}, - {"range", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "1000", + {"desc", RPCArg::Type::STR, RPCArg::Optional::NO, + "An output descriptor"}, + {"range", RPCArg::Type::NUM, /* default */ "1000", "Up to what child index HD chains should be " "explored"}, }, diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -97,12 +97,10 @@ "Pass in [height] to estimate the network speed at the " "time when a certain block was found.\n", { - {"nblocks", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "120", + {"nblocks", RPCArg::Type::NUM, /* default */ "120", "The number of blocks, or -1 for blocks since last " "difficulty change."}, - {"height", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "-1", + {"height", RPCArg::Type::NUM, /* default */ "-1", "To estimate at the time of the given height."}, }, RPCResult{"x (numeric) Hashes per second estimated\n"}, @@ -196,14 +194,12 @@ "\nMine blocks immediately to a specified address before the " "RPC call returns)\n", { - {"nblocks", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", + {"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."}, - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address to send the newly generated bitcoin to."}, - {"maxtries", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "1000000", "How many iterations to try."}, + {"maxtries", RPCArg::Type::NUM, /* default */ "1000000", + "How many iterations to try."}, }, RPCResult{ "[ blockhashes ] (array) hashes of blocks generated\n"}, @@ -300,16 +296,15 @@ "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", + {"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, /* opt */ false, - /* default_val */ "", + {"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, " @@ -389,23 +384,22 @@ { {"template_request", RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", + "{}", "A json object in the following spec", { - {"mode", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", + {"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, - /* opt */ true, - /* default_val */ "", + /* treat as named arg */ + RPCArg::Optional::OMITTED_NAMED_ARG, "A list of strings", { - {"support", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", + {"support", RPCArg::Type::STR, + RPCArg::Optional::OMITTED, "client side supported feature, 'longpoll', " "'coinbasetxn', 'coinbasevalue', 'proposal', " "'serverlist', 'workid'"}, @@ -753,10 +747,9 @@ "See https://en.bitcoin.it/wiki/BIP_0022 for full " "specification.\n", { - {"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "the hex-encoded block data to submit"}, - {"dummy", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "ignored", + {"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "the hex-encoded block data to submit"}, + {"dummy", RPCArg::Type::STR, /* default */ "ignored", "dummy value, for compatibility with BIP22. This value is " "ignored."}, }, @@ -824,8 +817,8 @@ "candidate chain tip if valid." "\nThrows when the header is invalid.\n", { - {"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "the hex-encoded block header data"}, + {"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "the hex-encoded block header data"}, }, RPCResult{"None"}, RPCExamples{HelpExampleCli("submitheader", "\"aabbcc\"") + diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -39,8 +39,8 @@ "validateaddress", "\nReturn information about the given bitcoin address.\n", { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The bitcoin address to validate"}, + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, + "The bitcoin address to validate"}, }, RPCResult{ "{\n" @@ -96,17 +96,16 @@ "keys required.\n" "It returns a json object with the address and redeemScript.\n", { - {"nrequired", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", + {"nrequired", RPCArg::Type::NUM, RPCArg::Optional::NO, "The number of required signatures out of the n keys."}, {"keys", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "A json array of hex-encoded public keys.", { - {"key", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The hex-encoded public key"}, + {"key", RPCArg::Type::STR_HEX, + RPCArg::Optional::OMITTED, + "The hex-encoded public key"}, }}, }, RPCResult{"{\n" @@ -193,14 +192,17 @@ "a hardened child key.\n" "For more information on output descriptors, see the " "documentation in the doc/descriptors.md file.\n"}, - {{"descriptor", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The descriptor."}, - {"begin", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", - "If a ranged descriptor is used, this specifies the beginning of " - "the range to import."}, - {"end", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", - "If a ranged descriptor is used, this specifies the end of the " - "range to import."}}, + { + {"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, + "The descriptor."}, + {"begin", RPCArg::Type::NUM, + RPCArg::Optional::OMITTED_NAMED_ARG, + "If a ranged descriptor is used, this specifies the beginning " + "of the range to import."}, + {"end", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, + "If a ranged descriptor is used, this specifies the end of " + "the range to import."}, + }, RPCResult{"[ address ] (array) the derived addresses\n"}, RPCExamples{ "First three native segwit receive addresses\n" + @@ -294,15 +296,13 @@ "verifymessage", "\nVerify a signed message\n", { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to use for the signature."}, - {"signature", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"signature", RPCArg::Type::STR, RPCArg::Optional::NO, "The signature provided by the signer in base 64 encoding " "(see signmessage)."}, - {"message", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The message that was signed."}, + {"message", RPCArg::Type::STR, RPCArg::Optional::NO, + "The message that was signed."}, }, RPCResult{"true|false (boolean) If the signature is verified or " "not.\n"}, @@ -371,11 +371,10 @@ "signmessagewithprivkey", "\nSign a message with the private key of an address\n", { - {"privkey", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"privkey", RPCArg::Type::STR, RPCArg::Optional::NO, "The private key to sign the message with."}, - {"message", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The message to create a signature of."}, + {"message", RPCArg::Type::STR, RPCArg::Optional::NO, + "The message to create a signature of."}, }, RPCResult{"\"signature\" (string) The signature of the " "message encoded in base 64\n"}, @@ -421,8 +420,7 @@ "setmocktime", "\nSet the local time to given timestamp (-regtest only)\n", { - {"timestamp", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", + {"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, "Unix seconds-since-epoch timestamp\n" " Pass 0 to go back to using the system time."}, }, @@ -495,8 +493,7 @@ "getmemoryinfo", "Returns an object containing information about memory usage.\n", { - {"mode", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "\"stats\"", + {"mode", RPCArg::Type::STR, /* default */ "\"stats\"", "determines what kind of information is returned.\n" " - \"stats\" returns general statistics about memory usage " "in the daemon.\n" @@ -595,23 +592,19 @@ { {"include", RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "null", + RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of categories to add debug logging", { {"include_category", RPCArg::Type::STR, - /* opt */ false, /* default_val */ "", - "the valid logging category"}, + RPCArg::Optional::OMITTED, "the valid logging category"}, }}, {"exclude", RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "null", + RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of categories to remove debug logging", { {"exclude_category", RPCArg::Type::STR, - /* opt */ false, /* default_val */ "", - "the valid logging category"}, + RPCArg::Optional::OMITTED, "the valid logging category"}, }}, }, RPCResult{"{ (json object where keys are the " diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -272,10 +272,9 @@ "full nodes as other outbound peers are (though such peers " "will not be synced from).\n", { - {"node", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The node (see getpeerinfo for nodes)"}, - {"command", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"node", RPCArg::Type::STR, RPCArg::Optional::NO, + "The node (see getpeerinfo for nodes)"}, + {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'add' to add a node to the list, 'remove' to remove a " "node from the list, 'onetry' to try a connection to the " "node once"}, @@ -327,11 +326,11 @@ "\nTo disconnect by nodeid, either set 'address' to the empty " "string, or call using the named 'nodeid' argument only.\n", { - {"address", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "fallback to nodeid", + {"address", RPCArg::Type::STR, + /* default */ "fallback to nodeid", "The IP address/port of the node"}, - {"nodeid", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "fallback to address", + {"nodeid", RPCArg::Type::NUM, + /* default */ "fallback to address", "The node ID (see getpeerinfo for node IDs)"}, }, RPCResults{}, @@ -386,8 +385,7 @@ "all added nodes\n" "(note that onetry addnodes are not listed here)\n", { - {"node", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "all nodes", + {"node", RPCArg::Type::STR, /* default */ "all nodes", "If provided, return information about this specific node, " "otherwise all nodes are returned."}, }, @@ -664,22 +662,18 @@ "\nAttempts to add or remove an IP/Subnet from the " "banned list.\n", { - {"subnet", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"subnet", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP/Subnet (see getpeerinfo for nodes IP) with an " "optional netmask (default is /32 = single IP)"}, - {"command", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'add' to add an IP/Subnet to the list, 'remove' to " "remove an IP/Subnet from the list"}, - {"bantime", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", + {"bantime", RPCArg::Type::NUM, /* default */ "0", "time in seconds how long (or until when if [absolute] is " "set) the IP is banned (0 or empty means using the default " "time of 24h which can also be overwritten by the -bantime " "startup argument)"}, - {"absolute", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", + {"absolute", RPCArg::Type::BOOL, /* default */ "false", "If set, the bantime must be an absolute timestamp in seconds " "since epoch (Jan 1 1970 GMT)"}, }, @@ -824,8 +818,7 @@ "setnetworkactive", "\nDisable/enable all p2p network activity.\n", { - {"state", RPCArg::Type::BOOL, /* opt */ false, - /* default_val */ "", + {"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, "true to enable networking, false to disable"}, }, RPCResults{}, @@ -853,8 +846,7 @@ "\nReturn known addresses which can potentially be used " "to find new nodes in the network\n", { - {"count", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "1", + {"count", RPCArg::Type::NUM, /* default */ "1", "How many addresses to return. Limited to the " "smaller of " + std::to_string(ADDRMAN_GETADDR_MAX) + " or " + diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -89,14 +89,13 @@ "If verbose is 'false' or omitted, returns a string that is " "serialized, hex-encoded data for 'txid'.\n", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The transaction id"}, - {"verbose", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "The transaction id"}, + {"verbose", RPCArg::Type::BOOL, /* default */ "false", "If false, return a string, otherwise return a json " "object"}, - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, - /* default_val */ "null", + {"blockhash", RPCArg::Type::STR_HEX, + RPCArg::Optional::OMITTED_NAMED_ARG, "The block in which to look for the transaction"}, }, { @@ -274,16 +273,15 @@ { "txids", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "A json array of txids to filter", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "A transaction hash"}, + {"txid", RPCArg::Type::STR_HEX, + RPCArg::Optional::OMITTED, "A transaction hash"}, }, }, - {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, - /* default_val */ "null", + {"blockhash", RPCArg::Type::STR_HEX, + RPCArg::Optional::OMITTED_NAMED_ARG, "If specified, looks for txid in the block with this hash"}, }, RPCResult{"\"data\" (string) A string that is a " @@ -392,8 +390,7 @@ "and throwing an RPC error if the block is not in our " "best chain\n", { - {"proof", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", + {"proof", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded proof generated by gettxoutproof"}, }, RPCResult{"[\"txid\"] (array, strings) The txid(s) which the " @@ -452,24 +449,20 @@ { "inputs", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "A json array of json objects", { { "", RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", + RPCArg::Optional::OMITTED, "", { {"txid", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "The transaction id"}, - {"vout", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "The output number"}, - {"sequence", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ + RPCArg::Optional::NO, "The transaction id"}, + {"vout", RPCArg::Type::NUM, + RPCArg::Optional::NO, "The output number"}, + {"sequence", RPCArg::Type::NUM, /* default */ "depends on the value of the 'locktime' " "argument", "The sequence number"}, @@ -480,8 +473,7 @@ { "outputs", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "a json array with outputs (key-value pairs).\n" "For compatibility reasons, a dictionary, which holds " "the key-value pairs directly, is also\n" @@ -491,12 +483,11 @@ { "", RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", + RPCArg::Optional::OMITTED, "", { {"address", RPCArg::Type::AMOUNT, - /* opt */ false, /* default_val */ "", + RPCArg::Optional::NO, "A key-value pair. The key (string) is " "the bitcoin address, the value (float or " "string) is the amount in " + @@ -506,20 +497,18 @@ { "", RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", + RPCArg::Optional::OMITTED, "", { {"data", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", + RPCArg::Optional::NO, "A key-value pair. The key must be " "\"data\", the value is hex-encoded data"}, }, }, }, }, - {"locktime", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", + {"locktime", RPCArg::Type::NUM, /* default */ "0", "Raw locktime. Non-0 value also locktime-activates " "inputs"}, }, @@ -563,8 +552,8 @@ "\nReturn a JSON object representing the serialized, " "hex-encoded transaction.\n", { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The transaction hex string"}, + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "The transaction hex string"}, }, RPCResult{ "{\n" @@ -638,8 +627,8 @@ "decodescript", "\nDecode a hex-encoded script.\n", { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "the hex-encoded script"}, + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "the hex-encoded script"}, }, RPCResult{"{\n" " \"asm\":\"asm\", (string) Script public key\n" @@ -700,14 +689,12 @@ { "txs", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "A json array of hex strings of partially signed " "transactions", { {"hexstring", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "A transaction hash"}, + RPCArg::Optional::OMITTED, "A transaction hash"}, }, }, }, @@ -803,54 +790,47 @@ "this transaction depends on but may not yet be in the block " "chain.\n", { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The transaction hex string"}, + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "The transaction hex string"}, { "privkeys", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "A json array of base58-encoded private keys for signing", { {"privatekey", RPCArg::Type::STR, - /* opt */ false, /* default_val */ "", + RPCArg::Optional::OMITTED, "private key in base58-encoding"}, }, }, { "prevtxs", RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "null", + RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of previous dependent transaction outputs", { { "", RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", + /* default */ "", "", { {"txid", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "The transaction id"}, - {"vout", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "The output number"}, + RPCArg::Optional::NO, "The transaction id"}, + {"vout", RPCArg::Type::NUM, + RPCArg::Optional::NO, "The output number"}, {"scriptPubKey", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "script key"}, + RPCArg::Optional::NO, "script key"}, {"redeemScript", RPCArg::Type::STR_HEX, - /* opt */ true, /* default_val */ "omitted", + RPCArg::Optional::OMITTED, "(required for P2SH) redeem script"}, {"amount", RPCArg::Type::AMOUNT, - /* opt */ false, /* default_val */ "", - "The amount spent"}, + RPCArg::Optional::NO, "The amount spent"}, }, }, }, }, - {"sighashtype", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "ALL|FORKID", + {"sighashtype", RPCArg::Type::STR, /* default */ "ALL|FORKID", "The signature hash type. Must be one of:\n" " \"ALL|FORKID\"\n" " \"NONE|FORKID\"\n" @@ -924,10 +904,10 @@ "\nAlso see createrawtransaction and " "signrawtransactionwithkey calls.\n", { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The hex string of the raw transaction"}, - {"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", "Allow high fees"}, + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "The hex string of the raw transaction"}, + {"allowhighfees", RPCArg::Type::BOOL, /* default */ "false", + "Allow high fees"}, }, RPCResult{ "\"hex\" (string) The transaction hash in hex\n"}, @@ -988,18 +968,17 @@ { "rawtxs", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "An array of hex strings of raw transactions.\n" " Length must be " "one for now.", { {"rawtx", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", ""}, + RPCArg::Optional::OMITTED, ""}, }, }, - {"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", "Allow high fees"}, + {"allowhighfees", RPCArg::Type::BOOL, /* default */ "false", + "Allow high fees"}, }, RPCResult{ "[ (array) The result of the mempool " @@ -1104,8 +1083,8 @@ "\nReturn a JSON object representing the serialized, " "base64-encoded partially signed Bitcoin transaction.\n", { - {"psbt", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The PSBT base64 string"}, + {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, + "The PSBT base64 string"}, }, RPCResult{ "{\n" @@ -1387,13 +1366,12 @@ { "txs", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "A json array of base64 strings of partially signed " "transactions", { - {"psbt", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "A base64 string of a PSBT"}, + {"psbt", RPCArg::Type::STR, RPCArg::Optional::OMITTED, + "A base64 string of a PSBT"}, }, }, }, @@ -1447,10 +1425,9 @@ "inputs that are complete.\n" "Implements the Finalizer and Extractor roles.\n", { - {"psbt", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "A base64 string of a PSBT"}, - {"extract", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", + {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, + "A base64 string of a PSBT"}, + {"extract", RPCArg::Type::BOOL, /* default */ "true", "If true and the transaction is complete,\n" " extract and return the complete " "transaction in normal network serialization instead of the " @@ -1518,24 +1495,20 @@ { "inputs", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "A json array of json objects", { { "", RPCArg::Type::OBJ, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::OMITTED, "", { {"txid", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", - "The transaction id"}, - {"vout", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", "The output number"}, - {"sequence", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ + RPCArg::Optional::NO, "The transaction id"}, + {"vout", RPCArg::Type::NUM, + RPCArg::Optional::NO, "The output number"}, + {"sequence", RPCArg::Type::NUM, /* default */ "depends on the value of the 'locktime' " "argument", "The sequence number"}, @@ -1546,8 +1519,7 @@ { "outputs", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "a json array with outputs (key-value pairs).\n" "For compatibility reasons, a dictionary, which holds " "the key-value pairs directly, is also\n" @@ -1557,12 +1529,11 @@ { "", RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", + RPCArg::Optional::OMITTED, "", { {"address", RPCArg::Type::AMOUNT, - /* opt */ false, /* default_val */ "", + RPCArg::Optional::NO, "A key-value pair. The key (string) is " "the bitcoin address, the value (float or " "string) is the amount in " + @@ -1572,20 +1543,18 @@ { "", RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", + RPCArg::Optional::OMITTED, "", { {"data", RPCArg::Type::STR_HEX, - /* opt */ false, /* default_val */ "", + RPCArg::Optional::NO, "A key-value pair. The key must be " "\"data\", the value is hex-encoded data"}, }, }, }, }, - {"locktime", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", + {"locktime", RPCArg::Type::NUM, /* default */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"}, }, RPCResult{" \"psbt\" (string) The resulting raw " @@ -1638,10 +1607,9 @@ "createpsbt and walletcreatefundedpsbt should be used for new " "applications.\n", { - {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", "The hex string of a raw transaction"}, - {"permitsigdata", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", + {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "The hex string of a raw transaction"}, + {"permitsigdata", RPCArg::Type::BOOL, /* default */ "false", "If true, any signatures in the input will be discarded and " "conversion.\n" " will continue. If false, RPC " @@ -1702,8 +1670,7 @@ "utxoupdatepsbt", "\nUpdates a PSBT with witness UTXOs retrieved from the UTXO set " "or the mempool.\n", - {{"psbt", RPCArg::Type::STR, - /* opt */ false, /* default_val */ "", + {{"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "A base64 string of a PSBT"}}, RPCResult{" \"psbt\" (string) The base64-encoded " "partially signed transaction with inputs updated\n"}, @@ -1766,11 +1733,10 @@ "PSBTs.\n", {{"txs", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "A json array of base64 strings of partially signed transactions", - {{"psbt", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "A base64 string of a PSBT"}}}}, + {{"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, + "A base64 string of a PSBT"}}}}, RPCResult{" \"psbt\" (string) The base64-encoded " "partially signed transaction\n"}, RPCExamples{HelpExampleCli("joinpsbts", "\"psbt\"")}} @@ -1843,7 +1809,7 @@ "analyzepsbt", "\nAnalyzes and provides information about the current status of a " "PSBT and its inputs\n", - {{"psbt", RPCArg::Type::STR, /* opt */ false, /* default_var */ "", + {{"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "A base64 string of a PSBT"}}, RPCResult{ "{\n" diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -182,8 +182,7 @@ "help", "\nList all commands, or get help for a specified command.\n", { - {"command", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "all commands", + {"command", RPCArg::Type::STR, /* default */ "all commands", "The command to get help on"}, }, RPCResult{"\"text\" (string) The help text\n"}, diff --git a/src/rpc/util.h b/src/rpc/util.h --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -11,6 +11,8 @@ #include #include +#include + #include #include @@ -102,13 +104,33 @@ //! Special type that is a STR with only hex chars STR_HEX, }; + + enum class Optional { + /** Required arg */ + NO, + /** + * Optinal arg that is a named argument and has a default value of + * `null`. When possible, the default value should be specified. + */ + OMITTED_NAMED_ARG, + /** + * Optional argument with default value omitted because they are + * implicitly clear. That is, elements in an array or object may not + * exist by default. + * When possible, the default value should be specified. + */ + OMITTED, + }; + using Fallback = + boost::variant; + //! The name of the arg (can be empty for inner args) const std::string m_name; const Type m_type; //! Only used for arrays or dicts const std::vector m_inner; - const bool m_optional; - const std::string m_default_value; //!< Only used for optional args + const Fallback m_fallback; const std::string m_description; //! Should be empty unless it is supposed to override the auto-generated //! summary line @@ -121,23 +143,22 @@ //! override the type in the argument description. const std::vector m_type_str; - RPCArg(const std::string &name, const Type &type, const bool opt, - const std::string &default_val, const std::string &description, + RPCArg(const std::string &name, const Type &type, const Fallback &fallback, + const std::string &description, const std::string &oneline_description = "", const std::vector &type_str = {}) - : m_name{name}, m_type{type}, m_optional{opt}, - m_default_value{default_val}, m_description{description}, + : m_name{name}, m_type{type}, m_fallback{fallback}, + m_description{description}, m_oneline_description{oneline_description}, m_type_str{type_str} { CHECK_NONFATAL(type != Type::ARR && type != Type::OBJ); } - RPCArg(const std::string &name, const Type &type, const bool opt, - const std::string &default_val, const std::string &description, - const std::vector &inner, + RPCArg(const std::string &name, const Type &type, const Fallback &fallback, + const std::string &description, const std::vector &inner, const std::string &oneline_description = "", const std::vector &type_str = {}) - : m_name{name}, m_type{type}, m_inner{inner}, m_optional{opt}, - m_default_value{default_val}, m_description{description}, + : m_name{name}, m_type{type}, m_inner{inner}, m_fallback{fallback}, + m_description{description}, m_oneline_description{oneline_description}, m_type_str{type_str} { CHECK_NONFATAL(type == Type::ARR || type == Type::OBJ); } @@ -156,10 +177,8 @@ /** * Return the description string, including the argument type and whether * the argument is required. - * implicitly_required is set for arguments in an array, which are neither - * optional nor required. */ - std::string ToDescriptionString(bool implicitly_required = false) const; + std::string ToDescriptionString() const; }; struct RPCResult { diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -318,19 +318,14 @@ : arg.ToString(/* oneline */ false); } left += ","; - PushSection({left, arg.ToDescriptionString( - /* implicitly_required */ outer_type == - OuterType::ARR)}); + PushSection({left, arg.ToDescriptionString()}); break; } case RPCArg::Type::OBJ: case RPCArg::Type::OBJ_USER_KEYS: { - const auto right = - outer_type == OuterType::NAMED_ARG - ? "" - : arg.ToDescriptionString( - /* implicitly_required */ outer_type == - OuterType::ARR); + const auto right = outer_type == OuterType::NAMED_ARG + ? "" + : arg.ToDescriptionString(); PushSection({indent + "{", right}); for (const auto &arg_inner : arg.m_inner) { Push(arg_inner, current_indent + 2, OuterType::OBJ); @@ -350,12 +345,9 @@ ? "\"" + arg.m_name + "\": " : ""; left += "["; - const auto right = - outer_type == OuterType::NAMED_ARG - ? "" - : arg.ToDescriptionString( - /* implicitly_required */ outer_type == - OuterType::ARR); + const auto right = outer_type == OuterType::NAMED_ARG + ? "" + : arg.ToDescriptionString(); PushSection({left, right}); for (const auto &arg_inner : arg.m_inner) { Push(arg_inner, current_indent + 2, OuterType::ARR); @@ -447,8 +439,15 @@ ret += m_name; bool was_optional{false}; for (const auto &arg : m_args) { + bool optional; + if (arg.m_fallback.which() == 1) { + optional = true; + } else { + optional = RPCArg::Optional::NO != + boost::get(arg.m_fallback); + } ret += " "; - if (arg.m_optional) { + if (optional) { if (!was_optional) { ret += "( "; } @@ -499,7 +498,7 @@ return ret; } -std::string RPCArg::ToDescriptionString(const bool implicitly_required) const { +std::string RPCArg::ToDescriptionString() const { std::string ret; ret += "("; if (m_type_str.size() != 0) { @@ -536,21 +535,25 @@ // no default case, so the compiler can warn about missing cases } } - if (!implicitly_required) { - ret += ", "; - if (m_optional) { - ret += "optional"; - if (!m_default_value.empty()) { - ret += ", default=" + m_default_value; - } else { - // TODO enable this assert, when all optional parameters have - // their default value documented - // assert(false); + if (m_fallback.which() == 1) { + ret += ", optional, default=" + boost::get(m_fallback); + } else { + switch (boost::get(m_fallback)) { + case RPCArg::Optional::OMITTED: { + // nothing to do. Element is treated as if not present and has + // no default value + break; } - } else { - ret += "required"; - // Default value is ignored, and must not be present - assert(m_default_value.empty()); + case RPCArg::Optional::OMITTED_NAMED_ARG: { + ret += ", optional"; // Default value is "null" + break; + } + case RPCArg::Optional::NO: { + ret += ", required"; + break; + } + + // no default case, so the compiler can warn about missing cases } } ret += ")"; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -113,14 +113,12 @@ "are still missing, leading to temporarily incorrect/bogus " "balances and unspent outputs until rescan completes.\n", { - {"privkey", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The private key (see dumpprivkey)"}, - {"label", RPCArg::Type::STR, /* opt */ true, - /* default_val */ + {"privkey", RPCArg::Type::STR, RPCArg::Optional::NO, + "The private key (see dumpprivkey)"}, + {"label", RPCArg::Type::STR, /* default */ "current label if address exists, otherwise \"\"", "An optional label"}, - {"rescan", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", + {"rescan", RPCArg::Type::BOOL, /* default */ "true", "Rescan the wallet for transactions"}, }, RPCResults{}, @@ -323,16 +321,13 @@ "outputs sending to it will be treated\n" "as change, and not show up in many RPCs.\n", { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The Bitcoin address (or hex-encoded script)"}, - {"label", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "\"\"", "An optional label"}, - {"rescan", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", + {"label", RPCArg::Type::STR, /* default */ "\"\"", + "An optional label"}, + {"rescan", RPCArg::Type::BOOL, /* default */ "true", "Rescan the wallet for transactions"}, - {"p2sh", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "false", + {"p2sh", RPCArg::Type::BOOL, /* default */ "false", "Add the P2SH version of the script as well"}, }, RPCResults{}, @@ -425,12 +420,10 @@ "rescan after the point in the blockchain the transaction is " "included.\n", { - {"rawtransaction", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", + {"rawtransaction", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A raw transaction in hex funding an already-existing " "address in wallet"}, - {"txoutproof", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", + {"txoutproof", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex output from gettxoutproof that contains the " "transaction"}, }, @@ -510,8 +503,7 @@ "for use with pruned wallets and as a companion to " "importprunedfunds. This will affect wallet balances.\n", { - {"txid", RPCArg::Type::STR_HEX, /* opt */ false, - /* default_val */ "", + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded id of the transaction you are deleting"}, }, RPCResults{}, @@ -571,12 +563,11 @@ "incorrect/bogus balances and unspent outputs until rescan " "completes.\n", { - {"pubkey", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The hex-encoded public key"}, - {"label", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "\"\"", "An optional label"}, - {"rescan", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", + {"pubkey", RPCArg::Type::STR, RPCArg::Optional::NO, + "The hex-encoded public key"}, + {"label", RPCArg::Type::STR, /* default */ "\"\"", + "An optional label"}, + {"rescan", RPCArg::Type::BOOL, /* default */ "true", "Rescan the wallet for transactions"}, }, RPCResults{}, @@ -657,8 +648,8 @@ "\nImports keys from a wallet dump file (see dumpwallet). " "Requires a new wallet backup to include imported keys.\n", { - {"filename", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The wallet file"}, + {"filename", RPCArg::Type::STR, RPCArg::Optional::NO, + "The wallet file"}, }, RPCResults{}, RPCExamples{"\nDump the wallet\n" + @@ -862,8 +853,7 @@ "\nReveals the private key corresponding to 'address'.\n" "Then the importprivkey can be used with this output\n", { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address for the private key"}, }, RPCResult{"\"key\" (string) The private key\n"}, @@ -920,8 +910,7 @@ "only backing up the seed itself, and must be backed up " "too (e.g. ensure you back up the whole dumpfile).\n", { - {"filename", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The filename with path (either absolute or relative to " "bitcoind)"}, }, @@ -1598,26 +1587,23 @@ { {"requests", RPCArg::Type::ARR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "Data to be imported", { { "", RPCArg::Type::OBJ, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::OMITTED, "", { - {"desc", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "", + {"desc", RPCArg::Type::STR, + RPCArg::Optional::OMITTED, "Descriptor to import. If using descriptor, do " "not also provide address/scriptPubKey, scripts, " "or pubkeys"}, {"scriptPubKey", RPCArg::Type::STR, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "Type of scriptPubKey (string for script, json " "for address). Should not be provided if using a " "descriptor", @@ -1626,8 +1612,7 @@ "string / json"}}, {"timestamp", RPCArg::Type::NUM, - /* opt */ false, - /* default_val */ "", + RPCArg::Optional::NO, "Creation time of the key in seconds since " "epoch (Jan 1 1970 GMT),\n" " " @@ -1652,59 +1637,55 @@ "be scanned.", /* oneline_description */ "", {"timestamp | \"now\"", "integer / string"}}, - {"redeemscript", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "omitted", + {"redeemscript", RPCArg::Type::STR, + RPCArg::Optional::OMITTED, "Allowed only if the scriptPubKey is a P2SH " "address/scriptPubKey"}, {"pubkeys", RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "empty array", + /* default */ "empty array", "Array of strings giving pubkeys to import. They " "must occur in P2PKH scripts. They are not " "required when the private key is also provided " "(see the \"keys\" argument).", { - {"pubKey", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", ""}, + {"pubKey", RPCArg::Type::STR, + RPCArg::Optional::OMITTED, ""}, }}, {"keys", RPCArg::Type::ARR, - /* opt */ true, - /* default_val */ "empty array", + /* default */ "empty array", "Array of strings giving private keys to import. " "The corresponding public keys must occur in the " "output or redeemscript.", { {"key", RPCArg::Type::STR, - /* opt */ false, /* default_val */ "", ""}, + RPCArg::Optional::OMITTED, ""}, }}, {"range", RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "", + RPCArg::Optional::OMITTED, "If a ranged descriptor is used, this specifies " "the start and end of the range to import", { - {"start", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "0", + {"start", RPCArg::Type::NUM, + /* default */ "0", "Start of the range to import"}, - {"end", RPCArg::Type::NUM, /* opt */ false, - /* default_val */ "", + {"end", RPCArg::Type::NUM, + RPCArg::Optional::NO, "End of the range to import (inclusive)"}, }}, {"internal", RPCArg::Type::BOOL, - /* opt */ true, /* default_val */ "false", + /* default */ "false", "Stating whether matching outputs should be " "treated as not incoming payments (also known as " "change)"}, {"watchonly", RPCArg::Type::BOOL, - /* opt */ true, /* default_val */ "false", + /* default */ "false", "Stating whether matching outputs should be " "considered watched even when not all private " "keys are provided."}, - {"label", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "''", + {"label", RPCArg::Type::STR, /* default */ "''", "Label to assign to the address, only " "allowed with internal=false"}, }, @@ -1713,12 +1694,10 @@ "\"requests\""}, {"options", RPCArg::Type::OBJ, - /* opt */ true, - /* default_val */ "null", + RPCArg::Optional::OMITTED_NAMED_ARG, "", { - {"rescan", RPCArg::Type::BOOL, /* opt */ true, - /* default_val */ "true", + {"rescan", RPCArg::Type::BOOL, /* default */ "true", "Stating if should rescan the blockchain after all " "imports"}, }, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -168,8 +168,7 @@ "so payments received with the address will be associated with " "'label'.\n", { - {"label", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "null", + {"label", RPCArg::Type::STR, /* default */ "null", "The label name for the address to be linked to. If not " "provided, the default label \"\" is used. It can also be set " "to the empty string \"\" to represent the default label. The " @@ -310,11 +309,10 @@ "setlabel", "\nSets the label associated with the given address.\n", { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to be associated with a label."}, - {"label", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The label to assign to the address."}, + {"label", RPCArg::Type::STR, RPCArg::Optional::NO, + "The label to assign to the address."}, }, RPCResults{}, RPCExamples{ @@ -421,25 +419,24 @@ "\nSend an amount to a given address.\n" + HelpRequiringPassphrase(pwallet) + "\n", { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The bitcoin address to send to."}, - {"amount", RPCArg::Type::AMOUNT, /* opt */ false, - /* default_val */ "", + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, + "The bitcoin address to send to."}, + {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The amount in " + CURRENCY_UNIT + " to send. eg 0.1"}, - {"comment", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "null", + {"comment", RPCArg::Type::STR, + RPCArg::Optional::OMITTED_NAMED_ARG, "A comment used to store what the transaction is for.\n" " This is not part of the " "transaction, just kept in your wallet."}, - {"comment_to", RPCArg::Type::STR, /* opt */ true, - /* default_val */ "null", + {"comment_to", RPCArg::Type::STR, + RPCArg::Optional::OMITTED_NAMED_ARG, "A comment to store the name of the person or organization\n" " to which you're sending the " "transaction. This is not part of the \n" " transaction, just kept in " "your wallet."}, {"subtractfeefromamount", RPCArg::Type::BOOL, - /* opt */ true, /* default_val */ "false", + /* default */ "false", "The fee will be deducted from the amount being sent.\n" " The recipient will receive " "less bitcoins than you enter in the amount field."}, @@ -587,11 +584,10 @@ "\nSign a message with the private key of an address" + HelpRequiringPassphrase(pwallet) + "\n", { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to use for the private key."}, - {"message", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The message to create a signature of."}, + {"message", RPCArg::Type::STR, RPCArg::Optional::NO, + "The message to create a signature of."}, }, RPCResult{ "\"signature\" (string) The signature of the message " @@ -668,10 +664,9 @@ "\nReturns the total amount received by the given address in " "transactions with at least minconf confirmations.\n", { - {"address", RPCArg::Type::STR, /* opt */ false, - /* default_val */ "", "The bitcoin address for transactions."}, - {"minconf", RPCArg::Type::NUM, /* opt */ true, - /* default_val */ "1", + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, + "The bitcoin address for transactions."}, + {"minconf", RPCArg::Type::NUM, /* default */ "1", "Only include transactions confirmed at least this many " "times."}, }, @@ -761,12 +756,10 @@ "\nReturns the total amount received by addresses with