New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc: Be able to access RPC parameters by name #27788
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, 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. |
857991f
to
35c5ffb
Compare
35c5ffb
to
2d41b19
Compare
2d41b19
to
176f61d
Compare
Concept ACK |
176f61d
to
3fe03c7
Compare
Might be nice to at least update one method to use the new code to see that it compiles and passes the existing tests? See also #20017 |
Added a commit to update the RPCs that have >= 6 args to use these named params. |
38662de
to
86e640c
Compare
I don't think there is a need to? |
It's trivial, but do we want to? It doesn't really add significant benefit (besides accessing by name), and importantly it'd muddy the interface. For example, with In cases where eliminating |
86e640c
to
41027ad
Compare
sgtm |
@stickies-v feel free to open an alternative approach. I'm not particularly attached to any approach, I just want to be able to access params by name. |
41027ad
to
73751f8
Compare
Instead of conditionally calling transformNamedArguments (renamed to transformArguments), unconditionally call it and perform the isObject check within that function.
In order to support positional and named parameter lookup, introduce a JSONRPCParameters class that contains the parameters. For now, this is simply a passthrough for the UniValue parameters.
JSONRPCParameters contains a map of named parameter name to the parameter, and a vector of the positional parameters. These allow for lookup by both parameter position and parameter name.
scanblocks, createwallet, listsinceblock, sendmany, and sendtoaddress all have 6 or more parameters. To make these easier to follow, use param names rather than positions.
73751f8
to
e87477c
Compare
Can be closed after #29277 ? |
30a6c99 rpc: access some args by name (stickies-v) bbb3126 rpc: add named arg helper (stickies-v) 13525e0 rpc: add arg helper unit test (stickies-v) Pull request description: Adds string overloads for the `RPCHelpMan::Arg` and `RPCHelpMan::MaybeArg` helpers to be able to access RPC arguments by name instead of index number. Especially in RPCs with a large number of parameters, this can be quite helpful. Example usage: ```cpp const auto action{self.Arg<std::string>("action")}; ``` Most of the LoC is adding test coverage and documentation updates. No behaviour change. An alternative approach to #27788 with significantly less overhaul. ACKs for top commit: fjahr: Code review ACK 30a6c99 maflcko: ACK 30a6c99 🥑 ryanofsky: Code review ACK 30a6c99. Nice change! Implementation is surprisingly simple and additional unit test coverage is welcome, too. Tree-SHA512: 4904f5f914fe1d421d32f60edb7c5a028c8ea0f140a2f207a106b4752d441164e073066a6bf2e17693f859fe847815a96609d3cf521e0ac4178d8cd09362ea3d
Although we accept named RPC parameters, we still access the parameters by position within the RPC implementations. This PR makes it possible to access these parameters directly by name. This is achieved by holding the parameters in a separate
JSONRPCParameters
class which contains mappings from both name to value, and position to value. Twooperator[]
methods are implemented which can accept both strings and ints. This allows for backwards compatibility, while also allowing for future implementation to access the parameters by name.The processing of named arguments ends up being entirely overhauled in order to be able to store the mappings to the parameters.
Based on #26485 to avoid conflicting with it.