@@ -20,93 +20,78 @@ import (
2020 "errors"
2121 "math/big"
2222
23+ "github.com/ethereum/go-ethereum"
2324 "github.com/ethereum/go-ethereum/common"
2425 "github.com/ethereum/go-ethereum/core/types"
2526 "golang.org/x/net/context"
2627)
2728
28- // ErrNoCode is returned by call and transact operations for which the requested
29- // recipient contract to operate on does not exist in the state db or does not
30- // have any code associated with it (i.e. suicided).
31- var ErrNoCode = errors .New ("no contract code at given address" )
29+ var (
30+ // ErrNoCode is returned by call and transact operations for which the requested
31+ // recipient contract to operate on does not exist in the state db or does not
32+ // have any code associated with it (i.e. suicided).
33+ ErrNoCode = errors .New ("no contract code at given address" )
34+
35+ // This error is raised when attempting to perform a pending state action
36+ // on a backend that doesn't implement PendingContractCaller.
37+ ErrNoPendingState = errors .New ("backend does not support pending state" )
38+
39+ // This error is returned by WaitDeployed if contract creation leaves an
40+ // empty contract behind.
41+ ErrNoCodeAfterDeploy = errors .New ("no contract code after deployment" )
42+ )
3243
3344// ContractCaller defines the methods needed to allow operating with contract on a read
3445// only basis.
3546type ContractCaller interface {
36- // HasCode checks if the contract at the given address has any code associated
37- // with it or not. This is needed to differentiate between contract internal
38- // errors and the local chain being out of sync.
39- HasCode (ctx context.Context , contract common.Address , pending bool ) (bool , error )
47+ // CodeAt returns the code of the given account. This is needed to differentiate
48+ // between contract internal errors and the local chain being out of sync.
49+ CodeAt (ctx context.Context , contract common.Address , blockNumber * big.Int ) ([]byte , error )
50+ // ContractCall executes an Ethereum contract call with the specified data as the
51+ // input.
52+ CallContract (ctx context.Context , call ethereum.CallMsg , blockNumber * big.Int ) ([]byte , error )
53+ }
4054
41- // ContractCall executes an Ethereum contract call with the specified data as
42- // the input. The pending flag requests execution against the pending block, not
43- // the stable head of the chain.
44- ContractCall (ctx context.Context , contract common.Address , data []byte , pending bool ) ([]byte , error )
55+ // DeployBackend wraps the operations needed by WaitMined and WaitDeployed.
56+ type DeployBackend interface {
57+ TransactionReceipt (ctx context.Context , txHash common.Hash ) (* types.Receipt , error )
58+ CodeAt (ctx context.Context , account common.Address , blockNumber * big.Int ) ([]byte , error )
59+ }
60+
61+ // PendingContractCaller defines methods to perform contract calls on the pending state.
62+ // Call will try to discover this interface when access to the pending state is requested.
63+ // If the backend does not support the pending state, Call returns ErrNoPendingState.
64+ type PendingContractCaller interface {
65+ // PendingCodeAt returns the code of the given account in the pending state.
66+ PendingCodeAt (ctx context.Context , contract common.Address ) ([]byte , error )
67+ // PendingCallContract executes an Ethereum contract call against the pending state.
68+ PendingCallContract (ctx context.Context , call ethereum.CallMsg ) ([]byte , error )
4569}
4670
4771// ContractTransactor defines the methods needed to allow operating with contract
4872// on a write only basis. Beside the transacting method, the remainder are helpers
4973// used when the user does not provide some needed values, but rather leaves it up
5074// to the transactor to decide.
5175type ContractTransactor interface {
52- // PendingAccountNonce retrieves the current pending nonce associated with an
53- // account.
54- PendingAccountNonce ( ctx context. Context , account common. Address ) ( uint64 , error )
55-
76+ // PendingCodeAt returns the code of the given account in the pending state.
77+ PendingCodeAt ( ctx context. Context , account common. Address ) ([] byte , error )
78+ // PendingNonceAt retrieves the current pending nonce associated with an account.
79+ PendingNonceAt ( ctx context. Context , account common. Address ) ( uint64 , error )
5680 // SuggestGasPrice retrieves the currently suggested gas price to allow a timely
5781 // execution of a transaction.
5882 SuggestGasPrice (ctx context.Context ) (* big.Int , error )
59-
60- // HasCode checks if the contract at the given address has any code associated
61- // with it or not. This is needed to differentiate between contract internal
62- // errors and the local chain being out of sync.
63- HasCode (ctx context.Context , contract common.Address , pending bool ) (bool , error )
64-
65- // EstimateGasLimit tries to estimate the gas needed to execute a specific
83+ // EstimateGas tries to estimate the gas needed to execute a specific
6684 // transaction based on the current pending state of the backend blockchain.
6785 // There is no guarantee that this is the true gas limit requirement as other
6886 // transactions may be added or removed by miners, but it should provide a basis
6987 // for setting a reasonable default.
70- EstimateGasLimit (ctx context.Context , sender common.Address , contract * common.Address , value * big.Int , data []byte ) (* big.Int , error )
71-
88+ EstimateGas (ctx context.Context , call ethereum.CallMsg ) (usedGas * big.Int , err error )
7289 // SendTransaction injects the transaction into the pending pool for execution.
7390 SendTransaction (ctx context.Context , tx * types.Transaction ) error
7491}
7592
76- // ContractBackend defines the methods needed to allow operating with contract
77- // on a read-write basis.
78- //
79- // This interface is essentially the union of ContractCaller and ContractTransactor
80- // but due to a bug in the Go compiler (https://github.com/golang/go/issues/6977),
81- // we cannot simply list it as the two interfaces. The other solution is to add a
82- // third interface containing the common methods, but that convolutes the user API
83- // as it introduces yet another parameter to require for initialization.
93+ // ContractBackend defines the methods needed to work with contracts on a read-write basis.
8494type ContractBackend interface {
85- // HasCode checks if the contract at the given address has any code associated
86- // with it or not. This is needed to differentiate between contract internal
87- // errors and the local chain being out of sync.
88- HasCode (ctx context.Context , contract common.Address , pending bool ) (bool , error )
89-
90- // ContractCall executes an Ethereum contract call with the specified data as
91- // the input. The pending flag requests execution against the pending block, not
92- // the stable head of the chain.
93- ContractCall (ctx context.Context , contract common.Address , data []byte , pending bool ) ([]byte , error )
94-
95- // PendingAccountNonce retrieves the current pending nonce associated with an
96- // account.
97- PendingAccountNonce (ctx context.Context , account common.Address ) (uint64 , error )
98-
99- // SuggestGasPrice retrieves the currently suggested gas price to allow a timely
100- // execution of a transaction.
101- SuggestGasPrice (ctx context.Context ) (* big.Int , error )
102-
103- // EstimateGasLimit tries to estimate the gas needed to execute a specific
104- // transaction based on the current pending state of the backend blockchain.
105- // There is no guarantee that this is the true gas limit requirement as other
106- // transactions may be added or removed by miners, but it should provide a basis
107- // for setting a reasonable default.
108- EstimateGasLimit (ctx context.Context , sender common.Address , contract * common.Address , value * big.Int , data []byte ) (* big.Int , error )
109-
110- // SendTransaction injects the transaction into the pending pool for execution.
111- SendTransaction (ctx context.Context , tx * types.Transaction ) error
95+ ContractCaller
96+ ContractTransactor
11297}
0 commit comments