Skip to content

Commit 2d08c99

Browse files
MariusVanDerWijdenfjlrjl493456442
authored
ethclient/simulated: implement new sim backend (#28202)
This is a rewrite of the 'simulated backend', an implementation of the ethclient interfaces which is backed by a simulated blockchain. It was getting annoying to maintain the old version of the simulated backend feature because there was a lot of code duplication with the main client. The new version is built using parts that we already have: an in-memory geth node instance running in developer mode provides the chain, while the Go API is provided by ethclient. A backwards-compatibility wrapper is provided, but the simulated backend has also moved to a more sensible import path: github.com/ethereum/go-ethereum/ethclient/simulated --------- Co-authored-by: Felix Lange <[email protected]> Co-authored-by: Gary Rong <[email protected]>
1 parent 9e018ce commit 2d08c99

File tree

10 files changed

+667
-2514
lines changed

10 files changed

+667
-2514
lines changed

accounts/abi/bind/backend.go

+11-32
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ type BlockHashContractCaller interface {
8484
// used when the user does not provide some needed values, but rather leaves it up
8585
// to the transactor to decide.
8686
type ContractTransactor interface {
87+
ethereum.GasEstimator
88+
ethereum.GasPricer
89+
ethereum.GasPricer1559
90+
ethereum.TransactionSender
91+
8792
// HeaderByNumber returns a block header from the current canonical chain. If
8893
// number is nil, the latest known header is returned.
8994
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
@@ -93,38 +98,6 @@ type ContractTransactor interface {
9398

9499
// PendingNonceAt retrieves the current pending nonce associated with an account.
95100
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
96-
97-
// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
98-
// execution of a transaction.
99-
SuggestGasPrice(ctx context.Context) (*big.Int, error)
100-
101-
// SuggestGasTipCap retrieves the currently suggested 1559 priority fee to allow
102-
// a timely execution of a transaction.
103-
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
104-
105-
// EstimateGas tries to estimate the gas needed to execute a specific
106-
// transaction based on the current pending state of the backend blockchain.
107-
// There is no guarantee that this is the true gas limit requirement as other
108-
// transactions may be added or removed by miners, but it should provide a basis
109-
// for setting a reasonable default.
110-
EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)
111-
112-
// SendTransaction injects the transaction into the pending pool for execution.
113-
SendTransaction(ctx context.Context, tx *types.Transaction) error
114-
}
115-
116-
// ContractFilterer defines the methods needed to access log events using one-off
117-
// queries or continuous event subscriptions.
118-
type ContractFilterer interface {
119-
// FilterLogs executes a log filter operation, blocking during execution and
120-
// returning all the results in one batch.
121-
//
122-
// TODO(karalabe): Deprecate when the subscription one can return past data too.
123-
FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)
124-
125-
// SubscribeFilterLogs creates a background log filtering operation, returning
126-
// a subscription immediately, which can be used to stream the found events.
127-
SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
128101
}
129102

130103
// DeployBackend wraps the operations needed by WaitMined and WaitDeployed.
@@ -133,6 +106,12 @@ type DeployBackend interface {
133106
CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
134107
}
135108

109+
// ContractFilterer defines the methods needed to access log events using one-off
110+
// queries or continuous event subscriptions.
111+
type ContractFilterer interface {
112+
ethereum.LogFilterer
113+
}
114+
136115
// ContractBackend defines the methods needed to work with contracts on a read-write basis.
137116
type ContractBackend interface {
138117
ContractCaller

0 commit comments

Comments
 (0)