github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/accounts/abi/bind/backend.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:30</date> 10 //</624450059693461504> 11 12 13 package bind 14 15 import ( 16 "context" 17 "errors" 18 "math/big" 19 20 "github.com/ethereum/go-ethereum" 21 "github.com/ethereum/go-ethereum/common" 22 "github.com/ethereum/go-ethereum/core/types" 23 ) 24 25 var ( 26 //errnocode由请求的调用和事务处理操作返回 27 //要操作的收件人合同在状态db中不存在或不存在 28 //有任何与之相关的代码(即自杀)。 29 ErrNoCode = errors.New("no contract code at given address") 30 31 //尝试执行挂起状态操作时出现此错误 32 //在不实现PendingContractCaller的后端上。 33 ErrNoPendingState = errors.New("backend does not support pending state") 34 35 //如果合同创建离开 36 //后面是空合同。 37 ErrNoCodeAfterDeploy = errors.New("no contract code after deployment") 38 ) 39 40 //ContractCaller定义允许在读取时使用约定进行操作所需的方法 41 //只有基础。 42 type ContractCaller interface { 43 //codeat返回给定帐户的代码。这是为了区分 44 //在合同内部错误和本地链不同步之间。 45 CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) 46 //ContractCall以指定的数据作为 47 //输入。 48 CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) 49 } 50 51 //PendingContractCaller定义在挂起状态下执行协定调用的方法。 52 //当请求访问挂起状态时,调用将尝试发现此接口。 53 //如果后端不支持挂起状态,则call返回errnopendingState。 54 type PendingContractCaller interface { 55 //PendingCodeAt返回处于挂起状态的给定帐户的代码。 56 PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error) 57 //PendingCallContract针对挂起状态执行以太坊合同调用。 58 PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error) 59 } 60 61 //ContractTransactor定义了允许使用Contract操作所需的方法 62 //只写。除了事务处理方法,其余的是帮助器 63 //当用户不提供某些需要的值,而是将其保留时使用 64 //交交易人决定。 65 type ContractTransactor interface { 66 //PendingCodeAt返回处于挂起状态的给定帐户的代码。 67 PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) 68 //pendingnonceat检索与帐户关联的当前挂起的nonce。 69 PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) 70 //SuggestGasprice检索当前建议的天然气价格,以便及时 71 //交易的执行。 72 SuggestGasPrice(ctx context.Context) (*big.Int, error) 73 //EstimateGas试图估计执行特定 74 //基于后端区块链当前挂起状态的交易。 75 //不能保证这是真正的气体限值要求 76 //交易可以由矿工添加或删除,但它应该提供一个基础 77 //设置合理的默认值。 78 EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) 79 //sendTransaction将事务注入挂起池以执行。 80 SendTransaction(ctx context.Context, tx *types.Transaction) error 81 } 82 83 //ContractFilter定义了使用一次性访问日志事件所需的方法 84 //查询或连续事件订阅。 85 type ContractFilterer interface { 86 //filterlogs执行日志筛选操作,在执行期间阻塞,以及 87 //一批返回所有结果。 88 // 89 //TODO(karalabe):当订阅可以返回过去的数据时,取消预测。 90 FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) 91 92 //subscribeBilterLogs创建后台日志筛选操作,返回 93 //立即订阅,可用于流式处理找到的事件。 94 SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) 95 } 96 97 //deploybackend包装waitmined和waitdeployed所需的操作。 98 type DeployBackend interface { 99 TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) 100 CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) 101 } 102 103 //ContractBackend定义了在读写基础上处理合同所需的方法。 104 type ContractBackend interface { 105 ContractCaller 106 ContractTransactor 107 ContractFilterer 108 } 109