github.com/amazechain/amc@v0.1.3/accounts/abi/bind/backend.go (about)

     1  // Copyright 2023 The AmazeChain Authors
     2  // This file is part of the AmazeChain library.
     3  //
     4  // The AmazeChain 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 AmazeChain 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 AmazeChain library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package bind
    18  
    19  import (
    20  	"context"
    21  	"errors"
    22  	amazechain "github.com/amazechain/amc"
    23  	"github.com/amazechain/amc/common/block"
    24  	"github.com/amazechain/amc/common/transaction"
    25  	"github.com/amazechain/amc/common/types"
    26  	"github.com/holiman/uint256"
    27  	"math/big"
    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  	// ErrNoPendingState 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  	// ErrNoCodeAfterDeploy is returned by WaitDeployed if contract creation leaves
    41  	// an empty contract behind.
    42  	ErrNoCodeAfterDeploy = errors.New("no contract code after deployment")
    43  )
    44  
    45  // ContractCaller defines the methods needed to allow operating with a 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 types.Address, blockNumber *uint256.Int) ([]byte, error)
    51  
    52  	// CallContract executes an Ethereum contract call with the specified data as the
    53  	// input.
    54  	CallContract(ctx context.Context, call amazechain.CallMsg, blockNumber *uint256.Int) ([]byte, error)
    55  }
    56  
    57  // PendingContractCaller defines methods to perform contract calls on the pending state.
    58  // Call will try to discover this interface when access to the pending state is requested.
    59  // If the backend does not support the pending state, Call returns ErrNoPendingState.
    60  type PendingContractCaller interface {
    61  	// PendingCodeAt returns the code of the given account in the pending state.
    62  	PendingCodeAt(ctx context.Context, contract types.Address) ([]byte, error)
    63  
    64  	// PendingCallContract executes an Ethereum contract call against the pending state.
    65  	PendingCallContract(ctx context.Context, call amazechain.CallMsg) ([]byte, error)
    66  }
    67  
    68  // ContractTransactor defines the methods needed to allow operating with a contract
    69  // on a write only basis. Besides the transacting method, the remainder are helpers
    70  // used when the user does not provide some needed values, but rather leaves it up
    71  // to the transactor to decide.
    72  type ContractTransactor interface {
    73  	// HeaderByNumber returns a block header from the current canonical chain. If
    74  	// number is nil, the latest known header is returned.
    75  	HeaderByNumber(ctx context.Context, number *uint256.Int) (*block.Header, error)
    76  
    77  	// PendingCodeAt returns the code of the given account in the pending state.
    78  	PendingCodeAt(ctx context.Context, account types.Address) ([]byte, error)
    79  
    80  	// PendingNonceAt retrieves the current pending nonce associated with an account.
    81  	PendingNonceAt(ctx context.Context, account types.Address) (uint64, error)
    82  
    83  	// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
    84  	// execution of a transaction.
    85  	SuggestGasPrice(ctx context.Context) (*uint256.Int, error)
    86  
    87  	// SuggestGasTipCap retrieves the currently suggested 1559 priority fee to allow
    88  	// a timely execution of a transaction.
    89  	SuggestGasTipCap(ctx context.Context) (*uint256.Int, error)
    90  
    91  	// EstimateGas tries to estimate the gas needed to execute a specific
    92  	// transaction based on the current pending state of the backend blockchain.
    93  	// There is no guarantee that this is the true gas limit requirement as other
    94  	// transactions may be added or removed by miners, but it should provide a basis
    95  	// for setting a reasonable default.
    96  	EstimateGas(ctx context.Context, call amazechain.CallMsg) (gas uint64, err error)
    97  
    98  	// SendTransaction injects the transaction into the pending pool for execution.
    99  	SendTransaction(ctx context.Context, tx *transaction.Transaction) error
   100  }
   101  
   102  // ContractFilterer defines the methods needed to access log events using one-off
   103  // queries or continuous event subscriptions.
   104  type ContractFilterer interface {
   105  	// FilterLogs executes a log filter operation, blocking during execution and
   106  	// returning all the results in one batch.
   107  	//
   108  	// TODO(karalabe): Deprecate when the subscription one can return past data too.
   109  	FilterLogs(ctx context.Context, query amazechain.FilterQuery) ([]block.Log, error)
   110  
   111  	// SubscribeFilterLogs creates a background log filtering operation, returning
   112  	// a subscription immediately, which can be used to stream the found events.
   113  	SubscribeFilterLogs(ctx context.Context, query amazechain.FilterQuery, ch chan<- block.Log) (amazechain.Subscription, error)
   114  }
   115  
   116  // DeployBackend wraps the operations needed by WaitMined and WaitDeployed.
   117  type DeployBackend interface {
   118  	TransactionReceipt(ctx context.Context, txHash types.Hash) (*block.Receipt, error)
   119  	CodeAt(ctx context.Context, account types.Address, blockNumber *big.Int) ([]byte, error)
   120  }
   121  
   122  // ContractBackend defines the methods needed to work with contracts on a read-write basis.
   123  type ContractBackend interface {
   124  	ContractCaller
   125  	ContractTransactor
   126  	ContractFilterer
   127  }