github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/accounts/abi/bind/backend.go (about)

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