-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
rpcclient: implement createwallet with functional options #1650
rpcclient: implement createwallet with functional options #1650
Conversation
Pull Request Test Coverage Report for Build 298236815Warning: This coverage report may be inaccurate.We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
💛 - Coveralls |
135ac7f
to
26f0d27
Compare
26f0d27
to
30622e2
Compare
High level, I'm cool with this style. Going to do a real review now though. |
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.
Looks good to me. I like the new style. Will give it a few days in case anyone else wants to look and then i'll merge.
I like this. Must cleaner than what we have now and less tedious to implement than the builder strategy |
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.
Looks good to me! The only thing I might add is we should clarify some of our style guidelines here (https://github.com/btcsuite/btcd/blob/master/docs/code_contribution_guidelines.md) at some point
@jakesyl Indeed, we should document this. I'll do a separate PR to update the guidelines. If you can, please feel free to merge the PR. |
Rebased on #1645, to avoid having to resolve merge conflicts later. This PR only implements
createwallet
as a first-step towards functional options.Background
I find the current way of dealing with optional parameters in RPC commands very hard to maintain, and also clunky from a user's perspective. We implement one rpcclient method per optional parameter, with long-winding names, closely following the order of the parameters!
This has been previously discussed a bit in #1589.
Current style
We have multiple methods to choose from, depending upon the options you want to use. In the example below, it is impossible to specify just
watchOnly
without specifyingcount
. 😞Proposed style
The above is known as functional options pattern, which is widely used in the Go community. Dave Cheney has written about it here. Here's another article I really liked.
The API is made possible using the following variadic signature: