Skip to content

Commit f080c65

Browse files
author
MarcoFalke
committed
Merge #14875: RPCHelpMan: Support required arguments after optional ones
fa9a5bc RPCHelpMan: Support required arguments after optional ones (MarcoFalke) Pull request description: There was a requirement that required arguments could not be positioned after an optional argument, but the deprecation of priority made the second argument to `prioritisetransaction` optional. So support that in `RPCHelpMan`. Also format all named arguments in the same way (without the wrapping `"` even for strings), since the extended description already mentions the type and it feels odd to special case strings. Tree-SHA512: c125145afb4a63abc995aaf0a89489efc0f470a720727a1ca6ee0bfd2bcbc59e87c38128dd1e0cdf03dbb5b18e84867887c3dabf6ec8378e66cb1f4cecb9e407
2 parents d419781 + fa9a5bc commit f080c65

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
241241
"Accepts the transaction into mined blocks at a higher (or lower) priority\n",
242242
{
243243
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, /* default_val */ "", "The transaction id."},
244-
{"dummy", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "API-Compatibility for previous API. Must be zero or null.\n"
244+
{"dummy", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "null", "API-Compatibility for previous API. Must be zero or null.\n"
245245
" DEPRECATED. For forward compatibility use named arguments and omit this parameter."},
246246
{"fee_delta", RPCArg::Type::NUM, /* opt */ false, /* default_val */ "", "The fee value (in satoshis) to add (or subtract, if negative).\n"
247247
" Note, that this value is not a fee rate. It is a value to modify absolute fee of the TX.\n"

src/rpc/util.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,19 @@ std::string RPCHelpMan::ToString() const
258258

259259
// Oneline summary
260260
ret += m_name;
261-
bool is_optional{false};
261+
bool was_optional{false};
262262
for (const auto& arg : m_args) {
263263
ret += " ";
264264
if (arg.m_optional) {
265-
if (!is_optional) ret += "( ";
266-
is_optional = true;
265+
if (!was_optional) ret += "( ";
266+
was_optional = true;
267267
} else {
268-
// Currently we still support unnamed arguments, so any argument following an optional argument must also be optional
269-
// If support for positional arguments is deprecated in the future, remove this line
270-
assert(!is_optional);
268+
if (was_optional) ret += ") ";
269+
was_optional = false;
271270
}
272271
ret += arg.ToString(/* oneline */ true);
273272
}
274-
if (is_optional) ret += " )";
273+
if (was_optional) ret += " )";
275274
ret += "\n";
276275

277276
// Description
@@ -285,8 +284,7 @@ std::string RPCHelpMan::ToString() const
285284
if (i == 0) ret += "\nArguments:\n";
286285

287286
// Push named argument name and description
288-
const auto str_wrapper = (arg.m_type == RPCArg::Type::STR || arg.m_type == RPCArg::Type::STR_HEX) ? "\"" : "";
289-
sections.m_sections.emplace_back(std::to_string(i + 1) + ". " + str_wrapper + arg.m_name + str_wrapper, arg.ToDescriptionString());
287+
sections.m_sections.emplace_back(std::to_string(i + 1) + ". " + arg.m_name, arg.ToDescriptionString());
290288
sections.m_max_pad = std::max(sections.m_max_pad, sections.m_sections.back().m_left.size());
291289

292290
// Recursively push nested args

0 commit comments

Comments
 (0)