github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/accounts/abi/bind/backend.go (about)

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