-
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: Export symbols needed for custom commands #1457
Conversation
2b1eed8 Switch to new rpcclient based on latest upstream Conformal (JeremyRand) Pull request description: Namecoin's fork of Conformal's RPC client library is ancient and unmaintained; switching to upstream eliminates a major source of potential bugs (and known bugs, e.g. the ConsensusJ and Electrum compatibility bugs that we had to patch). Fixes #9 TODO: - [ ] Wait for Conformal to merge btcsuite/btcd#1457 - [ ] Wait for Conformal to merge btcsuite/btcd#1460 - [x] Push `name_show` support for `ncjson` and `ncrpcclient` - [x] Implement cookie authentication - [x] Test cookie authentication ACKs for commit 2b1eed: Tree-SHA512: 157780613661af240d83a78d66386c66fcfeed0700088d263a20389c45b200db1b651ea985f345de2ac2f250bdafcc4cd5901579e9f5a97ddc13e77e7a7bcf39
What is the motivation for this change though? As far as I can tell, it isn't used anywhere |
A use case is implementing a RPC for an unreleased version of Core/btcd, or simply to add a RPC locally which isn't available in |
@torkelrogstad Namecoin is adding custom commands in these repos: Should be pretty easy to figure out how to do it based on the code in those two repos. If desired, I could add links to those two repos to the readme or something. |
I think linking to code in a different repo is not really something we should do here. A simple demonstration of how to add a RPC would be more than enough, should be 20 lines of code or so? |
Also, this PR needs a rebase |
@torkelrogstad No objection from me. I probably won't be able to get to it until early January though. (Ditto for the rebase.) |
9bb754a
to
13cd083
Compare
Rebased. @torkelrogstad Should the sample code for using a custom command go in the |
I think |
@jcvernaleo (as per #1530)
Probably needs some work as per @torkelrogstad |
13cd083
to
3b83c84
Compare
Rebased and added example. @torkelrogstad How does it look now? (I'm not 100% sure about the CI failure, but at first glance it looks unrelated to this PR.) |
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.
Couple of comments on the wording in the README, other than that this looks good to me. Also looks like there's a CI failure
```bash | ||
$ cd $GOPATH/src/github.com/btcsuite/btcd/rpcclient/examples/customcommand | ||
$ go run *.go | ||
``` |
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 example assumes that the user is using Go modules, which is no longer the default with newer Go versions. I'd suggest replacing 9-13 with:
The first step is to clone the btcd
repo:
$ git clone github.com/btcsuite/btcd
$ cd btcd
And then replace 23-28 with:
Finally, run the example:
$ go run rpcclient/examples/customcommand/main.go
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 Readme is copied nearly verbatim from the bitcoincorehttp
example's Readme; for consistency I prefer not to make the requested changes as part of this PR (but I'd be fine with those changes as a separate PR that covers both examples' Readmes).
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 agree with the changes suggested here, but I'm happy to take care of it in a separate PR.
Triggering a CI rebuild to see if the failure was a fluke... |
Yes, CI appears to have succeeded this time. |
3b83c84
to
98c8f0c
Compare
Pull Request Test Coverage Report for Build 993591029
💛 - Coveralls |
Rebased to fix merge conflicts. Would be great if this can be reviewed and/or merged. |
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.
rpcclient/examples/customcommand/main.go
needs to be formatted with gofmt
rpcclient/infrastructure.go
Outdated
func (c *Client) sendCmdAndWait(cmd interface{}) (interface{}, error) { | ||
func (c *Client) SendCmdAndWait(cmd interface{}) (interface{}, error) { | ||
// Marshal the command to JSON-RPC, send it to the connected server, and | ||
// wait for a response on the returned channel. | ||
return receiveFuture(c.sendCmd(cmd)) | ||
return ReceiveFuture(c.SendCmd(cmd)) |
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.
What do you think of deleting this method? It is only used a single place. It can be replaced by inling the contents here. That way there's one less public symbol exported, which is nice.
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.
Whoops, making that one public was unintentional; seems I was a tad sloppy while rebasing. Reverted it to private; thanks for catching that.
56a3124
to
48a1ec7
Compare
@torkelrogstad Thanks for catching that; fixed. |
960ae63
to
96fed42
Compare
This facilitates using custom commands with rpcclient. See btcsuite#1083
This facilitates using custom commands with rpcclient. See btcsuite#1083
96fed42
to
91ad6db
Compare
Rebased again. Would be awesome if we can get this reviewed and merged. |
Thanks @JeremyRand I don't have time to review this morning but I added it to the milestone for the next release so it is at the top of the list. |
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.
One minor thing from me then looks good.
@@ -0,0 +1,32 @@ | |||
Namecoin Core Custom Command Example |
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'm fine with leaving the other parts of the readme as is and then update with a future PR, but I think we should fix the name at least so it isn't Namecoin
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.
Let's do this in a separate PR. I think just using "Custom Command Example" is appropriate.
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.
Fixed.
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 PR needs some very minor cosmetic changes, but let's do that in a different PR.
@@ -0,0 +1,32 @@ | |||
Namecoin Core Custom Command Example |
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.
Let's do this in a separate PR. I think just using "Custom Command Example" is appropriate.
```bash | ||
$ cd $GOPATH/src/github.com/btcsuite/btcd/rpcclient/examples/customcommand | ||
$ go run *.go | ||
``` |
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 agree with the changes suggested here, but I'm happy to take care of it in a separate PR.
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 think this is good to go.
OK
Any chance we can get this merged? AFAICT there are no remaining blockers (unless I missed something?). |
Squashed and merged. Thanks @JeremyRand for the PR. 🙌 |
@JeremyRand my apologies. I see that I approved this a while ago but forgot to actually merge it. Sorry about that. Thanks for the reminder. |
* rpcclient: Export sendCmd and response This facilitates using custom commands with rpcclient. See btcsuite#1083 * rpcclient: Export receiveFuture This facilitates using custom commands with rpcclient. See btcsuite#1083 * rpcclient: Add customcommand example * rpcclient: remove "Namecoin" from customcommand readme heading
* rpcclient: Export sendCmd and response This facilitates using custom commands with rpcclient. See btcsuite#1083 * rpcclient: Export receiveFuture This facilitates using custom commands with rpcclient. See btcsuite#1083 * rpcclient: Add customcommand example * rpcclient: remove "Namecoin" from customcommand readme heading
* rpcclient: Export sendCmd and response This facilitates using custom commands with rpcclient. See btcsuite#1083 * rpcclient: Export receiveFuture This facilitates using custom commands with rpcclient. See btcsuite#1083 * rpcclient: Add customcommand example * rpcclient: remove "Namecoin" from customcommand readme heading
Fixes #1083
I'm not particularly familiar with the btcsuite codebase yet, so hopefully I didn't break anything with this patch. (I assume I'll notice quickly if Travis complains.)