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

Support BlockHash in contract bindings #28017

Closed
ajsutton opened this issue Aug 27, 2023 · 1 comment · Fixed by #28084
Closed

Support BlockHash in contract bindings #28017

ajsutton opened this issue Aug 27, 2023 · 1 comment · Fixed by #28084

Comments

@ajsutton
Copy link
Contributor

Rationale

To allow users of contract bindings to get a consistent view of the chain across multiple calls it would be useful for bind.CallOpts to support a BlockHash option instead of just BlockNumber. This also allows callers to track changes in specific blocks more easily - for example if they're subscribed to head or log updates and then requesting additional data from the contract, they could do so with block hash, whereas block number may return incorrect data if there is a reorg.

Implementation

Happy to implement this if it is something that would be accepted upstream.

I'd suggest following the same pattern as the pending block support uses by introducing a new bind.BlockHashContractCaller that provides the required CallContractAtHash and GetCodeAtHash (GetCodeAtHash would also have to be added to ethclient.Client but the underlying eth_getCode rpc method already supports passing a block number or block hash).

Like pending calls, if a CallOpts.BlockHash is specified but the backend doesn't implement BlockHashContractCaller an error would be returned. It would also be an error to specify both BlockHash and BlockNumber.

@holiman
Copy link
Contributor

holiman commented Sep 5, 2023

Happy to implement this if it is something that would be accepted upstream.

Triage discussion: yeah, sounds good to us!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
@ajsutton @holiman and others