|
| 1 | +package utils |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "math/big" |
| 6 | + |
| 7 | + "github.com/ethereum/go-ethereum" |
| 8 | + "github.com/ethereum/go-ethereum/common" |
| 9 | + "github.com/ethereum/go-ethereum/core/types" |
| 10 | +) |
| 11 | + |
| 12 | +// Blockchain is a generalized interface for interacting with the ethereum blockchain |
| 13 | +type Blockchain interface { |
| 14 | + // CodeAt returns the code of the given account. This is needed to differentiate |
| 15 | + // between contract internal errors and the local chain being out of sync. |
| 16 | + CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) |
| 17 | + // ContractCall executes an Ethereum contract call with the specified data as the |
| 18 | + // input. |
| 19 | + CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) |
| 20 | + // PendingCodeAt returns the code of the given account in the pending state. |
| 21 | + PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error) |
| 22 | + // PendingCallContract executes an Ethereum contract call against the pending state. |
| 23 | + PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error) |
| 24 | + // PendingNonceAt retrieves the current pending nonce associated with an account. |
| 25 | + PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) |
| 26 | + // SuggestGasPrice retrieves the currently suggested gas price to allow a timely |
| 27 | + // execution of a transaction. |
| 28 | + SuggestGasPrice(ctx context.Context) (*big.Int, error) |
| 29 | + // EstimateGas tries to estimate the gas needed to execute a specific |
| 30 | + // transaction based on the current pending state of the backend blockchain. |
| 31 | + // There is no guarantee that this is the true gas limit requirement as other |
| 32 | + // transactions may be added or removed by miners, but it should provide a basis |
| 33 | + // for setting a reasonable default. |
| 34 | + EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) |
| 35 | + // SendTransaction injects the transaction into the pending pool for execution. |
| 36 | + SendTransaction(ctx context.Context, tx *types.Transaction) error |
| 37 | + // FilterLogs executes a log filter operation, blocking during execution and |
| 38 | + // returning all the results in one batch. |
| 39 | + // |
| 40 | + // TODO(karalabe): Deprecate when the subscription one can return past data too. |
| 41 | + FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) |
| 42 | + // SubscribeFilterLogs creates a background log filtering operation, returning |
| 43 | + // a subscription immediately, which can be used to stream the found events. |
| 44 | + SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) |
| 45 | + TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) |
| 46 | +} |
0 commit comments