github.com/klaytn/klaytn@v1.12.1/accounts/abi/bind/backend.go (about)

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