-
Notifications
You must be signed in to change notification settings - Fork 188
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
Add support for JSON RPC named parameters #33
Conversation
5c131dd
to
d5b14cf
Compare
d5b14cf
to
9fe550d
Compare
src/index.js
Outdated
@@ -84,6 +84,8 @@ class Client { | |||
.value(); | |||
} | |||
|
|||
this.hasNamedParametersSupport = semver.satisfies(version || '0.14.0', '>=0.14.0'); |
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.
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.
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.
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). |
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.
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 () => { |
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.
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?
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.
Since each method has its own named arguments, we cannot add a generic test (or at least without adding all method definitions).
9fe550d
to
2a03715
Compare
src/index.js
Outdated
@@ -63,6 +63,7 @@ class Client { | |||
|
|||
this.agentOptions = agentOptions; | |||
this.auth = (password || username) && { pass: password, user: username }; | |||
this.hasNamedParametersSupport = true; |
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.
@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.
Added information to README. |
@pedrobranco I've got the changes done locally but I'm unable to push to your branch. Can you enable collaborative commit access? |
2a03715
to
7ca5b94
Compare
@@ -77,6 +78,14 @@ class Client { | |||
let unsupported = []; | |||
|
|||
if (version) { | |||
// Convert to semver (removing pathes). | |||
if (!/[0-9]+\.[0-9]+\.[0-9]+/.test(version)) { |
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.
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'); |
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.
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). |
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.
patches
Please follow this PR on #51. |
This PR adds support for JSON RPC named parameters (only available in 0.14.x).