github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/accounts/abi/bind/backend.go (about)

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