github.com/ethereum/go-ethereum@v1.14.3/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/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  
    48  // ContractCaller defines the methods needed to allow operating with a contract on a read
    49  // only basis.
    50  type ContractCaller interface {
    51  	// CodeAt returns the code of the given account. This is needed to differentiate
    52  	// between contract internal errors and the local chain being out of sync.
    53  	CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
    54  
    55  	// CallContract executes an Ethereum contract call with the specified data as the
    56  	// input.
    57  	CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
    58  }
    59  
    60  // PendingContractCaller defines methods to perform contract calls on the pending state.
    61  // Call will try to discover this interface when access to the pending state is requested.
    62  // If the backend does not support the pending state, Call returns ErrNoPendingState.
    63  type PendingContractCaller interface {
    64  	// PendingCodeAt returns the code of the given account in the pending state.
    65  	PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error)
    66  
    67  	// PendingCallContract executes an Ethereum contract call against the pending state.
    68  	PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error)
    69  }
    70  
    71  // BlockHashContractCaller defines methods to perform contract calls on a specific block hash.
    72  // Call will try to discover this interface when access to a block by hash is requested.
    73  // If the backend does not support the block hash state, Call returns ErrNoBlockHashState.
    74  type BlockHashContractCaller interface {
    75  	// CodeAtHash returns the code of the given account in the state at the specified block hash.
    76  	CodeAtHash(ctx context.Context, contract common.Address, blockHash common.Hash) ([]byte, error)
    77  
    78  	// CallContractAtHash executes an Ethereum contract call against the state at the specified block hash.
    79  	CallContractAtHash(ctx context.Context, call ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
    80  }
    81  
    82  // ContractTransactor defines the methods needed to allow operating with a contract
    83  // on a write only basis. Besides the transacting method, the remainder are helpers
    84  // used when the user does not provide some needed values, but rather leaves it up
    85  // to the transactor to decide.
    86  type ContractTransactor interface {
    87  	ethereum.GasEstimator
    88  	ethereum.GasPricer
    89  	ethereum.GasPricer1559
    90  	ethereum.TransactionSender
    91  
    92  	// HeaderByNumber returns a block header from the current canonical chain. If
    93  	// number is nil, the latest known header is returned.
    94  	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
    95  
    96  	// PendingCodeAt returns the code of the given account in the pending state.
    97  	PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
    98  
    99  	// PendingNonceAt retrieves the current pending nonce associated with an account.
   100  	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
   101  }
   102  
   103  // DeployBackend wraps the operations needed by WaitMined and WaitDeployed.
   104  type DeployBackend interface {
   105  	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
   106  	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
   107  }
   108  
   109  // ContractFilterer defines the methods needed to access log events using one-off
   110  // queries or continuous event subscriptions.
   111  type ContractFilterer interface {
   112  	ethereum.LogFilterer
   113  }
   114  
   115  // ContractBackend defines the methods needed to work with contracts on a read-write basis.
   116  type ContractBackend interface {
   117  	ContractCaller
   118  	ContractTransactor
   119  	ContractFilterer
   120  }