Skip to content
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

ethclient: add NetworkID function #14791

Merged
merged 4 commits into from
Aug 1, 2017
Merged

ethclient: add NetworkID function #14791

merged 4 commits into from
Aug 1, 2017

Conversation

mcdee
Copy link
Contributor

@mcdee mcdee commented Jul 11, 2017

There is currently no simple way to obtain the network ID from a Client. This adds a NetworkID() function that wraps the net_version JSON-RPC call and returns the network ID in a suitable format.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@fjl fjl self-requested a review July 31, 2017 10:27

version.SetString(ver, 10)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove return value names.
Please parse into version directly instead of doing the parsing via SetString.

version := new(big.Int)
err := ec.c.CallContext(ctx, &version, "net_version")
return version, err

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove the return value names.

Regarding the direct parsing: the result is returned from the RPC interface as a string rather than a number:

{"jsonrpc":"2.0","id":74,"result":"1"}

so attempting to unmarshal directly in to the big.Int fails. Is this an underlying issue with the RPC interface or should I leave the string parsing code in place?

Copy link
Contributor

@fjl fjl Jul 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the spec a bit too quickly and mistook "id" for "result". The string parsing is fine then, but please check for errors when parsing the string.

@fjl fjl merged commit bc0e6a5 into ethereum:master Aug 1, 2017
@karalabe karalabe added this to the 1.7.0 milestone Aug 3, 2017
markya0616 pushed a commit to markya0616/go-ethereum that referenced this pull request Aug 17, 2017
There is currently no simple way to obtain the network ID from a Client. 
This adds a NetworkID method that wraps the net_version JSON-RPC call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants