Skip to content

Commit 0d1160e

Browse files
author
MarcoFalke
committed
Merge #14918: RPCHelpMan: Check default values are given at compile-time
fa0ad4e RPCHelpMan: Check default values are given at compile-time (MarcoFalke) Pull request description: Remove the run time assertions on the default values and ensure that the correct default type and value is provided at compile time. Tree-SHA512: 80df2f3fab4379b500c773c27da63f22786c58be5963fe99744746320e43627a5d433eedf8b32209158df7805ebdce65ed4d242c829c4fe6e5d13deb4799ed42
2 parents 029d28a + fa0ad4e commit 0d1160e

File tree

10 files changed

+388
-363
lines changed

10 files changed

+388
-363
lines changed

src/rpc/blockchain.cpp

Lines changed: 37 additions & 37 deletions
Large diffs are not rendered by default.

src/rpc/mining.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request)
8282
"Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n"
8383
"Pass in [height] to estimate the network speed at the time when a certain block was found.\n",
8484
{
85-
{"nblocks", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "120", "The number of blocks, or -1 for blocks since last difficulty change."},
86-
{"height", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "-1", "To estimate at the time of the given height."},
85+
{"nblocks", RPCArg::Type::NUM, /* default */ "120", "The number of blocks, or -1 for blocks since last difficulty change."},
86+
{"height", RPCArg::Type::NUM, /* default */ "-1", "To estimate at the time of the given height."},
8787
},
8888
RPCResult{
8989
"x (numeric) Hashes per second estimated\n"
@@ -153,9 +153,9 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
153153
RPCHelpMan{"generatetoaddress",
154154
"\nMine blocks immediately to a specified address (before the RPC call returns)\n",
155155
{
156-
{"nblocks", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "How many blocks are generated immediately."},
157-
{"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The address to send the newly generated bitcoin to."},
158-
{"maxtries", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "1000000", "How many iterations to try."},
156+
{"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
157+
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address to send the newly generated bitcoin to."},
158+
{"maxtries", RPCArg::Type::NUM, /* default */ "1000000", "How many iterations to try."},
159159
},
160160
RPCResult{
161161
"[ blockhashes ] (array) hashes of blocks generated\n"
@@ -234,10 +234,10 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
234234
RPCHelpMan{"prioritisetransaction",
235235
"Accepts the transaction into mined blocks at a higher (or lower) priority\n",
236236
{
237-
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id."},
238-
{"dummy", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "null", "API-Compatibility for previous API. Must be zero or null.\n"
237+
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id."},
238+
{"dummy", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "API-Compatibility for previous API. Must be zero or null.\n"
239239
" DEPRECATED. For forward compatibility use named arguments and omit this parameter."},
240-
{"fee_delta", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The fee value (in satoshis) to add (or subtract, if negative).\n"
240+
{"fee_delta", RPCArg::Type::NUM, RPCArg::Optional::NO, "The fee value (in satoshis) to add (or subtract, if negative).\n"
241241
" Note, that this value is not a fee rate. It is a value to modify absolute fee of the TX.\n"
242242
" The fee is not actually paid, only the algorithm for selecting transactions into a block\n"
243243
" considers the transaction as it would have paid a higher (or lower) fee."},
@@ -306,17 +306,17 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
306306
" https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n"
307307
" https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki\n",
308308
{
309-
{"template_request", RPCArg::Type::OBJ, /* opt */ false, /* default_val */ "", "A json object in the following spec",
309+
{"template_request", RPCArg::Type::OBJ, RPCArg::Optional::NO, "A json object in the following spec",
310310
{
311-
{"mode", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "This must be set to \"template\", \"proposal\" (see BIP 23), or omitted"},
312-
{"capabilities", RPCArg::Type::ARR, /* opt */ true, /* default_val */ "", "A list of strings",
311+
{"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"},
312+
{"capabilities", RPCArg::Type::ARR, /* treat as named arg */ RPCArg::Optional::OMITTED_NAMED_ARG, "A list of strings",
313313
{
314-
{"support", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'"},
314+
{"support", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'"},
315315
},
316316
},
317-
{"rules", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "A list of strings",
317+
{"rules", RPCArg::Type::ARR, RPCArg::Optional::NO, "A list of strings",
318318
{
319-
{"support", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "client side supported softfork deployment"},
319+
{"support", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported softfork deployment"},
320320
},
321321
},
322322
},
@@ -706,8 +706,8 @@ static UniValue submitblock(const JSONRPCRequest& request)
706706
"\nAttempts to submit new block to network.\n"
707707
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n",
708708
{
709-
{"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded block data to submit"},
710-
{"dummy", RPCArg::Type::STR, /* opt */ true, /* default_val */ "ignored", "dummy value, for compatibility with BIP22. This value is ignored."},
709+
{"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded block data to submit"},
710+
{"dummy", RPCArg::Type::STR, /* default */ "ignored", "dummy value, for compatibility with BIP22. This value is ignored."},
711711
},
712712
RPCResults{},
713713
RPCExamples{
@@ -771,7 +771,7 @@ static UniValue submitheader(const JSONRPCRequest& request)
771771
"\nDecode the given hexdata as a header and submit it as a candidate chain tip if valid."
772772
"\nThrows when the header is invalid.\n",
773773
{
774-
{"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded block header data"},
774+
{"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded block header data"},
775775
},
776776
RPCResult{
777777
"None"
@@ -813,8 +813,8 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
813813
"for which the estimate is valid. Uses virtual transaction size as defined\n"
814814
"in BIP 141 (witness data is discounted).\n",
815815
{
816-
{"conf_target", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "Confirmation target in blocks (1 - 1008)"},
817-
{"estimate_mode", RPCArg::Type::STR, /* opt */ true, /* default_val */ "CONSERVATIVE", "The fee estimate mode.\n"
816+
{"conf_target", RPCArg::Type::NUM, RPCArg::Optional::NO, "Confirmation target in blocks (1 - 1008)"},
817+
{"estimate_mode", RPCArg::Type::STR, /* default */ "CONSERVATIVE", "The fee estimate mode.\n"
818818
" Whether to return a more conservative estimate which also satisfies\n"
819819
" a longer history. A conservative estimate potentially returns a\n"
820820
" higher feerate and is more likely to be sufficient for the desired\n"
@@ -880,8 +880,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
880880
"confirmation within conf_target blocks if possible. Uses virtual transaction size as\n"
881881
"defined in BIP 141 (witness data is discounted).\n",
882882
{
883-
{"conf_target", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "Confirmation target in blocks (1 - 1008)"},
884-
{"threshold", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0.95", "The proportion of transactions in a given feerate range that must have been\n"
883+
{"conf_target", RPCArg::Type::NUM, RPCArg::Optional::NO, "Confirmation target in blocks (1 - 1008)"},
884+
{"threshold", RPCArg::Type::NUM, /* default */ "0.95", "The proportion of transactions in a given feerate range that must have been\n"
885885
" confirmed within conf_target in order to consider those feerates as high enough and proceed to check\n"
886886
" lower buckets."},
887887
},

src/rpc/misc.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static UniValue validateaddress(const JSONRPCRequest& request)
4040
"fields have moved to getaddressinfo and will only be shown here with -deprecatedrpc=validateaddress: ismine, iswatchonly,\n"
4141
"script, hex, pubkeys, sigsrequired, pubkey, addresses, embedded, iscompressed, account, timestamp, hdkeypath, kdmasterkeyid.\n",
4242
{
43-
{"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The bitcoin address to validate"},
43+
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to validate"},
4444
},
4545
RPCResult{
4646
"{\n"
@@ -87,12 +87,12 @@ static UniValue createmultisig(const JSONRPCRequest& request)
8787
"\nCreates a multi-signature address with n signature of m keys required.\n"
8888
"It returns a json object with the address and redeemScript.\n",
8989
{
90-
{"nrequired", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The number of required signatures out of the n keys."},
91-
{"keys", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "A json array of hex-encoded public keys.",
90+
{"nrequired", RPCArg::Type::NUM, RPCArg::Optional::NO, "The number of required signatures out of the n keys."},
91+
{"keys", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of hex-encoded public keys.",
9292
{
93-
{"key", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The hex-encoded public key"},
93+
{"key", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "The hex-encoded public key"},
9494
}},
95-
{"address_type", RPCArg::Type::STR, /* opt */ true, /* default_val */ "legacy", "The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
95+
{"address_type", RPCArg::Type::STR, /* default */ "legacy", "The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
9696
},
9797
RPCResult{
9898
"{\n"
@@ -158,9 +158,9 @@ UniValue deriveaddresses(const JSONRPCRequest& request)
158158
"or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n"
159159
"For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n"},
160160
{
161-
{"descriptor", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The descriptor."},
162-
{"begin", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "If a ranged descriptor is used, this specifies the beginning of the range to import."},
163-
{"end", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "If a ranged descriptor is used, this specifies the end of the range to import."}
161+
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor."},
162+
{"begin", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "If a ranged descriptor is used, this specifies the beginning of the range to import."},
163+
{"end", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "If a ranged descriptor is used, this specifies the end of the range to import."}
164164
},
165165
RPCResult{
166166
"[ address ] (array) the derived addresses\n"
@@ -239,9 +239,9 @@ static UniValue verifymessage(const JSONRPCRequest& request)
239239
RPCHelpMan{"verifymessage",
240240
"\nVerify a signed message\n",
241241
{
242-
{"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The bitcoin address to use for the signature."},
243-
{"signature", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The signature provided by the signer in base 64 encoding (see signmessage)."},
244-
{"message", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The message that was signed."},
242+
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to use for the signature."},
243+
{"signature", RPCArg::Type::STR, RPCArg::Optional::NO, "The signature provided by the signer in base 64 encoding (see signmessage)."},
244+
{"message", RPCArg::Type::STR, RPCArg::Optional::NO, "The message that was signed."},
245245
},
246246
RPCResult{
247247
"true|false (boolean) If the signature is verified or not.\n"
@@ -298,8 +298,8 @@ static UniValue signmessagewithprivkey(const JSONRPCRequest& request)
298298
RPCHelpMan{"signmessagewithprivkey",
299299
"\nSign a message with the private key of an address\n",
300300
{
301-
{"privkey", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The private key to sign the message with."},
302-
{"message", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The message to create a signature of."},
301+
{"privkey", RPCArg::Type::STR, RPCArg::Optional::NO, "The private key to sign the message with."},
302+
{"message", RPCArg::Type::STR, RPCArg::Optional::NO, "The message to create a signature of."},
303303
},
304304
RPCResult{
305305
"\"signature\" (string) The signature of the message encoded in base 64\n"
@@ -340,7 +340,7 @@ static UniValue setmocktime(const JSONRPCRequest& request)
340340
RPCHelpMan{"setmocktime",
341341
"\nSet the local time to given timestamp (-regtest only)\n",
342342
{
343-
{"timestamp", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "Unix seconds-since-epoch timestamp\n"
343+
{"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, "Unix seconds-since-epoch timestamp\n"
344344
" Pass 0 to go back to using the system time."},
345345
},
346346
RPCResults{},
@@ -406,7 +406,7 @@ static UniValue getmemoryinfo(const JSONRPCRequest& request)
406406
RPCHelpMan{"getmemoryinfo",
407407
"Returns an object containing information about memory usage.\n",
408408
{
409-
{"mode", RPCArg::Type::STR, /* opt */ true, /* default_val */ "\"stats\"", "determines what kind of information is returned.\n"
409+
{"mode", RPCArg::Type::STR, /* default */ "\"stats\"", "determines what kind of information is returned.\n"
410410
" - \"stats\" returns general statistics about memory usage in the daemon.\n"
411411
" - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+)."},
412412
},
@@ -483,13 +483,13 @@ UniValue logging(const JSONRPCRequest& request)
483483
" - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n"
484484
,
485485
{
486-
{"include", RPCArg::Type::ARR, /* opt */ true, /* default_val */ "null", "A json array of categories to add debug logging",
486+
{"include", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of categories to add debug logging",
487487
{
488-
{"include_category", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "the valid logging category"},
488+
{"include_category", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "the valid logging category"},
489489
}},
490-
{"exclude", RPCArg::Type::ARR, /* opt */ true, /* default_val */ "null", "A json array of categories to remove debug logging",
490+
{"exclude", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "A json array of categories to remove debug logging",
491491
{
492-
{"exclude_category", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "the valid logging category"},
492+
{"exclude_category", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "the valid logging category"},
493493
}},
494494
},
495495
RPCResult{

0 commit comments

Comments
 (0)