The JSON-RPC specification allows either passing parameters as an Array, for by-position arguments, or as an Object, for by-name arguments. Currently Bitcoin Core only supports by-position arguments.
This pull request makes the (minimal) changes to support by-name arguments, but preserves full backwards compatibility. APIs using by-name arguments are easier to extend - as arguments can be left out - and easier to use - no need to guess which argument goes where.
This is especially nice in languages such as Python, which have native support for named arguments. Examples from the test:
0h = node.help(command='getinfo')
1h = node.getblockhash(index=0)
2h = node.getblock(hash=h)
- In this implementation named arguments are mapped to positions by a per-call structure, provided in the RPC command table. In the future calls could process the parameter object themselves, but this provides nice automatic interoperability with both worlds.
- Missing arguments will be replaced by null (“holes”), except if at the end, then the argument is left out completely.
- It is not possible to specify both named and positional arguments like in Python. JSON-RPC doesn’t allow for this, and I think it would be only confusing anyhow.
- An error (
RPC_INVALID_PARAMETER
) will be return if an unknown named argument is specified.
Currently no calls have support for “holes” between arguments, but this should be implemented later on a per-call basis. These should be replaced with default values.
TODO
-
DONE see #8811 (comment)bitcoin-cli
should grow support for providing named arguments -
Calls inmining
,net
,rawtransaction
wallet
still need argument names filled in. I’ll do this if reaction to this is positive.
Later
- Same for the debug console. Syntax to be determined there. Not necessarily in this pull, my focus here is the core implementation.