github.com/ethereum/go-ethereum@v1.16.1/accounts/abi/bind/v2/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/ethereum/go-ethereum" 25 "github.com/ethereum/go-ethereum/common" 26 "github.com/ethereum/go-ethereum/core/types" 27 ) 28 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. self-destructed). 33 ErrNoCode = errors.New("no contract code at given address") 34 35 // ErrNoPendingState 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 // ErrNoBlockHashState is raised when attempting to perform a block hash action 40 // on a backend that doesn't implement BlockHashContractCaller. 41 ErrNoBlockHashState = errors.New("backend does not support block hash state") 42 43 // ErrNoCodeAfterDeploy is returned by WaitDeployed if contract creation leaves 44 // an empty contract behind. 45 ErrNoCodeAfterDeploy = errors.New("no contract code after deployment") 46 47 // ErrNoAddressInReceipt is returned by WaitDeployed when the receipt for the 48 // transaction hash does not contain a contract address. This error may indicate 49 // that the transaction hash was not a CREATE transaction. 50 ErrNoAddressInReceipt = errors.New("no contract address in receipt") 51 ) 52 53 // ContractCaller defines the methods needed to allow operating with a contract on a read 54 // only basis. 55 type ContractCaller interface { 56 // CodeAt returns the code of the given account. This is needed to differentiate 57 // between contract internal errors and the local chain being out of sync. 58 CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) 59 60 // CallContract executes an Ethereum contract call with the specified data as the 61 // input. 62 CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) 63 } 64 65 // PendingContractCaller defines methods to perform contract calls on the pending state. 66 // Call will try to discover this interface when access to the pending state is requested. 67 // If the backend does not support the pending state, Call returns ErrNoPendingState. 68 type PendingContractCaller interface { 69 // PendingCodeAt returns the code of the given account in the pending state. 70 PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error) 71 72 // PendingCallContract executes an Ethereum contract call against the pending state. 73 PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error) 74 } 75 76 // BlockHashContractCaller defines methods to perform contract calls on a specific block hash. 77 // Call will try to discover this interface when access to a block by hash is requested. 78 // If the backend does not support the block hash state, Call returns ErrNoBlockHashState. 79 type BlockHashContractCaller interface { 80 // CodeAtHash returns the code of the given account in the state at the specified block hash. 81 CodeAtHash(ctx context.Context, contract common.Address, blockHash common.Hash) ([]byte, error) 82 83 // CallContractAtHash executes an Ethereum contract call against the state at the specified block hash. 84 CallContractAtHash(ctx context.Context, call ethereum.CallMsg, blockHash common.Hash) ([]byte, error) 85 } 86 87 // ContractTransactor defines the methods needed to allow operating with a contract 88 // on a write only basis. Besides the transacting method, the remainder are helpers 89 // used when the user does not provide some needed values, but rather leaves it up 90 // to the transactor to decide. 91 type ContractTransactor interface { 92 ethereum.GasEstimator 93 ethereum.GasPricer 94 ethereum.GasPricer1559 95 ethereum.TransactionSender 96 97 // HeaderByNumber returns a block header from the current canonical chain. If 98 // number is nil, the latest known header is returned. 99 HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) 100 101 // PendingCodeAt returns the code of the given account in the pending state. 102 PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) 103 104 // PendingNonceAt retrieves the current pending nonce associated with an account. 105 PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) 106 } 107 108 // DeployBackend wraps the operations needed by WaitMined and WaitDeployed. 109 type DeployBackend interface { 110 TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) 111 CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) 112 } 113 114 // ContractFilterer defines the methods needed to access log events using one-off 115 // queries or continuous event subscriptions. 116 type ContractFilterer interface { 117 ethereum.LogFilterer 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 } 126 127 // Backend combines all backend methods used in this package. This type is provided for 128 // convenience. It is meant to be used when you need to hold a reference to a backend that 129 // is used for both deployment and contract interaction. 130 type Backend interface { 131 DeployBackend 132 ContractBackend 133 }