You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rpc: Add check for unintended option/parameter name clashes
Also add flag to allow RPC methods that intendionally accept options and
parameters with the same name bypass the check.
Check and flag were suggested by ajtowns
bitcoin/bitcoin#26485 (comment)
Co-authored-by: Anthony Towns <aj@erisian.com.au>
Copy file name to clipboardExpand all lines: src/rpc/util.h
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -130,6 +130,15 @@ struct RPCArgOptions {
130
130
std::string oneline_description{}; //!< Should be empty unless it is supposed to override the auto-generated summary line
131
131
std::vector<std::string> type_str{}; //!< Should be empty unless it is supposed to override the auto-generated type strings. Vector length is either 0 or 2, m_opts.type_str.at(0) will override the type of the value in a key-value pair, m_opts.type_str.at(1) will override the type in the argument description.
132
132
bool hidden{false}; //!< For testing only
133
+
bool also_positional{false}; //!< If set allows a named-parameter field in an OBJ_NAMED_PARAM options object
134
+
//!< to have the same name as a top-level parameter. By default the RPC
135
+
//!< framework disallows this, because if an RPC request passes the value by
136
+
//!< name, it is assigned to top-level parameter position, not to the options
137
+
//!< position, defeating the purpose of using OBJ_NAMED_PARAMS instead OBJ for
138
+
//!< that option. But sometimes it makes sense to allow less-commonly used
139
+
//!< options to be passed by name only, and more commonly used options to be
140
+
//!< passed by name or position, so the RPC framework allows this as long as
141
+
//!< methods set the also_positional flag and read values from both positions.
"replaceable", RPCArg::Type::BOOL, RPCArg::DefaultHint{"wallet default"}, "Marks this transaction as BIP125-replaceable.\n"
461
461
"Allows this transaction to be replaced by a transaction with higher fees"
@@ -1200,7 +1200,7 @@ RPCHelpMan send()
1200
1200
{"change_address", RPCArg::Type::STR, RPCArg::DefaultHint{"automatic"}, "The bitcoin address to receive the change"},
1201
1201
{"change_position", RPCArg::Type::NUM, RPCArg::DefaultHint{"random"}, "The index of the change output"},
1202
1202
{"change_type", RPCArg::Type::STR, RPCArg::DefaultHint{"set by -changetype"}, "The output type to use. Only valid if change_address is not specified. Options are \"legacy\", \"p2sh-segwit\", \"bech32\" and \"bech32m\"."},
1203
-
{"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},
1203
+
{"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB.", RPCArgOptions{.also_positional = true}},
1204
1204
{"include_watching", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Also select inputs which are watch only.\n"
1205
1205
"Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or output script was imported,\n"
1206
1206
"e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field."},
@@ -1306,7 +1306,7 @@ RPCHelpMan sendall()
1306
1306
Cat<std::vector<RPCArg>>(
1307
1307
{
1308
1308
{"add_to_wallet", RPCArg::Type::BOOL, RPCArg::Default{true}, "When false, returns the serialized transaction without broadcasting or adding it to the wallet"},
1309
-
{"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB."},
1309
+
{"fee_rate", RPCArg::Type::AMOUNT, RPCArg::DefaultHint{"not set, fall back to wallet fee estimation"}, "Specify a fee rate in " + CURRENCY_ATOM + "/vB.", RPCArgOptions{.also_positional = true}},
1310
1310
{"include_watching", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Also select inputs which are watch-only.\n"
1311
1311
"Only solvable inputs can be used. Watch-only destinations are solvable if the public key and/or output script was imported,\n"
1312
1312
"e.g. with 'importpubkey' or 'importmulti' with the 'pubkeys' or 'desc' field."},
0 commit comments