github.com/murrekatt/go-ethereum@v1.5.8-0.20170123175102-fc52f2c007fb/mobile/ethereum.go (about)

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