-
Notifications
You must be signed in to change notification settings - Fork 37.7k
rpc/server: Support for specifying options as named parameters #11441
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
Conversation
I'm not sure what the motivation is for this, since there's no PR description. As currently implemented, this doesn't seem to work for bitcoin.cli. Options don't get converted from strings into the correct type:
It also seems to break argument name checking. With this PR:
on master:
|
That would be a task for an independent PR. This is just for the server.
Doesn't look broken to me. It's seeing the missing argument before checking options. If we want the other behaviour, the RPC method should check options before other arguments. |
How about going the other way? When an 'options' parameter is present, and the RPC has no argument with that name, treat its keys as extra named arguments. This presents an easier interface for implementing RPCs (which can just use named arguments, rather than needing to disassemble and typecheck fields of an object). This needs motivation regardless. |
The motivation is to fix the named args interface. Going "the other way" encourages terrible array-args interfaces, which should be discouraged. |
The interface would be identical. You'd accept any named argument either as real named argument, or as a key in a positional 'options' argument. You either convert one to the other, or the other to one. But it would be easier to write RPC handlers for. |
But when using positional arguments, you'd have a terrible interface where you have a dozen null values just to reach the one you actually want to set. |
slight NACK - I'm not convinced this is really necessary. As I see it it adds complexity to the argument parsing code and makes nothing new possible. Just follow the darn API and pass these additional options in the options object and don't be lazy. |
The interface for
The point is that this PR makes the error message less helpful for the user. That's a regression.
It's not obvious to me that the named args interface needs 'fixing'. Named args are arguably better than an options object for a number of reasons:
No-one is suggesting that users should use positional arguments. Named args solve this problem already. |
Named arguments with
This sounds more command line to me. Anyway, IMO we should avoid adding fat to bitcoin-cli. |
Named args should not be used as an excuse to have a crappy positional-args interface. |
This is not improved here. The JSON-RPC implementation supports both positional and named arguments and this can not change. If all RPC method implementations change to use named arguments then we must invert the index->name mapping to keep compatibility with the existing version. I can't see the advantages for other clients other than bitcoin-cli. And for bitcoin-cli something like would be enough. |
@promag The other day someone was being suggested to make the problem worse. |
Superceded by #11660, hopefully addressing the concerns here. |
No description provided.