Skip to content

Commit b4d9cc1

Browse files
MarcoFalkevijaydasmp
authored andcommitted
Merge bitcoin#21679: rpc: Keep default argument value in correct type
bee56c7 rpc: Check default value type againts argument type (João Barbosa) f81ef43 rpc: 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 bitcoin#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: ACK bee56c7 MarcoFalke: ACK bee56c7 🦅 Tree-SHA512: c47d78c918e996d36631d4ad3c933b270a34c5b446b8d736be94cf4a0a7b8c0e33d954149ec786cf9550639865b79deb6a130ad044de6030f95aac33f524293a
1 parent a1d231e commit b4d9cc1

File tree

15 files changed

+288
-256
lines changed

15 files changed

+288
-256
lines changed

src/rpc/blockchain.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static RPCHelpMan waitfornewblock()
289289
"\nWaits for a specific new block and returns useful info about it.\n"
290290
"\nReturns the current block on timeout or exit.\n",
291291
{
292-
{"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."},
292+
{"timeout", RPCArg::Type::NUM, RPCArg::Default{0}, "Time in milliseconds to wait for a response. 0 indicates no timeout."},
293293
},
294294
RPCResult{
295295
RPCResult::Type::OBJ, "", "",
@@ -332,7 +332,7 @@ static RPCHelpMan waitforblock()
332332
"\nReturns the current block on timeout or exit.\n",
333333
{
334334
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "Block hash to wait for."},
335-
{"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."},
335+
{"timeout", RPCArg::Type::NUM, RPCArg::Default{0}, "Time in milliseconds to wait for a response. 0 indicates no timeout."},
336336
},
337337
RPCResult{
338338
RPCResult::Type::OBJ, "", "",
@@ -379,7 +379,7 @@ static RPCHelpMan waitforblockheight()
379379
"\nReturns the current block on timeout or exit.\n",
380380
{
381381
{"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "Block height to wait for."},
382-
{"timeout", RPCArg::Type::NUM, /* default */ "0", "Time in milliseconds to wait for a response. 0 indicates no timeout."},
382+
{"timeout", RPCArg::Type::NUM, RPCArg::Default{0}, "Time in milliseconds to wait for a response. 0 indicates no timeout."},
383383
},
384384
RPCResult{
385385
RPCResult::Type::OBJ, "", "",
@@ -572,6 +572,7 @@ UniValue MempoolToJSON(const CTxMemPool& pool, llmq::CInstantSendManager* isman,
572572
return o;
573573
}
574574
}
575+
575576
}
576577

577578
static RPCHelpMan getrawmempool()
@@ -580,8 +581,8 @@ static RPCHelpMan getrawmempool()
580581
"\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n"
581582
"\nHint: use getmempoolentry to fetch a specific transaction from the mempool.\n",
582583
{
583-
{"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"},
584-
{"mempool_sequence", RPCArg::Type::BOOL, /* default */ "false", "If verbose=false, returns a json object with transaction list and mempool sequence number attached."},
584+
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
585+
{"mempool_sequence", RPCArg::Type::BOOL, RPCArg::Default{false}, "If verbose=false, returns a json object with transaction list and mempool sequence number attached."},
585586
},
586587
{
587588
RPCResult{"for verbose = false",
@@ -633,7 +634,7 @@ static RPCHelpMan getmempoolancestors()
633634
"\nIf txid is in the mempool, returns all in-mempool ancestors.\n",
634635
{
635636
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
636-
{"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"},
637+
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
637638
},
638639
{
639640
RPCResult{"for verbose = false",
@@ -700,7 +701,7 @@ static RPCHelpMan getmempooldescendants()
700701
"\nIf txid is in the mempool, returns all in-mempool descendants.\n",
701702
{
702703
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
703-
{"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"},
704+
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
704705
},
705706
{
706707
RPCResult{"for verbose = false",
@@ -923,7 +924,7 @@ static RPCHelpMan getblockheader()
923924
"If verbose is true, returns an Object with information about blockheader <hash>.\n",
924925
{
925926
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
926-
{"verbose", RPCArg::Type::BOOL, /* default */ "true", "true for a json object, false for the hex-encoded data"},
927+
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{true}, "true for a json object, false for the hex-encoded data"},
927928
},
928929
{
929930
RPCResult{"for verbose = true",
@@ -997,8 +998,8 @@ static RPCHelpMan getblockheaders()
997998
"If verbose is true, each item is an Object with information about a single blockheader.\n",
998999
{
9991000
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
1000-
{"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS_UNCOMPRESSED_RESULT), ""},
1001-
{"verbose", RPCArg::Type::BOOL, /* default */ "true", "true for a json object, false for the hex-encoded data"},
1001+
{"count", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%s", MAX_HEADERS_UNCOMPRESSED_RESULT)}, ""},
1002+
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{true}, "true for a json object, false for the hex-encoded data"},
10021003
},
10031004
{
10041005
RPCResult{"for verbose = true",
@@ -1135,7 +1136,7 @@ static RPCHelpMan getmerkleblocks()
11351136
{
11361137
{"filter", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded bloom filter"},
11371138
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
1138-
{"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS_UNCOMPRESSED_RESULT), ""},
1139+
{"count", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%s", MAX_HEADERS_UNCOMPRESSED_RESULT)}, ""},
11391140
},
11401141
RPCResult{
11411142
RPCResult::Type::ARR, "", "",
@@ -1211,7 +1212,7 @@ static RPCHelpMan getblock()
12111212
"If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n",
12121213
{
12131214
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
1214-
{"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"},
1215+
{"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"},
12151216
},
12161217
{
12171218
RPCResult{"for verbosity = 0",
@@ -1388,9 +1389,9 @@ static RPCHelpMan gettxoutsetinfo()
13881389
"\nReturns statistics about the unspent transaction output set.\n"
13891390
"Note this call may take some time if you are not using coinstatsindex.\n",
13901391
{
1391-
{"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'."},
1392+
{"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'."},
13921393
{"hash_or_height", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The block hash or height of the target height (only available with coinstatsindex).", "", {"", "string or numeric"}},
1393-
{"use_index", RPCArg::Type::BOOL, /* default */ "true", "Use coinstatsindex, if available."},
1394+
{"use_index", RPCArg::Type::BOOL, RPCArg::Default{true}, "Use coinstatsindex, if available."},
13941395
},
13951396
RPCResult{
13961397
RPCResult::Type::OBJ, "", "",
@@ -1532,7 +1533,7 @@ static RPCHelpMan gettxout()
15321533
{
15331534
{"txid", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction id"},
15341535
{"n", RPCArg::Type::NUM, RPCArg::Optional::NO, "vout number"},
1535-
{"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."},
1536+
{"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."},
15361537
},
15371538
{
15381539
RPCResult{"If the UTXO was not found", RPCResult::Type::NONE, "", ""},
@@ -1619,10 +1620,10 @@ static RPCHelpMan verifychain()
16191620
return RPCHelpMan{"verifychain",
16201621
"\nVerifies blockchain database.\n",
16211622
{
1622-
{"checklevel", RPCArg::Type::NUM, /* default */ strprintf("%d, range=0-4", DEFAULT_CHECKLEVEL),
1623+
{"checklevel", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%d, range=0-4", DEFAULT_CHECKLEVEL)},
16231624
strprintf("How thorough the block verification is:\n - %s", MakeUnorderedList(CHECKLEVEL_DOC))},
1624-
{"nblocks", RPCArg::Type::NUM, /* default */ strprintf("%d, 0=all", DEFAULT_CHECKBLOCKS), "The number of blocks to check."},
1625-
},
1625+
{"nblocks", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%d, 0=all", DEFAULT_CHECKBLOCKS)}, "The number of blocks to check."},
1626+
},
16261627
RPCResult{
16271628
RPCResult::Type::BOOL, "", "Verified or not"},
16281629
RPCExamples{
@@ -1872,8 +1873,8 @@ static RPCHelpMan getchaintips()
18721873
"Return information about all known tips in the block tree,"
18731874
" including the main chain as well as orphaned branches.\n",
18741875
{
1875-
{"count", RPCArg::Type::NUM, /* default */ "", "only show this much of latest tips"},
1876-
{"branchlen", RPCArg::Type::NUM, /* default */ "", "only show tips that have equal or greater length of branch"},
1876+
{"count", RPCArg::Type::NUM, RPCArg::DefaultHint{""}, "only show this much of latest tips"},
1877+
{"branchlen", RPCArg::Type::NUM, RPCArg::DefaultHint{""}, "only show tips that have equal or greater length of branch"},
18771878
},
18781879
RPCResult{
18791880
RPCResult::Type::ARR, "", "",
@@ -2174,8 +2175,8 @@ static RPCHelpMan getchaintxstats()
21742175
return RPCHelpMan{"getchaintxstats",
21752176
"\nCompute statistics about the total number and rate of transactions in the chain.\n",
21762177
{
2177-
{"nblocks", RPCArg::Type::NUM, /* default */ "one month", "Size of the window in number of blocks"},
2178-
{"blockhash", RPCArg::Type::STR_HEX, /* default */ "chain tip", "The hash of the block that ends the window."},
2178+
{"nblocks", RPCArg::Type::NUM, RPCArg::DefaultHint{"one month"}, "Size of the window in number of blocks"},
2179+
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::DefaultHint{"chain tip"}, "The hash of the block that ends the window."},
21792180
},
21802181
RPCResult{
21812182
RPCResult::Type::OBJ, "", "",
@@ -2324,7 +2325,7 @@ static RPCHelpMan getblockstats()
23242325
"It won't work for some heights with pruning.\n",
23252326
{
23262327
{"hash_or_height", RPCArg::Type::NUM, RPCArg::Optional::NO, "The block hash or height of the target block", "", {"", "string or numeric"}},
2327-
{"stats", RPCArg::Type::ARR, /* default */ "all values", "Values to plot (see result below)",
2328+
{"stats", RPCArg::Type::ARR, RPCArg::DefaultHint{"all values"}, "Values to plot (see result below)",
23282329
{
23292330
{"height", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Selected statistic"},
23302331
{"time", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Selected statistic"},
@@ -2542,10 +2543,10 @@ static RPCHelpMan getspecialtxes()
25422543
"If verbosity is 2, returns an Object with information for each transaction.\n",
25432544
{
25442545
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
2545-
{"type", RPCArg::Type::NUM, /* default */ "-1", "Filter special txes by type, -1 means all types"},
2546-
{"count", RPCArg::Type::NUM, /* default */ "10", "The number of transactions to return"},
2547-
{"skip", RPCArg::Type::NUM, /* default */ "0", "The number of transactions to skip"},
2548-
{"verbosity", RPCArg::Type::NUM, /* default */ "0", "0 for hashes, 1 for hex-encoded data, and 2 for json object"},
2546+
{"type", RPCArg::Type::NUM, RPCArg::Default{-1}, "Filter special txes by type, -1 means all types"},
2547+
{"count", RPCArg::Type::NUM, RPCArg::Default{10}, "The number of transactions to return"},
2548+
{"skip", RPCArg::Type::NUM, RPCArg::Default{0}, "The number of transactions to skip"},
2549+
{"verbosity", RPCArg::Type::NUM, RPCArg::Default{0}, "0 for hashes, 1 for hex-encoded data, and 2 for json object"},
25492550
},
25502551
{
25512552
RPCResult{"for verbosity = 0",
@@ -2767,7 +2768,7 @@ static RPCHelpMan scantxoutset()
27672768
{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "An object with output descriptor and metadata",
27682769
{
27692770
{"desc", RPCArg::Type::STR, RPCArg::Optional::NO, "An output descriptor"},
2770-
{"range", RPCArg::Type::RANGE, /* default */ "1000", "The range of HD chain indexes to explore (either end or [begin,end])"},
2771+
{"range", RPCArg::Type::RANGE, RPCArg::Default{1000}, "The range of HD chain indexes to explore (either end or [begin,end])"},
27712772
},
27722773
},
27732774
},
@@ -2913,7 +2914,7 @@ static RPCHelpMan getblockfilter()
29132914
"\nRetrieve a BIP 157 content filter for a particular block.\n",
29142915
{
29152916
{"blockhash", RPCArg::Type::STR, RPCArg::Optional::NO, "The hash of the block"},
2916-
{"filtertype", RPCArg::Type::STR, /* default */ "basic", "The type name of the filter"},
2917+
{"filtertype", RPCArg::Type::STR, RPCArg::Default{"basic"}, "The type name of the filter"},
29172918
},
29182919
RPCResult{
29192920
RPCResult::Type::OBJ, "", "",

src/rpc/coinjoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static RPCHelpMan coinjoinsalt_generate()
207207
"\nGenerate new CoinJoin salt and store it in the wallet database\n"
208208
"Cannot generate new salt if CoinJoin mixing is in process or wallet has private keys disabled.\n",
209209
{
210-
{"overwrite", RPCArg::Type::BOOL, /* default */ "false", "Generate new salt even if there is an existing salt and/or there is CoinJoin balance"},
210+
{"overwrite", RPCArg::Type::BOOL, RPCArg::Default{false}, "Generate new salt even if there is an existing salt and/or there is CoinJoin balance"},
211211
},
212212
RPCResult{
213213
RPCResult::Type::BOOL, "", "Status of CoinJoin salt generation and commitment"
@@ -309,7 +309,7 @@ static RPCHelpMan coinjoinsalt_set()
309309
"Will overwrite existing salt. The presence of a CoinJoin balance will cause the wallet to rescan.\n",
310310
{
311311
{"salt", RPCArg::Type::STR, RPCArg::Optional::NO, "Desired CoinJoin salt value for the wallet"},
312-
{"overwrite", RPCArg::Type::BOOL, /* default */ "false", "Overwrite salt even if CoinJoin balance present"},
312+
{"overwrite", RPCArg::Type::BOOL, RPCArg::Default{false}, "Overwrite salt even if CoinJoin balance present"},
313313
},
314314
RPCResult{
315315
RPCResult::Type::BOOL, "", "Status of CoinJoin salt change request"

0 commit comments

Comments
 (0)