-
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
Add getnodeaddresses JSON-RPC support (rpc client & server) #1590
Conversation
rpcserver.go
Outdated
if int32(len(nodes)) < count { | ||
count = int32(len(nodes)) | ||
} |
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.
Will an extra assignment be better than traversing nodes
twice?
if int32(len(nodes)) < count { | |
count = int32(len(nodes)) | |
} | |
if numOfNodes := int32(len(nodes)); numOfNodes < count { | |
count = numOfNodes | |
} |
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.
Implementations of len
should be fast because slice knows its length. I do like the reduced repetition of your suggestion especially since int32
conversion is duplicated here. I'm keen to name this variable something short like nn
given its narrow scope.
} | ||
|
||
// GetNodeAddresses returns data about known node addresses. | ||
func (c *Client) GetNodeAddresses(count *int32) ([]btcjson.GetNodeAddressesResult, error) { |
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.
There are plenty of examples in rpcclient where each optional parameter has its own dedicated method. For example, instead of GetNodeAddresses(count *int32)
, we can have the following:
GetNodeAddresses()
GetNodeAddressesCount(count int32)
What do you think?
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.
Thank you for bringing this up. After getting similar feedback in another PR I was looking around rpcclient
. In RPC calls that take a single optional variable I can see many examples where a single function which takes a pointer is provided - similarly to GetNodeAddresses(count *int32)
Trying to be consistent is the best solution I think. I can change it to the non-pointer style that you're suggesting if you think that's better.
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.
Fine with me as long as we are consistent. 👍
4270f15
to
1954064
Compare
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! 🚀
@lindlof Could you please rebase this? Will have this merged tomorrow. 🙂 |
Rebase/conflict fix and then this is good to go in. |
Add NodeAddresses function to rpcserverConnManager interface for fetching known node addresses.
1954064
to
c1b6b40
Compare
Pull Request Test Coverage Report for Build 245431911
💛 - Coveralls |
@onyb @jcvernaleo Sweet, rebased |
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.
OK
Add NodeAddresses function to rpcserverConnManager
interface for fetching known node addresses.