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

Add support for JSON RPC named parameters #33

Conversation

pedrobranco
Copy link
Collaborator

This PR adds support for JSON RPC named parameters (only available in 0.14.x).

const balance = await new Client(config.bitcoind).getBalance({
  account: '*',
  minconf: 0
});

// Same as:
const balance = await new Client(config.bitcoind).getBalance('*', 0);

@pedrobranco pedrobranco self-assigned this Sep 11, 2017
@pedrobranco pedrobranco force-pushed the enhancement/support-jsonrpc-named-parameters branch from 5c131dd to d5b14cf Compare September 27, 2017 10:34
@pedrobranco pedrobranco force-pushed the enhancement/support-jsonrpc-named-parameters branch from d5b14cf to 9fe550d Compare September 27, 2017 14:25
src/index.js Outdated
@@ -84,6 +84,8 @@ class Client {
.value();
}

this.hasNamedParametersSupport = semver.satisfies(version || '0.14.0', '>=0.14.0');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, it is assumed that 0.14.0 is the default version as per this condition. I would rather do this globally - affecting available methods as well - or only enable this when a version is set and matches the given constraints. My vote is on the latter.

Copy link
Collaborator Author

@pedrobranco pedrobranco Oct 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could enable this feature by default, and only disable it when version is passed and is lower than 0.14.0 just like all methods. WDYT?

src/index.js Outdated
@@ -113,6 +115,11 @@ class Client {
parameters = _.dropRight(parameters);
}

// Support named parameters (Bitcoin Core >=0.14.0 only).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should be sufficient on the boolean setter.

@@ -242,6 +251,16 @@ describe('Client', () => {

transactions.should.be.an.Array().and.empty();
});

it('should support named parameters', async () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more generic test we can add that doesn't require adding a should support named parameters type of test for each and every method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since each method has its own named arguments, we cannot add a generic test (or at least without adding all method definitions).

@pedrobranco pedrobranco force-pushed the enhancement/support-jsonrpc-named-parameters branch from 9fe550d to 2a03715 Compare October 30, 2017 12:20
src/index.js Outdated
@@ -63,6 +63,7 @@ class Client {

this.agentOptions = agentOptions;
this.auth = (password || username) && { pass: password, user: username };
this.hasNamedParametersSupport = true;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobranco I don't think the default should be true. Without passing a specific version, we can't be sure of that, so it seems rather imprudent to simply enable this for all clients.

@ruimarinho
Copy link
Owner

Added information to README.

@ruimarinho
Copy link
Owner

@pedrobranco I've got the changes done locally but I'm unable to push to your branch. Can you enable collaborative commit access?

@pedrobranco pedrobranco force-pushed the enhancement/support-jsonrpc-named-parameters branch from 2a03715 to 7ca5b94 Compare October 31, 2017 12:18
@@ -77,6 +78,14 @@ class Client {
let unsupported = [];

if (version) {
// Convert to semver (removing pathes).
if (!/[0-9]+\.[0-9]+\.[0-9]+/.test(version)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to run this test as exec gives us both informations (the test and the capture which we need below).


[version] = /[0-9]+\.[0-9]+\.[0-9]+/.exec(version);

this.hasNamedParametersSupport = semver.satisfies(version, '>=0.14.0');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If version is null, the result will be false, so everything will be ok here.

@@ -77,6 +78,14 @@ class Client {
let unsupported = [];

if (version) {
// Convert to semver (removing pathes).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patches

@ruimarinho
Copy link
Owner

Please follow this PR on #51.

@ruimarinho ruimarinho closed this Nov 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants