github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/mobile/ethereum.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:43</date>
    10  //</624342653793734656>
    11  
    12  
    13  //包含go-ethereum根包中的所有包装。
    14  
    15  package geth
    16  
    17  import (
    18  	"errors"
    19  
    20  	ethereum "github.com/ethereum/go-ethereum"
    21  	"github.com/ethereum/go-ethereum/common"
    22  )
    23  
    24  //订阅表示事件订阅,其中
    25  //通过数据通道传送。
    26  type Subscription struct {
    27  	sub ethereum.Subscription
    28  }
    29  
    30  //取消订阅取消向数据通道发送事件
    31  //关闭错误通道。
    32  func (s *Subscription) Unsubscribe() {
    33  	s.sub.Unsubscribe()
    34  }
    35  
    36  //callmsg包含合同调用的参数。
    37  type CallMsg struct {
    38  	msg ethereum.CallMsg
    39  }
    40  
    41  //newcallmsg创建一个空的合同调用参数列表。
    42  func NewCallMsg() *CallMsg {
    43  	return new(CallMsg)
    44  }
    45  
    46  func (msg *CallMsg) GetFrom() *Address    { return &Address{msg.msg.From} }
    47  func (msg *CallMsg) GetGas() int64        { return int64(msg.msg.Gas) }
    48  func (msg *CallMsg) GetGasPrice() *BigInt { return &BigInt{msg.msg.GasPrice} }
    49  func (msg *CallMsg) GetValue() *BigInt    { return &BigInt{msg.msg.Value} }
    50  func (msg *CallMsg) GetData() []byte      { return msg.msg.Data }
    51  func (msg *CallMsg) GetTo() *Address {
    52  	if to := msg.msg.To; to != nil {
    53  		return &Address{*msg.msg.To}
    54  	}
    55  	return nil
    56  }
    57  
    58  func (msg *CallMsg) SetFrom(address *Address)  { msg.msg.From = address.address }
    59  func (msg *CallMsg) SetGas(gas int64)          { msg.msg.Gas = uint64(gas) }
    60  func (msg *CallMsg) SetGasPrice(price *BigInt) { msg.msg.GasPrice = price.bigint }
    61  func (msg *CallMsg) SetValue(value *BigInt)    { msg.msg.Value = value.bigint }
    62  func (msg *CallMsg) SetData(data []byte)       { msg.msg.Data = common.CopyBytes(data) }
    63  func (msg *CallMsg) SetTo(address *Address) {
    64  	if address == nil {
    65  		msg.msg.To = nil
    66  		return
    67  	}
    68  	msg.msg.To = &address.address
    69  }
    70  
    71  //当节点与
    72  //以太坊网络。
    73  type SyncProgress struct {
    74  	progress ethereum.SyncProgress
    75  }
    76  
    77  func (p *SyncProgress) GetStartingBlock() int64 { return int64(p.progress.StartingBlock) }
    78  func (p *SyncProgress) GetCurrentBlock() int64  { return int64(p.progress.CurrentBlock) }
    79  func (p *SyncProgress) GetHighestBlock() int64  { return int64(p.progress.HighestBlock) }
    80  func (p *SyncProgress) GetPulledStates() int64  { return int64(p.progress.PulledStates) }
    81  func (p *SyncProgress) GetKnownStates() int64   { return int64(p.progress.KnownStates) }
    82  
    83  //主题是一组用于筛选事件的主题列表。
    84  type Topics struct{ topics [][]common.Hash }
    85  
    86  //newtopics创建一个未初始化主题的切片。
    87  func NewTopics(size int) *Topics {
    88  	return &Topics{
    89  		topics: make([][]common.Hash, size),
    90  	}
    91  }
    92  
    93  //newtopicsempty创建主题值的空切片。
    94  func NewTopicsEmpty() *Topics {
    95  	return NewTopics(0)
    96  }
    97  
    98  //SIZE返回集合内主题列表的数目
    99  func (t *Topics) Size() int {
   100  	return len(t.topics)
   101  }
   102  
   103  //get从切片返回给定索引处的主题列表。
   104  func (t *Topics) Get(index int) (hashes *Hashes, _ error) {
   105  	if index < 0 || index >= len(t.topics) {
   106  		return nil, errors.New("index out of bounds")
   107  	}
   108  	return &Hashes{t.topics[index]}, nil
   109  }
   110  
   111  //set在切片中的给定索引处设置主题列表。
   112  func (t *Topics) Set(index int, topics *Hashes) error {
   113  	if index < 0 || index >= len(t.topics) {
   114  		return errors.New("index out of bounds")
   115  	}
   116  	t.topics[index] = topics.hashes
   117  	return nil
   118  }
   119  
   120  //附加将新的主题列表添加到切片的末尾。
   121  func (t *Topics) Append(topics *Hashes) {
   122  	t.topics = append(t.topics, topics.hashes)
   123  }
   124  
   125  //filterquery包含用于合同日志筛选的选项。
   126  type FilterQuery struct {
   127  	query ethereum.FilterQuery
   128  }
   129  
   130  //newfilterquery为合同日志筛选创建空的筛选器查询。
   131  func NewFilterQuery() *FilterQuery {
   132  	return new(FilterQuery)
   133  }
   134  
   135  func (fq *FilterQuery) GetFromBlock() *BigInt    { return &BigInt{fq.query.FromBlock} }
   136  func (fq *FilterQuery) GetToBlock() *BigInt      { return &BigInt{fq.query.ToBlock} }
   137  func (fq *FilterQuery) GetAddresses() *Addresses { return &Addresses{fq.query.Addresses} }
   138  func (fq *FilterQuery) GetTopics() *Topics       { return &Topics{fq.query.Topics} }
   139  
   140  func (fq *FilterQuery) SetFromBlock(fromBlock *BigInt)    { fq.query.FromBlock = fromBlock.bigint }
   141  func (fq *FilterQuery) SetToBlock(toBlock *BigInt)        { fq.query.ToBlock = toBlock.bigint }
   142  func (fq *FilterQuery) SetAddresses(addresses *Addresses) { fq.query.Addresses = addresses.addresses }
   143  func (fq *FilterQuery) SetTopics(topics *Topics)          { fq.query.Topics = topics.topics }
   144