@@ -27,15 +27,16 @@ import (
27
27
// ErrNoCode is returned by call and transact operations for which the requested
28
28
// recipient contract to operate on does not exist in the state db or does not
29
29
// have any code associated with it (i.e. suicided).
30
- //
31
- // Please note, this error string is part of the RPC API and is expected by the
32
- // native contract bindings to signal this particular error. Do not change this
33
- // as it will break all dependent code!
34
30
var ErrNoCode = errors .New ("no contract code at given address" )
35
31
36
32
// ContractCaller defines the methods needed to allow operating with contract on a read
37
33
// only basis.
38
34
type ContractCaller interface {
35
+ // HasCode checks if the contract at the given address has any code associated
36
+ // with it or not. This is needed to differentiate between contract internal
37
+ // errors and the local chain being out of sync.
38
+ HasCode (contract common.Address , pending bool ) (bool , error )
39
+
39
40
// ContractCall executes an Ethereum contract call with the specified data as
40
41
// the input. The pending flag requests execution against the pending block, not
41
42
// the stable head of the chain.
@@ -55,6 +56,11 @@ type ContractTransactor interface {
55
56
// execution of a transaction.
56
57
SuggestGasPrice () (* big.Int , error )
57
58
59
+ // HasCode checks if the contract at the given address has any code associated
60
+ // with it or not. This is needed to differentiate between contract internal
61
+ // errors and the local chain being out of sync.
62
+ HasCode (contract common.Address , pending bool ) (bool , error )
63
+
58
64
// EstimateGasLimit tries to estimate the gas needed to execute a specific
59
65
// transaction based on the current pending state of the backend blockchain.
60
66
// There is no guarantee that this is the true gas limit requirement as other
@@ -68,7 +74,38 @@ type ContractTransactor interface {
68
74
69
75
// ContractBackend defines the methods needed to allow operating with contract
70
76
// on a read-write basis.
77
+ //
78
+ // This interface is essentially the union of ContractCaller and ContractTransactor
79
+ // but due to a bug in the Go compiler (https://github.com/golang/go/issues/6977),
80
+ // we cannot simply list it as the two interfaces. The other solution is to add a
81
+ // third interface containing the common methods, but that convolutes the user API
82
+ // as it introduces yet another parameter to require for initialization.
71
83
type ContractBackend interface {
72
- ContractCaller
73
- ContractTransactor
84
+ // HasCode checks if the contract at the given address has any code associated
85
+ // with it or not. This is needed to differentiate between contract internal
86
+ // errors and the local chain being out of sync.
87
+ HasCode (contract common.Address , pending bool ) (bool , error )
88
+
89
+ // ContractCall executes an Ethereum contract call with the specified data as
90
+ // the input. The pending flag requests execution against the pending block, not
91
+ // the stable head of the chain.
92
+ ContractCall (contract common.Address , data []byte , pending bool ) ([]byte , error )
93
+
94
+ // PendingAccountNonce retrieves the current pending nonce associated with an
95
+ // account.
96
+ PendingAccountNonce (account common.Address ) (uint64 , error )
97
+
98
+ // SuggestGasPrice retrieves the currently suggested gas price to allow a timely
99
+ // execution of a transaction.
100
+ SuggestGasPrice () (* big.Int , error )
101
+
102
+ // EstimateGasLimit tries to estimate the gas needed to execute a specific
103
+ // transaction based on the current pending state of the backend blockchain.
104
+ // There is no guarantee that this is the true gas limit requirement as other
105
+ // transactions may be added or removed by miners, but it should provide a basis
106
+ // for setting a reasonable default.
107
+ EstimateGasLimit (sender common.Address , contract * common.Address , value * big.Int , data []byte ) (* big.Int , error )
108
+
109
+ // SendTransaction injects the transaction into the pending pool for execution.
110
+ SendTransaction (tx * types.Transaction ) error
74
111
}
0 commit comments