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

Expose totalDifficulty in go-ethereum client #24754

Closed

Conversation

zimbabao
Copy link
Contributor

@zimbabao zimbabao commented Apr 25, 2022

This PR contains API to expose totalDifficulty in go-ethereum client.
APIs like JSON-RPC, web3.js all expose totalDifficulty, but somehow go-ethereum was not exposing it.
Block object was populated with totalDifficulty as a private field but was not used anywhere.

@zimbabao zimbabao changed the title Expose totalDifficulty in go-ethereum client [WIP] Expose totalDifficulty in go-ethereum client Apr 25, 2022
@zimbabao zimbabao changed the title [WIP] Expose totalDifficulty in go-ethereum client Expose totalDifficulty in go-ethereum client Apr 25, 2022
@fjl
Copy link
Contributor

fjl commented Apr 25, 2022

I would rather remove the td field. This field will lose its meaning very soon when the PoS transition happens. I'm sorry that we cannot provide this information when loading blocks via RPC, but it is arguably a niche use case.

If you must get the totalDifficulty via RPC, you can always do this:

type rpcBlock struct{
    Number *hexutil.Big `json:"number"`
    TD     *hexutil.Big `json:"totalDifficulty"`
}

c, err := rpc.Dial("<url>")

var info rpcBlock
err := c.Call(&info, "eth_getBlockByNumber", "latest")
fmt.Println(info.TD)

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.

2 participants