github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/interfaces.go (about)

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