github.com/aigarnetwork/aigar@v0.0.0-20191115204914-d59a6eb70f8e/accounts/abi/bind/backend.go (about)

     1  //  Copyright 2018 The go-ethereum Authors
     2  //  Copyright 2019 The go-aigar Authors
     3  //  This file is part of the go-aigar library.
     4  //
     5  //  The go-aigar 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-aigar 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-aigar library. If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package bind
    19  
    20  import (
    21  	"context"
    22  	"errors"
    23  	"math/big"
    24  
    25  	"github.com/AigarNetwork/aigar"
    26  	"github.com/AigarNetwork/aigar/common"
    27  	"github.com/AigarNetwork/aigar/core/types"
    28  )
    29  
    30  var (
    31  	// ErrNoCode is returned by call and transact operations for which the requested
    32  	// recipient contract to operate on does not exist in the state db or does not
    33  	// have any code associated with it (i.e. suicided).
    34  	ErrNoCode = errors.New("no contract code at given address")
    35  
    36  	// This error is raised when attempting to perform a pending state action
    37  	// on a backend that doesn't implement PendingContractCaller.
    38  	ErrNoPendingState = errors.New("backend does not support pending state")
    39  
    40  	// This error is returned by WaitDeployed if contract creation leaves an
    41  	// empty contract behind.
    42  	ErrNoCodeAfterDeploy = errors.New("no contract code after deployment")
    43  )
    44  
    45  // ContractCaller defines the methods needed to allow operating with contract on a read
    46  // only basis.
    47  type ContractCaller interface {
    48  	// CodeAt returns the code of the given account. This is needed to differentiate
    49  	// between contract internal errors and the local chain being out of sync.
    50  	CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
    51  	// ContractCall executes an Ethereum contract call with the specified data as the
    52  	// input.
    53  	CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
    54  }
    55  
    56  // PendingContractCaller defines methods to perform contract calls on the pending state.
    57  // Call will try to discover this interface when access to the pending state is requested.
    58  // If the backend does not support the pending state, Call returns ErrNoPendingState.
    59  type PendingContractCaller interface {
    60  	// PendingCodeAt returns the code of the given account in the pending state.
    61  	PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error)
    62  	// PendingCallContract executes an Ethereum contract call against the pending state.
    63  	PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error)
    64  }
    65  
    66  // ContractTransactor defines the methods needed to allow operating with contract
    67  // on a write only basis. Beside the transacting method, the remainder are helpers
    68  // used when the user does not provide some needed values, but rather leaves it up
    69  // to the transactor to decide.
    70  type ContractTransactor interface {
    71  	// PendingCodeAt returns the code of the given account in the pending state.
    72  	PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
    73  	// PendingNonceAt retrieves the current pending nonce associated with an account.
    74  	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
    75  	// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
    76  	// execution of a transaction.
    77  	SuggestGasPrice(ctx context.Context) (*big.Int, error)
    78  	// EstimateGas tries to estimate the gas needed to execute a specific
    79  	// transaction based on the current pending state of the backend blockchain.
    80  	// There is no guarantee that this is the true gas limit requirement as other
    81  	// transactions may be added or removed by miners, but it should provide a basis
    82  	// for setting a reasonable default.
    83  	EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)
    84  	// SendTransaction injects the transaction into the pending pool for execution.
    85  	SendTransaction(ctx context.Context, tx *types.Transaction) error
    86  }
    87  
    88  // ContractFilterer defines the methods needed to access log events using one-off
    89  // queries or continuous event subscriptions.
    90  type ContractFilterer interface {
    91  	// FilterLogs executes a log filter operation, blocking during execution and
    92  	// returning all the results in one batch.
    93  	//
    94  	// TODO(karalabe): Deprecate when the subscription one can return past data too.
    95  	FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)
    96  
    97  	// SubscribeFilterLogs creates a background log filtering operation, returning
    98  	// a subscription immediately, which can be used to stream the found events.
    99  	SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
   100  }
   101  
   102  // DeployBackend wraps the operations needed by WaitMined and WaitDeployed.
   103  type DeployBackend interface {
   104  	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
   105  	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
   106  }
   107  
   108  // ContractBackend defines the methods needed to work with contracts on a read-write basis.
   109  type ContractBackend interface {
   110  	ContractCaller
   111  	ContractTransactor
   112  	ContractFilterer
   113  }