aboutsummaryrefslogtreecommitdiffstats
path: root/mobile/ethereum.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-09-06 00:07:57 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-11-14 23:56:58 +0800
commit178da7c6a94718389e7192d87df5ee42e7223bc3 (patch)
tree010f49656b5d1656cf24a4ff9bac35788dd9959f /mobile/ethereum.go
parentd89ea3e6f90c32a97bad58b82a15af0d81f4250e (diff)
downloaddexon-178da7c6a94718389e7192d87df5ee42e7223bc3.tar
dexon-178da7c6a94718389e7192d87df5ee42e7223bc3.tar.gz
dexon-178da7c6a94718389e7192d87df5ee42e7223bc3.tar.bz2
dexon-178da7c6a94718389e7192d87df5ee42e7223bc3.tar.lz
dexon-178da7c6a94718389e7192d87df5ee42e7223bc3.tar.xz
dexon-178da7c6a94718389e7192d87df5ee42e7223bc3.tar.zst
dexon-178da7c6a94718389e7192d87df5ee42e7223bc3.zip
mobile: initial wrappers for mobile support
Diffstat (limited to 'mobile/ethereum.go')
-rw-r--r--mobile/ethereum.go125
1 files changed, 125 insertions, 0 deletions
diff --git a/mobile/ethereum.go b/mobile/ethereum.go
new file mode 100644
index 000000000..6e8046ac9
--- /dev/null
+++ b/mobile/ethereum.go
@@ -0,0 +1,125 @@
+// Copyright 2016 The go-ethereum Authors
+// This file is part of the go-ethereum library.
+//
+// The go-ethereum library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The go-ethereum library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
+
+// Contains all the wrappers from the go-ethereum root package.
+
+package geth
+
+import (
+ "errors"
+ "math/big"
+
+ ethereum "github.com/ethereum/go-ethereum"
+ "github.com/ethereum/go-ethereum/common"
+)
+
+// Subscription represents an event subscription where events are
+// delivered on a data channel.
+type Subscription struct {
+ sub ethereum.Subscription
+}
+
+// Unsubscribe cancels the sending of events to the data channel
+// and closes the error channel.
+func (s *Subscription) Unsubscribe() {
+ s.sub.Unsubscribe()
+}
+
+// CallMsg contains parameters for contract calls.
+type CallMsg struct {
+ msg ethereum.CallMsg
+}
+
+// NewCallMsg creates an empty contract call parameter list.
+func NewCallMsg() *CallMsg {
+ return new(CallMsg)
+}
+
+func (msg *CallMsg) GetFrom() *Address { return &Address{msg.msg.From} }
+func (msg *CallMsg) GetGas() int64 { return msg.msg.Gas.Int64() }
+func (msg *CallMsg) GetGasPrice() *BigInt { return &BigInt{msg.msg.GasPrice} }
+func (msg *CallMsg) GetValue() *BigInt { return &BigInt{msg.msg.Value} }
+func (msg *CallMsg) GetData() []byte { return msg.msg.Data }
+func (msg *CallMsg) GetTo() *Address {
+ if to := msg.msg.To; to != nil {
+ return &Address{*msg.msg.To}
+ }
+ return nil
+}
+
+func (msg *CallMsg) SetFrom(address *Address) { msg.msg.From = address.address }
+func (msg *CallMsg) SetGas(gas int64) { msg.msg.Gas = big.NewInt(gas) }
+func (msg *CallMsg) SetGasPrice(price *BigInt) { msg.msg.GasPrice = price.bigint }
+func (msg *CallMsg) SetValue(value *BigInt) { msg.msg.Value = value.bigint }
+func (msg *CallMsg) SetData(data []byte) { msg.msg.Data = data }
+func (msg *CallMsg) SetTo(address *Address) {
+ if address == nil {
+ msg.msg.To = nil
+ }
+ msg.msg.To = &address.address
+}
+
+// SyncProgress gives progress indications when the node is synchronising with
+// the Ethereum network.
+type SyncProgress struct {
+ progress ethereum.SyncProgress
+}
+
+func (p *SyncProgress) GetStartingBlock() int64 { return int64(p.progress.StartingBlock) }
+func (p *SyncProgress) GetCurrentBlock() int64 { return int64(p.progress.CurrentBlock) }
+func (p *SyncProgress) GetHighestBlock() int64 { return int64(p.progress.HighestBlock) }
+func (p *SyncProgress) GetPulledStates() int64 { return int64(p.progress.PulledStates) }
+func (p *SyncProgress) GetKnownStates() int64 { return int64(p.progress.KnownStates) }
+
+// Topics is a set of topic lists to filter events with.
+type Topics struct{ topics [][]common.Hash }
+
+// Size returns the number of topic lists inside the set
+func (t *Topics) Size() int {
+ return len(t.topics)
+}
+
+// Get returns the topic list at the given index from the slice.
+func (t *Topics) Get(index int) (*Hashes, error) {
+ if index < 0 || index >= len(t.topics) {
+ return nil, errors.New("index out of bounds")
+ }
+ return &Hashes{t.topics[index]}, nil
+}
+
+// Set sets the topic list at the given index in the slice.
+func (t *Topics) Set(index int, topics *Hashes) error {
+ if index < 0 || index >= len(t.topics) {
+ return errors.New("index out of bounds")
+ }
+ t.topics[index] = topics.hashes
+ return nil
+}
+
+// FilterQuery contains options for contact log filtering.
+type FilterQuery struct {
+ query ethereum.FilterQuery
+}
+
+// NewFilterQuery creates an empty filter query for contact log filtering.
+func NewFilterQuery() *FilterQuery {
+ return new(FilterQuery)
+}
+
+func (fq *FilterQuery) GetFromBlock() *BigInt { return &BigInt{fq.query.FromBlock} }
+func (fq *FilterQuery) GetToBlock() *BigInt { return &BigInt{fq.query.ToBlock} }
+func (fq *FilterQuery) GetAddresses() *Addresses { return &Addresses{fq.query.Addresses} }
+func (fq *FilterQuery) GetTopics() *Topics { return &Topics{fq.query.Topics} }