github.com/ethxdao/go-ethereum@v0.0.0-20221218102228-5ae34a9cc189/accounts/abi/bind/backend.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package bind 18 19 import ( 20 "context" 21 "errors" 22 "math/big" 23 24 "github.com/ethxdao/go-ethereum/common" 25 "github.com/ethxdao/go-ethereum/core/types" 26 ) 27 28 var ( 29 // ErrNoCode is returned by call and transact operations for which the requested 30 // recipient contract to operate on does not exist in the state db or does not 31 // have any code associated with it (i.e. suicided). 32 ErrNoCode = errors.New("no contract code at given address") 33 34 // ErrNoPendingState is raised when attempting to perform a pending state action 35 // on a backend that doesn't implement PendingContractCaller. 36 ErrNoPendingState = errors.New("backend does not support pending state") 37 38 // ErrNoCodeAfterDeploy is returned by WaitDeployed if contract creation leaves 39 // an empty contract behind. 40 ErrNoCodeAfterDeploy = errors.New("no contract code after deployment") 41 ) 42 43 // ContractCaller defines the methods needed to allow operating with a contract on a read 44 // only basis. 45 type ContractCaller interface { 46 // CodeAt returns the code of the given account. This is needed to differentiate 47 // between contract internal errors and the local chain being out of sync. 48 CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) 49 50 // CallContract 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 } 54 55 // PendingContractCaller defines methods to perform contract calls on the pending state. 56 // Call will try to discover this interface when access to the pending state is requested. 57 // If the backend does not support the pending state, Call returns ErrNoPendingState. 58 type PendingContractCaller interface { 59 // PendingCodeAt returns the code of the given account in the pending state. 60 PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error) 61 62 // PendingCallContract executes an Ethereum contract call against the pending state. 63 PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error) 64 } 65 66 // ContractTransactor defines the methods needed to allow operating with a contract 67 // on a write only basis. Besides the transacting method, the remainder are helpers 68 // used when the user does not provide some needed values, but rather leaves it up 69 // to the transactor to decide. 70 type ContractTransactor interface { 71 // HeaderByNumber returns a block header from the current canonical chain. If 72 // number is nil, the latest known header is returned. 73 HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) 74 75 // PendingCodeAt returns the code of the given account in the pending state. 76 PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) 77 78 // PendingNonceAt retrieves the current pending nonce associated with an account. 79 PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) 80 81 // SuggestGasPrice retrieves the currently suggested gas price to allow a timely 82 // execution of a transaction. 83 SuggestGasPrice(ctx context.Context) (*big.Int, error) 84 85 // SuggestGasTipCap retrieves the currently suggested 1559 priority fee to allow 86 // a timely execution of a transaction. 87 SuggestGasTipCap(ctx context.Context) (*big.Int, error) 88 89 // EstimateGas tries to estimate the gas needed to execute a specific 90 // transaction based on the current pending state of the backend blockchain. 91 // There is no guarantee that this is the true gas limit requirement as other 92 // transactions may be added or removed by miners, but it should provide a basis 93 // for setting a reasonable default. 94 EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) 95 96 // SendTransaction injects the transaction into the pending pool for execution. 97 SendTransaction(ctx context.Context, tx *types.Transaction) error 98 } 99 100 // ContractFilterer defines the methods needed to access log events using one-off 101 // queries or continuous event subscriptions. 102 type ContractFilterer interface { 103 // FilterLogs executes a log filter operation, blocking during execution and 104 // returning all the results in one batch. 105 // 106 // TODO(karalabe): Deprecate when the subscription one can return past data too. 107 FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) 108 109 // SubscribeFilterLogs creates a background log filtering operation, returning 110 // a subscription immediately, which can be used to stream the found events. 111 SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) 112 } 113 114 // DeployBackend wraps the operations needed by WaitMined and WaitDeployed. 115 type DeployBackend interface { 116 TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) 117 CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) 118 } 119 120 // ContractBackend defines the methods needed to work with contracts on a read-write basis. 121 type ContractBackend interface { 122 ContractCaller 123 ContractTransactor 124 ContractFilterer 125 }