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