github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/mobile/sberex.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 // Contains all the wrappers from the go-sberex root package. 13 14 package geth 15 16 import ( 17 "errors" 18 19 sberex "github.com/Sberex/go-sberex" 20 "github.com/Sberex/go-sberex/common" 21 ) 22 23 // Subscription represents an event subscription where events are 24 // delivered on a data channel. 25 type Subscription struct { 26 sub sberex.Subscription 27 } 28 29 // Unsubscribe cancels the sending of events to the data channel 30 // and closes the error channel. 31 func (s *Subscription) Unsubscribe() { 32 s.sub.Unsubscribe() 33 } 34 35 // CallMsg contains parameters for contract calls. 36 type CallMsg struct { 37 msg sberex.CallMsg 38 } 39 40 // NewCallMsg creates an empty contract call parameter list. 41 func NewCallMsg() *CallMsg { 42 return new(CallMsg) 43 } 44 45 func (msg *CallMsg) GetFrom() *Address { return &Address{msg.msg.From} } 46 func (msg *CallMsg) GetGas() int64 { return int64(msg.msg.Gas) } 47 func (msg *CallMsg) GetGasPrice() *BigInt { return &BigInt{msg.msg.GasPrice} } 48 func (msg *CallMsg) GetValue() *BigInt { return &BigInt{msg.msg.Value} } 49 func (msg *CallMsg) GetData() []byte { return msg.msg.Data } 50 func (msg *CallMsg) GetTo() *Address { 51 if to := msg.msg.To; to != nil { 52 return &Address{*msg.msg.To} 53 } 54 return nil 55 } 56 57 func (msg *CallMsg) SetFrom(address *Address) { msg.msg.From = address.address } 58 func (msg *CallMsg) SetGas(gas int64) { msg.msg.Gas = uint64(gas) } 59 func (msg *CallMsg) SetGasPrice(price *BigInt) { msg.msg.GasPrice = price.bigint } 60 func (msg *CallMsg) SetValue(value *BigInt) { msg.msg.Value = value.bigint } 61 func (msg *CallMsg) SetData(data []byte) { msg.msg.Data = common.CopyBytes(data) } 62 func (msg *CallMsg) SetTo(address *Address) { 63 if address == nil { 64 msg.msg.To = nil 65 } 66 msg.msg.To = &address.address 67 } 68 69 // SyncProgress gives progress indications when the node is synchronising with 70 // the Sberex network. 71 type SyncProgress struct { 72 progress sberex.SyncProgress 73 } 74 75 func (p *SyncProgress) GetStartingBlock() int64 { return int64(p.progress.StartingBlock) } 76 func (p *SyncProgress) GetCurrentBlock() int64 { return int64(p.progress.CurrentBlock) } 77 func (p *SyncProgress) GetHighestBlock() int64 { return int64(p.progress.HighestBlock) } 78 func (p *SyncProgress) GetPulledStates() int64 { return int64(p.progress.PulledStates) } 79 func (p *SyncProgress) GetKnownStates() int64 { return int64(p.progress.KnownStates) } 80 81 // Topics is a set of topic lists to filter events with. 82 type Topics struct{ topics [][]common.Hash } 83 84 // NewTopics creates a slice of uninitialized Topics. 85 func NewTopics(size int) *Topics { 86 return &Topics{ 87 topics: make([][]common.Hash, size), 88 } 89 } 90 91 // NewTopicsEmpty creates an empty slice of Topics values. 92 func NewTopicsEmpty() *Topics { 93 return NewTopics(0) 94 } 95 96 // Size returns the number of topic lists inside the set 97 func (t *Topics) Size() int { 98 return len(t.topics) 99 } 100 101 // Get returns the topic list at the given index from the slice. 102 func (t *Topics) Get(index int) (hashes *Hashes, _ error) { 103 if index < 0 || index >= len(t.topics) { 104 return nil, errors.New("index out of bounds") 105 } 106 return &Hashes{t.topics[index]}, nil 107 } 108 109 // Set sets the topic list at the given index in the slice. 110 func (t *Topics) Set(index int, topics *Hashes) error { 111 if index < 0 || index >= len(t.topics) { 112 return errors.New("index out of bounds") 113 } 114 t.topics[index] = topics.hashes 115 return nil 116 } 117 118 // Append adds a new topic list to the end of the slice. 119 func (t *Topics) Append(topics *Hashes) { 120 t.topics = append(t.topics, topics.hashes) 121 } 122 123 // FilterQuery contains options for contact log filtering. 124 type FilterQuery struct { 125 query sberex.FilterQuery 126 } 127 128 // NewFilterQuery creates an empty filter query for contact log filtering. 129 func NewFilterQuery() *FilterQuery { 130 return new(FilterQuery) 131 } 132 133 func (fq *FilterQuery) GetFromBlock() *BigInt { return &BigInt{fq.query.FromBlock} } 134 func (fq *FilterQuery) GetToBlock() *BigInt { return &BigInt{fq.query.ToBlock} } 135 func (fq *FilterQuery) GetAddresses() *Addresses { return &Addresses{fq.query.Addresses} } 136 func (fq *FilterQuery) GetTopics() *Topics { return &Topics{fq.query.Topics} } 137 138 func (fq *FilterQuery) SetFromBlock(fromBlock *BigInt) { fq.query.FromBlock = fromBlock.bigint } 139 func (fq *FilterQuery) SetToBlock(toBlock *BigInt) { fq.query.ToBlock = toBlock.bigint } 140 func (fq *FilterQuery) SetAddresses(addresses *Addresses) { fq.query.Addresses = addresses.addresses } 141 func (fq *FilterQuery) SetTopics(topics *Topics) { fq.query.Topics = topics.topics }