Skip to content

Commit fa0ad4e

Browse files
author
MarcoFalke
committed
RPCHelpMan: Check default values are given at compile-time
1 parent ff9e197 commit fa0ad4e

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
@@ -92,8 +92,8 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request)
9292
"Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n"
9393
"Pass in [height] to estimate the network speed at the time when a certain block was found.\n",
9494
{
95-
{"nblocks", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "120", "The number of blocks, or -1 for blocks since last difficulty change."},
96-
{"height", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "-1", "To estimate at the time of the given height."},
95+
{"nblocks", RPCArg::Type::NUM, /* default */ "120", "The number of blocks, or -1 for blocks since last difficulty change."},
96+
{"height", RPCArg::Type::NUM, /* default */ "-1", "To estimate at the time of the given height."},
9797
},
9898
RPCResult{
9999
"x (numeric) Hashes per second estimated\n"
@@ -163,9 +163,9 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
163163
RPCHelpMan{"generatetoaddress",
164164
"\nMine blocks immediately to a specified address (before the RPC call returns)\n",
165165
{
166-
{"nblocks", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "How many blocks are generated immediately."},
167-
{"address", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The address to send the newly generated bitcoin to."},
168-
{"maxtries", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "1000000", "How many iterations to try."},
166+
{"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
167+
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address to send the newly generated bitcoin to."},
168+
{"maxtries", RPCArg::Type::NUM, /* default */ "1000000", "How many iterations to try."},
169169
},
170170
RPCResult{
171171
"[ blockhashes ] (array) hashes of blocks generated\n"
@@ -244,10 +244,10 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
244244
RPCHelpMan{"prioritisetransaction",
245245
"Accepts the transaction into mined blocks at a higher (or lower) priority\n",
246246
{
247-
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id."},
248-
{"dummy", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "null", "API-Compatibility for previous API. Must be zero or null.\n"
247+
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id."},
248+
{"dummy", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "API-Compatibility for previous API. Must be zero or null.\n"
249249
" DEPRECATED. For forward compatibility use named arguments and omit this parameter."},
250-
{"fee_delta", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The fee value (in satoshis) to add (or subtract, if negative).\n"
250+
{"fee_delta", RPCArg::Type::NUM, RPCArg::Optional::NO, "The fee value (in satoshis) to add (or subtract, if negative).\n"
251251
" Note, that this value is not a fee rate. It is a value to modify absolute fee of the TX.\n"
252252
" The fee is not actually paid, only the algorithm for selecting transactions into a block\n"
253253
" considers the transaction as it would have paid a higher (or lower) fee."},
@@ -316,17 +316,17 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
316316
" https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n"
317317
" https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki\n",
318318
{
319-
{"template_request", RPCArg::Type::OBJ, /* opt */ false, /* default_val */ "", "A json object in the following spec",
319+
{"template_request", RPCArg::Type::OBJ, RPCArg::Optional::NO, "A json object in the following spec",
320320
{
321-
{"mode", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "This must be set to \"template\", \"proposal\" (see BIP 23), or omitted"},
322-
{"capabilities", RPCArg::Type::ARR, /* opt */ true, /* default_val */ "", "A list of strings",
321+
{"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"},
322+
{"capabilities", RPCArg::Type::ARR, /* treat as named arg */ RPCArg::Optional::OMITTED_NAMED_ARG, "A list of strings",
323323
{
324-
{"support", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'"},
324+
{"support", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'"},
325325
},
326326
},
327-
{"rules", RPCArg::Type::ARR, /* opt */ false, /* default_val */ "", "A list of strings",
327+
{"rules", RPCArg::Type::ARR, RPCArg::Optional::NO, "A list of strings",
328328
{
329-
{"support", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "client side supported softfork deployment"},
329+
{"support", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported softfork deployment"},
330330
},
331331
},
332332
},
@@ -716,8 +716,8 @@ static UniValue submitblock(const JSONRPCRequest& request)
716716
"\nAttempts to submit new block to network.\n"
717717
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n",
718718
{
719-
{"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded block data to submit"},
720-
{"dummy", RPCArg::Type::STR, /* opt */ true, /* default_val */ "ignored", "dummy value, for compatibility with BIP22. This value is ignored."},
719+
{"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded block data to submit"},
720+
{"dummy", RPCArg::Type::STR, /* default */ "ignored", "dummy value, for compatibility with BIP22. This value is ignored."},
721721
},
722722
RPCResults{},
723723
RPCExamples{
@@ -781,7 +781,7 @@ static UniValue submitheader(const JSONRPCRequest& request)
781781
"\nDecode the given hexdata as a header and submit it as a candidate chain tip if valid."
782782
"\nThrows when the header is invalid.\n",
783783
{
784-
{"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "the hex-encoded block header data"},
784+
{"hexdata", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded block header data"},
785785
},
786786
RPCResult{
787787
"None"
@@ -823,8 +823,8 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
823823
"for which the estimate is valid. Uses virtual transaction size as defined\n"
824824
"in BIP 141 (witness data is discounted).\n",
825825
{
826-
{"conf_target", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "Confirmation target in blocks (1 - 1008)"},
827-
{"estimate_mode", RPCArg::Type::STR, /* opt */ true, /* default_val */ "CONSERVATIVE", "The fee estimate mode.\n"
826+
{"conf_target", RPCArg::Type::NUM, RPCArg::Optional::NO, "Confirmation target in blocks (1 - 1008)"},
827+
{"estimate_mode", RPCArg::Type::STR, /* default */ "CONSERVATIVE", "The fee estimate mode.\n"
828828
" Whether to return a more conservative estimate which also satisfies\n"
829829
" a longer history. A conservative estimate potentially returns a\n"
830830
" higher feerate and is more likely to be sufficient for the desired\n"
@@ -890,8 +890,8 @@ static UniValue estimaterawfee(const JSONRPCRequest& request)
890890
"confirmation within conf_target blocks if possible. Uses virtual transaction size as\n"
891891
"defined in BIP 141 (witness data is discounted).\n",
892892
{
893-
{"conf_target", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "Confirmation target in blocks (1 - 1008)"},
894-
{"threshold", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "0.95", "The proportion of transactions in a given feerate range that must have been\n"
893+
{"conf_target", RPCArg::Type::NUM, RPCArg::Optional::NO, "Confirmation target in blocks (1 - 1008)"},
894+
{"threshold", RPCArg::Type::NUM, /* default */ "0.95", "The proportion of transactions in a given feerate range that must have been\n"
895895
" confirmed within conf_target in order to consider those feerates as high enough and proceed to check\n"
896896
" lower buckets."},
897897
},

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)