mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
Merge #21679: rpc: Keep default argument value in correct type
bee56c78e9rpc: Check default value type againts argument type (João Barbosa)f81ef4303erpc: Keep default argument value in correct type (João Barbosa) Pull request description: Store default values of RPC arguments in the corresponding type instead of a string. The value is then serialized when the help output is needed. This change simplifies #20017. The following examples illustrates how to use the new `RPCArg::Default` and `RPCArg::DefaultHint`: ```diff - {"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"} + {"verbose", RPCArg::Type::BOOL, RPCArg::Default(false), "True for a json object, false for array of transaction ids"} ``` ```diff - {"nblocks", RPCArg::Type::NUM, /* default */ "one month", "Size of the window in number of blocks"} + {"nblocks", RPCArg::Type::NUM, RPCArg::DefaultHint("one month"), "Size of the window in number of blocks"} ``` No behavior change is expected. ACKs for top commit: LarryRuane: ACKbee56c78e9MarcoFalke: ACKbee56c78e9🦅 Tree-SHA512: c47d78c918e996d36631d4ad3c933b270a34c5b446b8d736be94cf4a0a7b8c0e33d954149ec786cf9550639865b79deb6a130ad044de6030f95aac33f524293a
This commit is contained in:
@@ -254,7 +254,7 @@ static RPCHelpMan waitfornewblock()
|
||||
"\nWaits for a specific new block and returns useful info about it.\n"
|
||||
"\nReturns the current block on timeout or exit.\n",
|
||||
{
|
||||
{"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."},
|
||||
{"timeout", RPCArg::Type::NUM, RPCArg::Default{0}, "Time in milliseconds to wait for a response. 0 indicates no timeout."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
@@ -297,7 +297,7 @@ static RPCHelpMan waitforblock()
|
||||
"\nReturns the current block on timeout or exit.\n",
|
||||
{
|
||||
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "Block hash to wait for."},
|
||||
{"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."},
|
||||
{"timeout", RPCArg::Type::NUM, RPCArg::Default{0}, "Time in milliseconds to wait for a response. 0 indicates no timeout."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
@@ -344,7 +344,7 @@ static RPCHelpMan waitforblockheight()
|
||||
"\nReturns the current block on timeout or exit.\n",
|
||||
{
|
||||
{"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "Block height to wait for."},
|
||||
{"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."},
|
||||
{"timeout", RPCArg::Type::NUM, RPCArg::Default{0}, "Time in milliseconds to wait for a response. 0 indicates no timeout."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
@@ -558,8 +558,8 @@ static RPCHelpMan getrawmempool()
|
||||
"\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n"
|
||||
"\nHint: use getmempoolentry to fetch a specific transaction from the mempool.\n",
|
||||
{
|
||||
{"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"},
|
||||
{"mempool_sequence", RPCArg::Type::BOOL, /* default */ "false", "If verbose=false, returns a json object with transaction list and mempool sequence number attached."},
|
||||
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
|
||||
{"mempool_sequence", RPCArg::Type::BOOL, RPCArg::Default{false}, "If verbose=false, returns a json object with transaction list and mempool sequence number attached."},
|
||||
},
|
||||
{
|
||||
RPCResult{"for verbose = false",
|
||||
@@ -608,7 +608,7 @@ static RPCHelpMan getmempoolancestors()
|
||||
"\nIf txid is in the mempool, returns all in-mempool ancestors.\n",
|
||||
{
|
||||
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
|
||||
{"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"},
|
||||
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
|
||||
},
|
||||
{
|
||||
RPCResult{"for verbose = false",
|
||||
@@ -672,7 +672,7 @@ static RPCHelpMan getmempooldescendants()
|
||||
"\nIf txid is in the mempool, returns all in-mempool descendants.\n",
|
||||
{
|
||||
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
|
||||
{"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"},
|
||||
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
|
||||
},
|
||||
{
|
||||
RPCResult{"for verbose = false",
|
||||
@@ -800,7 +800,7 @@ static RPCHelpMan getblockheader()
|
||||
"If verbose is true, returns an Object with information about blockheader <hash>.\n",
|
||||
{
|
||||
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
|
||||
{"verbose", RPCArg::Type::BOOL, /* default */ "true", "true for a json object, false for the hex-encoded data"},
|
||||
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{true}, "true for a json object, false for the hex-encoded data"},
|
||||
},
|
||||
{
|
||||
RPCResult{"for verbose = true",
|
||||
@@ -902,7 +902,7 @@ static RPCHelpMan getblock()
|
||||
"If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n",
|
||||
{
|
||||
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
|
||||
{"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"},
|
||||
{"verbosity|verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a json object, and 2 for json object with transaction data"},
|
||||
},
|
||||
{
|
||||
RPCResult{"for verbosity = 0",
|
||||
@@ -1070,7 +1070,7 @@ static RPCHelpMan gettxoutsetinfo()
|
||||
"\nReturns statistics about the unspent transaction output set.\n"
|
||||
"Note this call may take some time.\n",
|
||||
{
|
||||
{"hash_type", RPCArg::Type::STR, /* default */ "hash_serialized_2", "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'muhash', 'none'."},
|
||||
{"hash_type", RPCArg::Type::STR, RPCArg::Default{"hash_serialized_2"}, "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'muhash', 'none'."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
@@ -1137,7 +1137,7 @@ static RPCHelpMan gettxout()
|
||||
{
|
||||
{"txid", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction id"},
|
||||
{"n", RPCArg::Type::NUM, RPCArg::Optional::NO, "vout number"},
|
||||
{"include_mempool", RPCArg::Type::BOOL, /* default */ "true", "Whether to include the mempool. Note that an unspent output that is spent in the mempool won't appear."},
|
||||
{"include_mempool", RPCArg::Type::BOOL, RPCArg::Default{true}, "Whether to include the mempool. Note that an unspent output that is spent in the mempool won't appear."},
|
||||
},
|
||||
{
|
||||
RPCResult{"If the UTXO was not found", RPCResult::Type::NONE, "", ""},
|
||||
@@ -1220,9 +1220,9 @@ static RPCHelpMan verifychain()
|
||||
return RPCHelpMan{"verifychain",
|
||||
"\nVerifies blockchain database.\n",
|
||||
{
|
||||
{"checklevel", RPCArg::Type::NUM, /* default */ strprintf("%d, range=0-4", DEFAULT_CHECKLEVEL),
|
||||
{"checklevel", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%d, range=0-4", DEFAULT_CHECKLEVEL)},
|
||||
strprintf("How thorough the block verification is:\n - %s", Join(CHECKLEVEL_DOC, "\n- "))},
|
||||
{"nblocks", RPCArg::Type::NUM, /* default */ strprintf("%d, 0=all", DEFAULT_CHECKBLOCKS), "The number of blocks to check."},
|
||||
{"nblocks", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%d, 0=all", DEFAULT_CHECKBLOCKS)}, "The number of blocks to check."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::BOOL, "", "Verified or not"},
|
||||
@@ -1704,8 +1704,8 @@ static RPCHelpMan getchaintxstats()
|
||||
return RPCHelpMan{"getchaintxstats",
|
||||
"\nCompute statistics about the total number and rate of transactions in the chain.\n",
|
||||
{
|
||||
{"nblocks", RPCArg::Type::NUM, /* default */ "one month", "Size of the window in number of blocks"},
|
||||
{"blockhash", RPCArg::Type::STR_HEX, /* default */ "chain tip", "The hash of the block that ends the window."},
|
||||
{"nblocks", RPCArg::Type::NUM, RPCArg::DefaultHint{"one month"}, "Size of the window in number of blocks"},
|
||||
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::DefaultHint{"chain tip"}, "The hash of the block that ends the window."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
@@ -1852,7 +1852,7 @@ static RPCHelpMan getblockstats()
|
||||
"It won't work for some heights with pruning.\n",
|
||||
{
|
||||
{"hash_or_height", RPCArg::Type::NUM, RPCArg::Optional::NO, "The block hash or height of the target block", "", {"", "string or numeric"}},
|
||||
{"stats", RPCArg::Type::ARR, /* default */ "all values", "Values to plot (see result below)",
|
||||
{"stats", RPCArg::Type::ARR, RPCArg::DefaultHint{"all values"}, "Values to plot (see result below)",
|
||||
{
|
||||
{"height", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Selected statistic"},
|
||||
{"time", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Selected statistic"},
|
||||
@@ -2221,7 +2221,7 @@ static RPCHelpMan scantxoutset()
|
||||
{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "An object with output descriptor and metadata",
|
||||
{
|
||||
{"desc", RPCArg::Type::STR, RPCArg::Optional::NO, "An output descriptor"},
|
||||
{"range", RPCArg::Type::RANGE, /* default */ "1000", "The range of HD chain indexes to explore (either end or [begin,end])"},
|
||||
{"range", RPCArg::Type::RANGE, RPCArg::Default{1000}, "The range of HD chain indexes to explore (either end or [begin,end])"},
|
||||
}},
|
||||
},
|
||||
"[scanobjects,...]"},
|
||||
@@ -2360,7 +2360,7 @@ static RPCHelpMan getblockfilter()
|
||||
"\nRetrieve a BIP 157 content filter for a particular block.\n",
|
||||
{
|
||||
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hash of the block"},
|
||||
{"filtertype", RPCArg::Type::STR, /*default*/ "basic", "The type name of the filter"},
|
||||
{"filtertype", RPCArg::Type::STR, RPCArg::Default{"basic"}, "The type name of the filter"},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
|
||||
@@ -89,8 +89,8 @@ static RPCHelpMan getnetworkhashps()
|
||||
"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."},
|
||||
{"nblocks", RPCArg::Type::NUM, RPCArg::Default{120}, "The number of blocks, or -1 for blocks since last difficulty change."},
|
||||
{"height", RPCArg::Type::NUM, RPCArg::Default{-1}, "To estimate at the time of the given height."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::NUM, "", "Hashes per second estimated"},
|
||||
@@ -214,7 +214,7 @@ static RPCHelpMan generatetodescriptor()
|
||||
{
|
||||
{"num_blocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
|
||||
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor to send the newly generated bitcoin to."},
|
||||
{"maxtries", RPCArg::Type::NUM, /* default */ ToString(DEFAULT_MAX_TRIES), "How many iterations to try."},
|
||||
{"maxtries", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_MAX_TRIES}, "How many iterations to try."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::ARR, "", "hashes of blocks generated",
|
||||
@@ -258,7 +258,7 @@ static RPCHelpMan generatetoaddress()
|
||||
{
|
||||
{"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 */ ToString(DEFAULT_MAX_TRIES), "How many iterations to try."},
|
||||
{"maxtries", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_MAX_TRIES}, "How many iterations to try."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::ARR, "", "hashes of blocks generated",
|
||||
@@ -525,7 +525,7 @@ static RPCHelpMan getblocktemplate()
|
||||
" https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n"
|
||||
" https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki\n",
|
||||
{
|
||||
{"template_request", RPCArg::Type::OBJ, "{}", "Format of the template",
|
||||
{"template_request", RPCArg::Type::OBJ, RPCArg::Default{UniValue::VOBJ}, "Format of the template",
|
||||
{
|
||||
{"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",
|
||||
@@ -960,7 +960,7 @@ static RPCHelpMan submitblock()
|
||||
"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."},
|
||||
{"dummy", RPCArg::Type::STR, RPCArg::DefaultHint{"ignored"}, "dummy value, for compatibility with BIP22. This value is ignored."},
|
||||
},
|
||||
{
|
||||
RPCResult{"If the block was accepted", RPCResult::Type::NONE, "", ""},
|
||||
@@ -1069,7 +1069,7 @@ static RPCHelpMan estimatesmartfee()
|
||||
"in BIP 141 (witness data is discounted).\n",
|
||||
{
|
||||
{"conf_target", RPCArg::Type::NUM, RPCArg::Optional::NO, "Confirmation target in blocks (1 - 1008)"},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "conservative", "The fee estimate mode.\n"
|
||||
{"estimate_mode", RPCArg::Type::STR, RPCArg::Default{"conservative"}, "The fee estimate mode.\n"
|
||||
" Whether to return a more conservative estimate which also satisfies\n"
|
||||
" a longer history. A conservative estimate potentially returns a\n"
|
||||
" higher feerate and is more likely to be sufficient for the desired\n"
|
||||
@@ -1140,7 +1140,7 @@ static RPCHelpMan estimaterawfee()
|
||||
"defined in BIP 141 (witness data is discounted).\n",
|
||||
{
|
||||
{"conf_target", RPCArg::Type::NUM, RPCArg::Optional::NO, "Confirmation target in blocks (1 - 1008)"},
|
||||
{"threshold", RPCArg::Type::NUM, /* default */ "0.95", "The proportion of transactions in a given feerate range that must have been\n"
|
||||
{"threshold", RPCArg::Type::NUM, RPCArg::Default{0.95}, "The proportion of transactions in a given feerate range that must have been\n"
|
||||
" confirmed within conf_target in order to consider those feerates as high enough and proceed to check\n"
|
||||
" lower buckets."},
|
||||
},
|
||||
|
||||
@@ -90,7 +90,7 @@ static RPCHelpMan createmultisig()
|
||||
{
|
||||
{"key", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "The hex-encoded public key"},
|
||||
}},
|
||||
{"address_type", RPCArg::Type::STR, /* default */ "legacy", "The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
|
||||
{"address_type", RPCArg::Type::STR, RPCArg::Default{"legacy"}, "The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
@@ -475,7 +475,7 @@ static RPCHelpMan getmemoryinfo()
|
||||
return RPCHelpMan{"getmemoryinfo",
|
||||
"Returns an object containing information about memory usage.\n",
|
||||
{
|
||||
{"mode", RPCArg::Type::STR, /* default */ "\"stats\"", "determines what kind of information is returned.\n"
|
||||
{"mode", RPCArg::Type::STR, RPCArg::Default{"stats"}, "determines what kind of information is returned.\n"
|
||||
" - \"stats\" returns general statistics about memory usage in the daemon.\n"
|
||||
" - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+)."},
|
||||
},
|
||||
|
||||
@@ -376,8 +376,8 @@ static RPCHelpMan disconnectnode()
|
||||
"\nStrictly one out of 'address' and 'nodeid' can be provided to identify the node.\n"
|
||||
"\nTo disconnect by nodeid, either set 'address' to the empty string, or call using the named 'nodeid' argument only.\n",
|
||||
{
|
||||
{"address", RPCArg::Type::STR, /* default */ "fallback to nodeid", "The IP address/port of the node"},
|
||||
{"nodeid", RPCArg::Type::NUM, /* default */ "fallback to address", "The node ID (see getpeerinfo for node IDs)"},
|
||||
{"address", RPCArg::Type::STR, RPCArg::DefaultHint{"fallback to nodeid"}, "The IP address/port of the node"},
|
||||
{"nodeid", RPCArg::Type::NUM, RPCArg::DefaultHint{"fallback to address"}, "The node ID (see getpeerinfo for node IDs)"},
|
||||
},
|
||||
RPCResult{RPCResult::Type::NONE, "", ""},
|
||||
RPCExamples{
|
||||
@@ -422,7 +422,7 @@ static RPCHelpMan getaddednodeinfo()
|
||||
"\nReturns information about the given added node, or all added nodes\n"
|
||||
"(note that onetry addnodes are not listed here)\n",
|
||||
{
|
||||
{"node", RPCArg::Type::STR, /* default */ "all nodes", "If provided, return information about this specific node, otherwise all nodes are returned."},
|
||||
{"node", RPCArg::Type::STR, RPCArg::DefaultHint{"all nodes"}, "If provided, return information about this specific node, otherwise all nodes are returned."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::ARR, "", "",
|
||||
@@ -663,8 +663,8 @@ static RPCHelpMan setban()
|
||||
{
|
||||
{"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, 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, /* 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, /* default */ "false", "If set, the bantime must be an absolute timestamp expressed in " + UNIX_EPOCH_TIME},
|
||||
{"bantime", RPCArg::Type::NUM, RPCArg::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, RPCArg::Default{false}, "If set, the bantime must be an absolute timestamp expressed in " + UNIX_EPOCH_TIME},
|
||||
},
|
||||
RPCResult{RPCResult::Type::NONE, "", ""},
|
||||
RPCExamples{
|
||||
@@ -842,7 +842,7 @@ static RPCHelpMan getnodeaddresses()
|
||||
return RPCHelpMan{"getnodeaddresses",
|
||||
"\nReturn known addresses, which can potentially be used to find new nodes in the network.\n",
|
||||
{
|
||||
{"count", RPCArg::Type::NUM, /* default */ "1", "The maximum number of addresses to return. Specify 0 to return all known addresses."},
|
||||
{"count", RPCArg::Type::NUM, RPCArg::Default{1}, "The maximum number of addresses to return. Specify 0 to return all known addresses."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::ARR, "", "",
|
||||
|
||||
@@ -85,7 +85,7 @@ static RPCHelpMan getrawtransaction()
|
||||
"If verbose is 'false' or omitted, returns a string that is serialized, hex-encoded data for 'txid'.\n",
|
||||
{
|
||||
{"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"},
|
||||
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "If false, return a string, otherwise return a json object"},
|
||||
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED_NAMED_ARG, "The block in which to look for the transaction"},
|
||||
},
|
||||
{
|
||||
@@ -387,7 +387,7 @@ static RPCHelpMan createrawtransaction()
|
||||
{
|
||||
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
|
||||
{"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
|
||||
{"sequence", RPCArg::Type::NUM, /* default */ "depends on the value of the 'replaceable' and 'locktime' arguments", "The sequence number"},
|
||||
{"sequence", RPCArg::Type::NUM, RPCArg::DefaultHint{"depends on the value of the 'replaceable' and 'locktime' arguments"}, "The sequence number"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -409,8 +409,8 @@ static RPCHelpMan createrawtransaction()
|
||||
},
|
||||
},
|
||||
},
|
||||
{"locktime", RPCArg::Type::NUM, /* default */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"},
|
||||
{"replaceable", RPCArg::Type::BOOL, /* default */ "false", "Marks this transaction as BIP125-replaceable.\n"
|
||||
{"locktime", RPCArg::Type::NUM, RPCArg::Default{0}, "Raw locktime. Non-0 value also locktime-activates inputs"},
|
||||
{"replaceable", RPCArg::Type::BOOL, RPCArg::Default{false}, "Marks this transaction as BIP125-replaceable.\n"
|
||||
" Allows this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible."},
|
||||
},
|
||||
RPCResult{
|
||||
@@ -449,7 +449,7 @@ static RPCHelpMan decoderawtransaction()
|
||||
"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n",
|
||||
{
|
||||
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction hex string"},
|
||||
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
|
||||
{"iswitness", RPCArg::Type::BOOL, RPCArg::DefaultHint{"depends on heuristic tests"}, "Whether the transaction hex is a serialized witness transaction.\n"
|
||||
"If iswitness is not present, heuristic tests will be used in decoding.\n"
|
||||
"If true, only witness deserialization will be tried.\n"
|
||||
"If false, only non-witness deserialization will be tried.\n"
|
||||
@@ -752,7 +752,7 @@ static RPCHelpMan signrawtransactionwithkey()
|
||||
},
|
||||
},
|
||||
},
|
||||
{"sighashtype", RPCArg::Type::STR, /* default */ "ALL", "The signature hash type. Must be one of:\n"
|
||||
{"sighashtype", RPCArg::Type::STR, RPCArg::Default{"ALL"}, "The signature hash type. Must be one of:\n"
|
||||
" \"ALL\"\n"
|
||||
" \"NONE\"\n"
|
||||
" \"SINGLE\"\n"
|
||||
@@ -832,7 +832,7 @@ static RPCHelpMan sendrawtransaction()
|
||||
"\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
|
||||
{
|
||||
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"},
|
||||
{"maxfeerate", RPCArg::Type::AMOUNT, /* default */ FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK()),
|
||||
{"maxfeerate", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK())},
|
||||
"Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT +
|
||||
"/kB.\nSet to 0 to accept any fee rate.\n"},
|
||||
},
|
||||
@@ -895,7 +895,7 @@ static RPCHelpMan testmempoolaccept()
|
||||
{"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""},
|
||||
},
|
||||
},
|
||||
{"maxfeerate", RPCArg::Type::AMOUNT, /* default */ FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK()), "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT + "/kB\n"},
|
||||
{"maxfeerate", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK())}, "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT + "/kB\n"},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::ARR, "", "The result of the mempool acceptance test for each raw transaction in the input array.\n"
|
||||
@@ -1362,7 +1362,7 @@ static RPCHelpMan finalizepsbt()
|
||||
"Implements the Finalizer and Extractor roles.\n",
|
||||
{
|
||||
{"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "A base64 string of a PSBT"},
|
||||
{"extract", RPCArg::Type::BOOL, /* default */ "true", "If true and the transaction is complete,\n"
|
||||
{"extract", RPCArg::Type::BOOL, RPCArg::Default{true}, "If true and the transaction is complete,\n"
|
||||
" extract and return the complete transaction in normal network serialization instead of the PSBT."},
|
||||
},
|
||||
RPCResult{
|
||||
@@ -1424,7 +1424,7 @@ static RPCHelpMan createpsbt()
|
||||
{
|
||||
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
|
||||
{"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
|
||||
{"sequence", RPCArg::Type::NUM, /* default */ "depends on the value of the 'replaceable' and 'locktime' arguments", "The sequence number"},
|
||||
{"sequence", RPCArg::Type::NUM, RPCArg::DefaultHint{"depends on the value of the 'replaceable' and 'locktime' arguments"}, "The sequence number"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1446,8 +1446,8 @@ static RPCHelpMan createpsbt()
|
||||
},
|
||||
},
|
||||
},
|
||||
{"locktime", RPCArg::Type::NUM, /* default */ "0", "Raw locktime. Non-0 value also locktime-activates inputs"},
|
||||
{"replaceable", RPCArg::Type::BOOL, /* default */ "false", "Marks this transaction as BIP125 replaceable.\n"
|
||||
{"locktime", RPCArg::Type::NUM, RPCArg::Default{0}, "Raw locktime. Non-0 value also locktime-activates inputs"},
|
||||
{"replaceable", RPCArg::Type::BOOL, RPCArg::Default{false}, "Marks this transaction as BIP125 replaceable.\n"
|
||||
" Allows this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible."},
|
||||
},
|
||||
RPCResult{
|
||||
@@ -1499,9 +1499,9 @@ static RPCHelpMan converttopsbt()
|
||||
"createpsbt and walletcreatefundedpsbt should be used for new applications.\n",
|
||||
{
|
||||
{"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"
|
||||
{"permitsigdata", RPCArg::Type::BOOL, RPCArg::Default{false}, "If true, any signatures in the input will be discarded and conversion\n"
|
||||
" will continue. If false, RPC will fail if any signatures are present."},
|
||||
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
|
||||
{"iswitness", RPCArg::Type::BOOL, RPCArg::DefaultHint{"depends on heuristic tests"}, "Whether the transaction hex is a serialized witness transaction.\n"
|
||||
"If iswitness is not present, heuristic tests will be used in decoding.\n"
|
||||
"If true, only witness deserialization will be tried.\n"
|
||||
"If false, only non-witness deserialization will be tried.\n"
|
||||
@@ -1571,7 +1571,7 @@ static RPCHelpMan utxoupdatepsbt()
|
||||
{"", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "An output descriptor"},
|
||||
{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "An object with an output descriptor and extra information", {
|
||||
{"desc", RPCArg::Type::STR, RPCArg::Optional::NO, "An output descriptor"},
|
||||
{"range", RPCArg::Type::RANGE, "1000", "Up to what index HD chains should be explored (either end or [begin,end])"},
|
||||
{"range", RPCArg::Type::RANGE, RPCArg::Default{1000}, "Up to what index HD chains should be explored (either end or [begin,end])"},
|
||||
}},
|
||||
}},
|
||||
},
|
||||
|
||||
@@ -135,7 +135,7 @@ static RPCHelpMan help()
|
||||
return RPCHelpMan{"help",
|
||||
"\nList all commands, or get help for a specified command.\n",
|
||||
{
|
||||
{"command", RPCArg::Type::STR, /* default */ "all commands", "The command to get help on"},
|
||||
{"command", RPCArg::Type::STR, RPCArg::DefaultHint{"all commands"}, "The command to get help on"},
|
||||
},
|
||||
{
|
||||
RPCResult{RPCResult::Type::STR, "", "The help text"},
|
||||
|
||||
@@ -498,6 +498,33 @@ RPCHelpMan::RPCHelpMan(std::string name, std::string description, std::vector<RP
|
||||
for (const std::string& name : names) {
|
||||
CHECK_NONFATAL(named_args.insert(name).second);
|
||||
}
|
||||
// Default value type should match argument type only when defined
|
||||
if (arg.m_fallback.index() == 2) {
|
||||
const RPCArg::Type type = arg.m_type;
|
||||
switch (std::get<RPCArg::Default>(arg.m_fallback).getType()) {
|
||||
case UniValue::VOBJ:
|
||||
CHECK_NONFATAL(type == RPCArg::Type::OBJ);
|
||||
break;
|
||||
case UniValue::VARR:
|
||||
CHECK_NONFATAL(type == RPCArg::Type::ARR);
|
||||
break;
|
||||
case UniValue::VSTR:
|
||||
CHECK_NONFATAL(type == RPCArg::Type::STR || type == RPCArg::Type::STR_HEX || type == RPCArg::Type::AMOUNT);
|
||||
break;
|
||||
case UniValue::VNUM:
|
||||
CHECK_NONFATAL(type == RPCArg::Type::NUM || type == RPCArg::Type::AMOUNT || type == RPCArg::Type::RANGE);
|
||||
break;
|
||||
case UniValue::VBOOL:
|
||||
CHECK_NONFATAL(type == RPCArg::Type::BOOL);
|
||||
break;
|
||||
case UniValue::VNULL:
|
||||
// Null values are accepted in all arguments
|
||||
break;
|
||||
default:
|
||||
CHECK_NONFATAL(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,7 +673,7 @@ std::string RPCArg::GetName() const
|
||||
|
||||
bool RPCArg::IsOptional() const
|
||||
{
|
||||
if (m_fallback.index() == 1) {
|
||||
if (m_fallback.index() != 0) {
|
||||
return true;
|
||||
} else {
|
||||
return RPCArg::Optional::NO != std::get<RPCArg::Optional>(m_fallback);
|
||||
@@ -694,7 +721,9 @@ std::string RPCArg::ToDescriptionString() const
|
||||
} // no default case, so the compiler can warn about missing cases
|
||||
}
|
||||
if (m_fallback.index() == 1) {
|
||||
ret += ", optional, default=" + std::get<std::string>(m_fallback);
|
||||
ret += ", optional, default=" + std::get<RPCArg::DefaultHint>(m_fallback);
|
||||
} else if (m_fallback.index() == 2) {
|
||||
ret += ", optional, default=" + std::get<RPCArg::Default>(m_fallback).write();
|
||||
} else {
|
||||
switch (std::get<RPCArg::Optional>(m_fallback)) {
|
||||
case RPCArg::Optional::OMITTED: {
|
||||
|
||||
@@ -145,7 +145,9 @@ struct RPCArg {
|
||||
*/
|
||||
OMITTED,
|
||||
};
|
||||
using Fallback = std::variant<Optional, /* default value for optional args */ std::string>;
|
||||
using DefaultHint = std::string;
|
||||
using Default = UniValue;
|
||||
using Fallback = std::variant<Optional, /* hint for default value */ DefaultHint, /* default constant value */ Default>;
|
||||
const std::string m_names; //!< The name of the arg (can be empty for inner args, can contain multiple aliases separated by | for named request arguments)
|
||||
const Type m_type;
|
||||
const bool m_hidden;
|
||||
|
||||
Reference in New Issue
Block a user