github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/accounts/abi/bind/backend.go (about)

     1  // Copyright 2016 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  	"errors"
    21  	"math/big"
    22  
    23  	"github.com/ethereumproject/go-ethereum/common"
    24  	"github.com/ethereumproject/go-ethereum/core/types"
    25  )
    26  
    27  // ErrNoCode is returned by call and transact operations for which the requested
    28  // recipient contract to operate on does not exist in the state db or does not
    29  // have any code associated with it (i.e. suicided).
    30  var ErrNoCode = errors.New("no contract code at given address")
    31  
    32  // ContractCaller defines the methods needed to allow operating with contract on a read
    33  // only basis.
    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  
    40  	// ContractCall executes an Ethereum contract call with the specified data as
    41  	// the input. The pending flag requests execution against the pending block, not
    42  	// the stable head of the chain.
    43  	ContractCall(contract common.Address, data []byte, pending bool) ([]byte, error)
    44  }
    45  
    46  // ContractTransactor defines the methods needed to allow operating with contract
    47  // on a write only basis. Beside the transacting method, the remainder are helpers
    48  // used when the user does not provide some needed values, but rather leaves it up
    49  // to the transactor to decide.
    50  type ContractTransactor interface {
    51  	// PendingAccountNonce retrieves the current pending nonce associated with an
    52  	// account.
    53  	PendingAccountNonce(account common.Address) (uint64, error)
    54  
    55  	// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
    56  	// execution of a transaction.
    57  	SuggestGasPrice() (*big.Int, error)
    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  
    64  	// EstimateGasLimit tries to estimate the gas needed to execute a specific
    65  	// transaction based on the current pending state of the backend blockchain.
    66  	// There is no guarantee that this is the true gas limit requirement as other
    67  	// transactions may be added or removed by miners, but it should provide a basis
    68  	// for setting a reasonable default.
    69  	EstimateGasLimit(sender common.Address, contract *common.Address, value *big.Int, data []byte) (*big.Int, error)
    70  
    71  	// SendTransaction injects the transaction into the pending pool for execution.
    72  	SendTransaction(tx *types.Transaction) error
    73  }
    74  
    75  // ContractBackend defines the methods needed to allow operating with contract
    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.
    83  type ContractBackend interface {
    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
   111  }