github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/interfaces.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 12:09:39</date> 10 //</624342640053194752> 11 12 13 //包以太坊定义了与以太坊交互的接口。 14 package ethereum 15 16 import ( 17 "context" 18 "errors" 19 "math/big" 20 21 "github.com/ethereum/go-ethereum/common" 22 "github.com/ethereum/go-ethereum/core/types" 23 ) 24 //如果请求的项不存在,则API方法将返回NotFound。 25 var NotFound = errors.New("not found") 26 27 //TODO:将订阅移动到包事件 28 29 //订阅表示事件订阅,其中 30 //通过数据通道传送。 31 type Subscription interface { 32 //取消订阅取消向数据通道发送事件 33 //关闭错误通道。 34 Unsubscribe() 35 //err返回订阅错误通道。错误通道接收 36 //如果订阅存在问题(例如网络连接)的值 37 //传递活动已关闭)。将只发送一个值。 38 //通过退订来关闭错误通道。 39 Err() <-chan error 40 } 41 42 //ChainReader提供对区块链的访问。此接口中的方法访问原始 43 //来自规范链(按块号请求时)或任何 44 //以前由节点下载和处理的区块链分支。街区 45 //number参数可以为nil以选择最新的规范块。读取块头 46 //应尽可能优先于全块。 47 // 48 //如果请求的项不存在,则找不到返回的错误。 49 type ChainReader interface { 50 BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) 51 BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) 52 HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) 53 HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) 54 TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) 55 TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) 56 57 //此方法订阅有关 58 //规范链。 59 SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (Subscription, error) 60 } 61 62 //TransactionReader提供对过去事务及其收据的访问。 63 //实施可能会对以下交易和收据施加任意限制: 64 //可以检索。历史交易可能不可用。 65 // 66 //尽可能避免依赖此接口。合同日志(通过日志过滤器 67 //接口)更可靠,在有链条的情况下通常更安全。 68 //重组。 69 // 70 //如果请求的项不存在,则找不到返回的错误。 71 type TransactionReader interface { 72 //TransactionByHash除了检查 73 //块链。ISPUPDATE返回值指示事务是否已被关闭。 74 //开采了。请注意,事务可能不是规范链的一部分,即使 75 //它没有挂起。 76 TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error) 77 //TransactionReceipt返回挖掘的事务的收据。请注意 78 //事务可能不包括在当前规范链中,即使收据 79 //存在。 80 TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) 81 } 82 83 //ChainStateReader包装对规范区块链的状态trie的访问。注意 84 //接口的实现可能无法返回旧块的状态值。 85 //在许多情况下,使用CallContract比读取原始合同存储更可取。 86 type ChainStateReader interface { 87 BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) 88 StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) 89 CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) 90 NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) 91 } 92 93 //当节点与 94 //以太坊网络。 95 type SyncProgress struct { 96 StartingBlock uint64 //同步开始的块号 97 CurrentBlock uint64 //同步所在的当前块号 98 HighestBlock uint64 //链中最高的声称块数 99 PulledStates uint64 //已下载的状态trie条目数 100 KnownStates uint64 //已知的State Trie条目的总数 101 } 102 103 //ChainSyncReader将访问打包到节点的当前同步状态。如果没有 104 //同步当前正在运行,它返回零。 105 type ChainSyncReader interface { 106 SyncProgress(ctx context.Context) (*SyncProgress, error) 107 } 108 109 //callmsg包含合同调用的参数。 110 type CallMsg struct { 111 From common.Address //“交易”的发送方 112 To *common.Address //目的地合同(合同创建为零) 113 Gas uint64 //如果为0,则调用以接近无穷大的气体执行。 114 GasPrice *big.Int //气体交换率 115 Value *big.Int //随呼叫发送的wei数量 116 Data []byte //输入数据,通常是ABI编码的合同方法调用 117 } 118 119 //ContractCaller提供合同调用,本质上是由 120 //EVM,但没有挖掘到区块链中。ContractCall是用于 121 //执行此类调用。对于围绕特定合同构建的应用程序, 122 //AbigEn工具提供了一种更好的、正确类型的执行调用的方法。 123 type ContractCaller interface { 124 CallContract(ctx context.Context, call CallMsg, blockNumber *big.Int) ([]byte, error) 125 } 126 127 //filterquery包含用于合同日志筛选的选项。 128 type FilterQuery struct { 129 BlockHash *common.Hash //used by eth_getLogs, return logs only from block with this hash 130 FromBlock *big.Int //查询范围的开始,零表示Genesis块 131 ToBlock *big.Int //范围结束,零表示最新块 132 Addresses []common.Address //限制与特定合同创建的事件的匹配 133 134 //主题列表限制与特定事件主题的匹配。每个事件都有一个列表 135 //话题。Topics matches a prefix of that list. An empty element slice matches any 136 //话题。非空元素表示与 137 //包含的主题。 138 // 139 //实例: 140 //或零匹配任何主题列表 141 //匹配第一个位置的主题A 142 //,b匹配第一位置的任何主题,B匹配第二位置的任何主题 143 //A,B匹配第一位置的主题A,第二位置的主题B 144 //A,B,C,D匹配第一位置的主题(A或B),第二位置的主题(C或D) 145 Topics [][]common.Hash 146 } 147 148 //LogFilter提供使用一次性查询或连续查询访问合同日志事件的权限 149 //事件订阅。 150 // 151 //通过流式查询订阅接收的日志可能已删除设置为true, 152 //指示由于链重组而恢复日志。 153 type LogFilterer interface { 154 FilterLogs(ctx context.Context, q FilterQuery) ([]types.Log, error) 155 SubscribeFilterLogs(ctx context.Context, q FilterQuery, ch chan<- types.Log) (Subscription, error) 156 } 157 158 //TransactionSender包装事务发送。sendTransaction方法注入 159 //已将事务签名到挂起的事务池中以供执行。如果交易 160 //是合同创建的,TransactionReceipt方法可用于检索 161 //挖掘交易记录后的合同地址。 162 // 163 //必须对该事务进行签名并包含一个有效的nonce。消费者 164 //API可以使用包帐户来维护本地私钥,并且需要检索 165 //下一个可用的nonce使用pendingnonceat。 166 type TransactionSender interface { 167 SendTransaction(ctx context.Context, tx *types.Transaction) error 168 } 169 170 //Gasparicer包装了天然气价格甲骨文,甲骨文监控区块链以确定 171 //在当前收费市场条件下的最优天然气价格。 172 type GasPricer interface { 173 SuggestGasPrice(ctx context.Context) (*big.Int, error) 174 } 175 176 //一个PungStuteReDead提供对挂起状态的访问,这是所有结果的结果。 177 //尚未包含在区块链中的已知可执行交易。它是 178 //通常用于显示“未确认”操作的结果(例如钱包价值 179 //传输)由用户启动。PendingNoncoat操作是一种很好的方法 180 //检索特定帐户的下一个可用事务。 181 type PendingStateReader interface { 182 PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) 183 PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) 184 PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) 185 PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) 186 PendingTransactionCount(ctx context.Context) (uint, error) 187 } 188 189 //PendingContractCaller可用于对挂起状态执行调用。 190 type PendingContractCaller interface { 191 PendingCallContract(ctx context.Context, call CallMsg) ([]byte, error) 192 } 193 194 //GasEstimator包装EstimateGas,它试图估计执行 195 //基于未决状态的特定事务。不能保证这是 196 //真正的天然气限制要求,因为其他交易可能由矿工添加或删除,但 197 //它应为设定合理违约提供依据。 198 type GasEstimator interface { 199 EstimateGas(ctx context.Context, call CallMsg) (uint64, error) 200 } 201 202 //PendingStateEventer提供对 203 //悬而未决的状态。 204 type PendingStateEventer interface { 205 SubscribePendingTransactions(ctx context.Context, ch chan<- *types.Transaction) (Subscription, error) 206 } 207