// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package bind
import (
"context"
"errors"
"math/big"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
var (
// ErrNoCode is returned by call and transact operations for which the requested
// recipient contract to operate on does not exist in the state db or does not
// have any code associated with it (i.e. suicided).
// ErrNoCode是通过调用和事务处理操作返回的,对于这些操作,状态数据库中不存在请求的要操作的接收方合同,或者没有任何与之相关的代码(即自杀)。
ErrNoCode = errors.New("no contract code at given address")
// ErrNoPendingState is raised when attempting to perform a pending state action
// on a backend that doesn't implement PendingContractCaller.
// 尝试在未实现PendingContractCaller的后端上执行挂起状态操作时引发ErrNoPendingState。
ErrNoPendingState = errors.New("backend does not support pending state")
// ErrNoCodeAfterDeploy is returned by WaitDeployed if contract creation leaves
// an empty contract behind.
// 如果合同创建留下一个空合同,则WaitDeployd将返回ErrNoCodeAfterDeploy。
ErrNoCodeAfterDeploy = errors.New("no contract code after deployment")
)
// ContractCaller defines the methods needed to allow operating with a contract on a read
// only basis.
// ContractCaller定义了允许在只读基础上操作合同所需的方法。
type ContractCaller interface {
// CodeAt returns the code of the given account. This is needed to differentiate
// between contract internal errors and the local chain being out of sync.
// CodeAt返回给定帐户的代码。这是区分合同内部错误和本地链不同步所必需的。
CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
// CallContract executes an Ethereum contract call with the specified data as the
// input.
// CallContract以指定的数据作为输入执行以太坊合约调用。
CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
}
// PendingContractCaller defines methods to perform contract calls on the pending state.
// Call will try to discover this interface when access to the pending state is requested.
// If the backend does not support the pending state, Call returns ErrNoPendingState.
// PendingContractCaller定义了在挂起状态下执行约定调用的方法。当请求访问挂起状态时,调用将尝试发现此接口。如果后端不支持挂起状态,Call将返回ErrNoPendingState。
type PendingContractCaller interface {
// PendingCodeAt returns the code of the given account in the pending state.
// PendingCodeAt返回处于挂起状态的给定帐户的代码。
PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error)
// PendingCallContract executes an Ethereum contract call against the pending state.
// PendingCallContract针对挂起状态执行以太坊合约调用。
PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error)
}
// ContractTransactor defines the methods needed to allow operating with a contract
// on a write only basis. Besides the transacting method, the remainder are helpers
// used when the user does not provide some needed values, but rather leaves it up
// to the transactor to decide.
// ContractTransactor定义了允许在只写的基础上操作合同所需的方法。
// 除了transactioning方法之外,当用户没有提供一些所需的值,而是让transactor来决定时,其余的都是使用的助手。
type ContractTransactor interface {
// HeaderByNumber returns a block header from the current canonical chain. If
// number is nil, the latest known header is returned.
// HeaderByNumber返回当前规范链中的块标头。如果数字为零,则返回最新的已知标头。
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
// PendingCodeAt returns the code of the given account in the pending state.
// PendingCodeAt返回处于挂起状态的给定帐户的代码。
PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
// PendingNonceAt retrieves the current pending nonce associated with an account.
// PendingNonceAt检索与帐户关联的当前挂起的nonce。
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
// execution of a transaction.
// SuggestGasPrice检索当前建议的天然气价格,以便及时执行交易。
SuggestGasPrice(ctx context.Context) (*big.Int, error)
// SuggestGasTipCap retrieves the currently suggested 1559 priority fee to allow
// a timely execution of a transaction.
// SuggestGasTipCap检索当前建议的1559优先级费用,以允许及时执行事务。
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
// EstimateGas tries to estimate the gas needed to execute a specific
// transaction based on the current pending state of the backend blockchain.
// There is no guarantee that this is the true gas limit requirement as other
// transactions may be added or removed by miners, but it should provide a basis
// for setting a reasonable default.
// EstimateGas试图根据后端区块链的当前未决状态来估计执行特定交易所需的天然气。
// 无法保证这是真正的天然气限额要求,因为矿工可能会添加或删除其他交易,但它应该为设定合理的违约提供基础。
EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)
// SendTransaction injects the transaction into the pending pool for execution.
// SendTransaction将事务注入挂起的池中以供执行。
SendTransaction(ctx context.Context, tx *types.Transaction) error
}
// ContractFilterer defines the methods needed to access log events using one-off
// queries or continuous event subscriptions.
// ContractFilterer定义了使用一次性查询或连续事件订阅访问日志事件所需的方法。
type ContractFilterer interface {
// FilterLogs executes a log filter operation, blocking during execution and
// returning all the results in one batch.
// FilterLogs执行日志筛选操作,在执行过程中进行阻塞,并在一个批处理中返回所有结果。
// TODO(karalabe): Deprecate when the subscription one can return past data too.
// TODO(karalabe):不推荐订阅何时也可以返回过去的数据。
FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)
// SubscribeFilterLogs creates a background log filtering operation, returning
// a subscription immediately, which can be used to stream the found events.
// SubscribeFilterLogs创建一个后台日志过滤操作,立即返回一个订阅,该订阅可用于流式传输找到的事件。
SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
}
// DeployBackend wraps the operations needed by WaitMined and WaitDeployed.
// DeployBackend封装WaitMined和WaitDeployd所需的操作。
type DeployBackend interface {
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
}
// ContractBackend defines the methods needed to work with contracts on a read-write basis.
// ContractBackend定义了在读写基础上处理合同所需的方法。
type ContractBackend interface {
ContractCaller
ContractTransactor
ContractFilterer
}
【以太坊源码go-ethereum阅读】accounts/abi/bind/backend.go
猜你喜欢
转载自blog.csdn.net/qq2942713658/article/details/131199765
今日推荐
周排行