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