forked from dashpay/dash
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] Support for JSON-RPC named arguments #2386
Merged
furszy
merged 16 commits into
PIVX-Project:master
from
random-zebra:202105_rpc_namedargs
Jun 2, 2021
Merged
[RPC] Support for JSON-RPC named arguments #2386
furszy
merged 16 commits into
PIVX-Project:master
from
random-zebra:202105_rpc_namedargs
Jun 2, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
random-zebra
added this to In Progress
in perpetual updating PIVX Core to BTC Core
via automation
May 13, 2021
random-zebra
force-pushed
the
202105_rpc_namedargs
branch
from
May 17, 2021 23:38
60f1a11
to
3de8df0
Compare
The [JSON-RPC specification](http://www.jsonrpc.org/specification) allows passing parameters as an Array, for by-position arguments, or an Object, for by-name arguments. This implements by-name arguments, but preserves full backwards compatibility. API using by-name arguments are easier to extend, and easier to use (no need to guess which argument goes where). Named are mapped to positions by a per-call structure, provided through the RPC command table. Missing arguments will be replaced by null, except if at the end, then the argument is left out completely. Currently calls fail (though not crash) on intermediate nulls, but this should be improved on a per-call basis later.
This hidden call simply returns what is passed in.
>>> backports bitcoin/bitcoin@481f289 Usage e.g.: $ src/pivx-cli -testnet -named echo arg0="dfdf" [ "dfdf" ] Argument conversion also works, for arguments thus flagged in the table in `src/rpc/client.cpp`. $ src/pivx-cli -testnet -named echojson arg0="[1,2,3]" [ [ 1, 2, 3 ] ] Unknown parameter (detected server-side): $ src/pivx-cli -testnet -named getinfo arg0="dfdf" error code: -8 error message: Unknown named parameter arg0
needs rebase |
random-zebra
force-pushed
the
202105_rpc_namedargs
branch
from
May 25, 2021 13:10
3de8df0
to
9ed1bdd
Compare
also reviews :) There were a couple conflicts with #2308, merged only few hours ago. Fixed. |
furszy
approved these changes
May 27, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool feature, ACK 9ed1bdd
Fuzzbawls
approved these changes
Jun 2, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 9ed1bdd
perpetual updating PIVX Core to BTC Core
automation
moved this from In Progress
to Ready
Jun 2, 2021
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The JSON-RPC specification allows either passing parameters as an Array, for positional arguments, or as an Object, for named arguments. Currently PIVX Core only supports positional arguments.
This pull request adds support for named 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:
Backported from: