-
Notifications
You must be signed in to change notification settings - Fork 20.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
ethclient/ethclient.go add_get_block_by_tag_function #30984
base: master
Are you sure you want to change the base?
Conversation
@@ -94,6 +94,13 @@ func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Bl | |||
return ec.getBlock(ctx, "eth_getBlockByNumber", toBlockNumArg(number), true) | |||
} | |||
|
|||
// BlockByNumber returns a block from the current canonical chain. If tag is nil, the |
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.
You can retrieve the block by using tag with BlockByNumber
endpoint.
e.g.
- BlockByNumber(context.Background(), nil) means latest,
- BlockByNumber(context.Background(), big.NewInt(-1)) means pending,
- BlockByNumber(context.Background(), big.NewInt(-2)) means latest,
- BlockByNumber(context.Background(), big.NewInt(-3)) means finalized,
- BlockByNumber(context.Background(), big.NewInt(-4)) means safe,
However, I do see the point for having an endpoint to explicitly request blocks with tag.
While these special negative numbers can be translated by ethclient to tags, they are Geth-related, not publicly defined in the spec. Probably it's better to extend the BlockByNumber endpoint a bit, allowing specify tag explicitly?
cc @fjl
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 your reply.,Yes, I can know which numbers represent which labels after digging into the code, but it is very inconvenient, so do I need to modify the BlockByNumber method and submit it again?
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 the numbers are not very visible right now. After some discussion in team, we don't want to add another method, but would be open to improving documentation. We could also add redefinitions of these constants into package ethclient for convenience.
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 your reply.In response to your request, I have removed the method of querying according to tag , and in the BlockByNumber method, I have detailed instructions on how to obtain the corresponding blocknumber through tags. Please have a look, I hope this is a good PR , you can see the new commit.
When querying blocks using special tags, there is no direct method call. It requires delving into the code to find the corresponding number for the special tag and then retrieve the block, which is inconvenient. Therefore, a method was encapsulated to directly query blocks using special tags.