Reworked #11660 to add a new m_params
to JSONRPCRequest
in parallel to the legacy params
to ease the transition.
Dropped other unnecessary improvements and “options” handling for now to keep this PR smaller, those can go in later in other PRs.
Reworked #11660 to add a new m_params
to JSONRPCRequest
in parallel to the legacy params
to ease the transition.
Dropped other unnecessary improvements and “options” handling for now to keep this PR smaller, those can go in later in other PRs.
542@@ -543,8 +543,9 @@ static UniValue setban(const JSONRPCRequest& request)
543 },
544 };
545 std::string strCommand;
546- if (!request.params[1].isNull())
547- strCommand = request.params[1].get_str();
548+ if (!request.m_params["command"].isNull()) {
I think you could use a function instead of exposing m_params, like
0std::string strCommand = request.GetString("command");
Less code, supports specifying default value, abstract UniValue
.
Just a suggestion though.
I did think of that when making these changes and opened https://github.com/jgarzik/univalue/pull/63 as a road forward in that regard.
At the end of the day, it is unrelated to this PR though…
params
entirely…
echo
method (rpc/misc) wants up to 100 args, but only names 10 of them. Should I teach the positional-to-named-args conversion to make ad-hoc argN as needed (currently in branch as a fixup), extend the named arg list out to 100, or reduce the number allowed by echo?
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
rpc_misc
pushed after a revert of the “fixup” version
With internal named parameters, all parameters MUST have names
🐙 This pull request conflicts with the target branch and needs rebase.
Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a “draft”.
455+}
456+
457+static inline JSONRPCRequest transformArguments(const JSONRPCRequest& in, const std::vector<std::string>& argNames)
458+{
459+ auto out = in;
460+ if (in.params.isObject()) {
Nit: wouldn’t it be slightly cleaner to do something like:
0bool isPositional = in.params.isObject();
1out.m_used_positional_args = isPositional;
2if (isPositional) { ... }
Same loc count, but reads slightly cleaner IMHO.
461+ out.m_used_positional_args = false;
462+ out.m_params = in.params;
463+ out.params = transformNamedArguments(in.params, argNames);
464+ } else {
465+ out.m_used_positional_args = true;
466+ if (in.params.size() > argNames.size()) {
out.m_used_positional_args
? Otherwise it seems either cleaner to put it first, or to put it last and take out the return out;
.