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
std::string strCommand = request.GetString("command");
I don't see any benefit to doing that...?
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...
Concept ACK. Should mention in developer notes that named params is preferable for new code.
Well, my hope is that after this is merged, we can migrate existing code to use it and drop params entirely...
The 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?
100 args are only needed to throw an internal bug report. You can replace that with a check that checks if the first argument is the string "throw_internal_bug_report" (or anything else you can come up with)
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
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.
Concept ACK
Alternative fix for rpc_misc pushed after a revert of the "fixup" version
With internal named parameters, all parameters MUST have names
Rebased. Thanks to changes in master, neither hack is needed anymore.
<!--cf906140f33d8803c4a75a2196329ecb-->
🐙 This pull request conflicts with the target branch and needs rebase.
<sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>
Doesn't seem to be much point in rebasing this. It'd be nice to have, but without any review interest, just wasting time.
Concept ACK
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:
bool isPositional = in.params.isObject();
out.m_used_positional_args = isPositional;
if (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()) {
Is there some reason to do this after setting 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;.
Concept ACK. This would make a lot of code much cleaner!