Skip to content
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
merged 16 commits into from Jun 2, 2021

Conversation

random-zebra
Copy link

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:

h = node.help(command='getinfo')
h = node.getblockhash(height=0)
h = node.getblock(hash=h)

Backported from:

laanwj and others added 11 commits May 25, 2021 14:30
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
@furszy
Copy link

furszy commented May 25, 2021

needs rebase

@random-zebra
Copy link
Author

needs rebase

also reviews :)

There were a couple conflicts with #2308, merged only few hours ago. Fixed.

Copy link

@furszy furszy left a 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

@random-zebra
Copy link
Author

It would be good to merge this PR before others that are introducing new RPC commands, or modifying existing ones (such as #2341, #2349, #2351, etc.).

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a 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
@furszy furszy merged commit 29650e0 into PIVX-Project:master Jun 2, 2021
perpetual updating PIVX Core to BTC Core automation moved this from Ready to Done Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants