-
Notifications
You must be signed in to change notification settings - Fork 5
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
Added promise support #2
Conversation
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.
Very cool!
Minor style nits: put space after if
keyword and before the parens, i.e. if (...)
, and put semi-colons at the end of lines. I can fix these later if you prefer.
index.js
Outdated
this.calb = true; | ||
} else { | ||
this.calb = false; | ||
} |
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.
Can shrink to
this.calb = typeof args[args.length - 1] === 'function';
index.js
Outdated
method: cmd.toLowerCase(), | ||
params: slice(args, 0, args.length - 1), | ||
}, args[args.length - 1]); | ||
params: slice(args, 0, args.length), |
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.
No need for call to slice()
, can just use params: args
.
index.js
Outdated
return callback(e); | ||
} | ||
return callback(bufDeserialized.error, bufDeserialized); | ||
reject(err); |
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.
When calb
is set, both callback()
and reject()
will be called. Use else
for the !this.calb
case, or return in the above if block?
index.js
Outdated
@@ -136,61 +136,104 @@ function RpcAgent(opts = {}) { | |||
this.user = opts.user || 'user'; | |||
this.pass = opts.pass || 'pass'; | |||
this.prot = opts.ssl ? https : http; | |||
this.calb = false; // Defaults to promises |
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 you need this line. this.calb
is set every time a command is invoked.
index.js
Outdated
return callback(new Error('bitcoin JSON-RPC connection rejected: 401 unauthorized')); | ||
} | ||
reject(new Error('bitcoin JSON-RPC connection rejected: 401 unauthorized')); | ||
return |
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.
It's perfectly fine to return the reject call here and in the other places, I think, to save the extra return lines.
Thanks! I agree with all of the changes, I just updated my eslint file to follow those style rules, so it was no big deal. The current branch should reflect all of the changes suggested above. |
I squashed commits, but would it have been easier for you if I didn't on those latest changes? I haven't done a ton of contributing via github so I'm trying to figure out a good process. |
Squashing is totally fine. Thanks! |
If you think this is useful, I'd love your feedback.