github.com/ethxdao/go-ethereum@v0.0.0-20221218102228-5ae34a9cc189/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  
    24  	"github.com/ethxdao/go-ethereum/common"
    25  )
    26  
    27  // Subscription represents an event subscription where events are
    28  // delivered on a data channel.
    29  type Subscription struct {
    30  	sub ethereum.Subscription
    31  }
    32  
    33  // Unsubscribe cancels the sending of events to the data channel
    34  // and closes the error channel.
    35  func (s *Subscription) Unsubscribe() {
    36  	s.sub.Unsubscribe()
    37  }
    38  
    39  // CallMsg contains parameters for contract calls.
    40  type CallMsg struct {
    41  	msg ethereum.CallMsg
    42  }
    43  
    44  // NewCallMsg creates an empty contract call parameter list.
    45  func NewCallMsg() *CallMsg {
    46  	return new(CallMsg)
    47  }
    48  
    49  func (msg *CallMsg) GetFrom() *Address    { return &Address{msg.msg.From} }
    50  func (msg *CallMsg) GetGas() int64        { return int64(msg.msg.Gas) }
    51  func (msg *CallMsg) GetGasPrice() *BigInt { return &BigInt{msg.msg.GasPrice} }
    52  func (msg *CallMsg) GetValue() *BigInt    { return &BigInt{msg.msg.Value} }
    53  func (msg *CallMsg) GetData() []byte      { return msg.msg.Data }
    54  func (msg *CallMsg) GetTo() *Address {
    55  	if to := msg.msg.To; to != nil {
    56  		return &Address{*msg.msg.To}
    57  	}
    58  	return nil
    59  }
    60  
    61  func (msg *CallMsg) SetFrom(address *Address)  { msg.msg.From = address.address }
    62  func (msg *CallMsg) SetGas(gas int64)          { msg.msg.Gas = uint64(gas) }
    63  func (msg *CallMsg) SetGasPrice(price *BigInt) { msg.msg.GasPrice = price.bigint }
    64  func (msg *CallMsg) SetValue(value *BigInt)    { msg.msg.Value = value.bigint }
    65  func (msg *CallMsg) SetData(data []byte)       { msg.msg.Data = common.CopyBytes(data) }
    66  func (msg *CallMsg) SetTo(address *Address) {
    67  	if address == nil {
    68  		msg.msg.To = nil
    69  		return
    70  	}
    71  	msg.msg.To = &address.address
    72  }
    73  
    74  // SyncProgress gives progress indications when the node is synchronising with
    75  // the Ethereum network.
    76  type SyncProgress struct {
    77  	progress ethereum.SyncProgress
    78  }
    79  
    80  func (p *SyncProgress) GetStartingBlock() int64       { return int64(p.progress.StartingBlock) }
    81  func (p *SyncProgress) GetCurrentBlock() int64        { return int64(p.progress.CurrentBlock) }
    82  func (p *SyncProgress) GetHighestBlock() int64        { return int64(p.progress.HighestBlock) }
    83  func (p *SyncProgress) GetSyncedAccounts() int64      { return int64(p.progress.SyncedAccounts) }
    84  func (p *SyncProgress) GetSyncedAccountBytes() int64  { return int64(p.progress.SyncedAccountBytes) }
    85  func (p *SyncProgress) GetSyncedBytecodes() int64     { return int64(p.progress.SyncedBytecodes) }
    86  func (p *SyncProgress) GetSyncedBytecodeBytes() int64 { return int64(p.progress.SyncedBytecodeBytes) }
    87  func (p *SyncProgress) GetSyncedStorage() int64       { return int64(p.progress.SyncedStorage) }
    88  func (p *SyncProgress) GetSyncedStorageBytes() int64  { return int64(p.progress.SyncedStorageBytes) }
    89  func (p *SyncProgress) GetHealedTrienodes() int64     { return int64(p.progress.HealedTrienodes) }
    90  func (p *SyncProgress) GetHealedTrienodeBytes() int64 { return int64(p.progress.HealedTrienodeBytes) }
    91  func (p *SyncProgress) GetHealedBytecodes() int64     { return int64(p.progress.HealedBytecodes) }
    92  func (p *SyncProgress) GetHealedBytecodeBytes() int64 { return int64(p.progress.HealedBytecodeBytes) }
    93  func (p *SyncProgress) GetHealingTrienodes() int64    { return int64(p.progress.HealingTrienodes) }
    94  func (p *SyncProgress) GetHealingBytecode() int64     { return int64(p.progress.HealingBytecode) }
    95  
    96  // Topics is a set of topic lists to filter events with.
    97  type Topics struct{ topics [][]common.Hash }
    98  
    99  // NewTopics creates a slice of uninitialized Topics.
   100  func NewTopics(size int) *Topics {
   101  	return &Topics{
   102  		topics: make([][]common.Hash, size),
   103  	}
   104  }
   105  
   106  // NewTopicsEmpty creates an empty slice of Topics values.
   107  func NewTopicsEmpty() *Topics {
   108  	return NewTopics(0)
   109  }
   110  
   111  // Size returns the number of topic lists inside the set
   112  func (t *Topics) Size() int {
   113  	return len(t.topics)
   114  }
   115  
   116  // Get returns the topic list at the given index from the slice.
   117  func (t *Topics) Get(index int) (hashes *Hashes, _ error) {
   118  	if index < 0 || index >= len(t.topics) {
   119  		return nil, errors.New("index out of bounds")
   120  	}
   121  	return &Hashes{t.topics[index]}, nil
   122  }
   123  
   124  // Set sets the topic list at the given index in the slice.
   125  func (t *Topics) Set(index int, topics *Hashes) error {
   126  	if index < 0 || index >= len(t.topics) {
   127  		return errors.New("index out of bounds")
   128  	}
   129  	t.topics[index] = topics.hashes
   130  	return nil
   131  }
   132  
   133  // Append adds a new topic list to the end of the slice.
   134  func (t *Topics) Append(topics *Hashes) {
   135  	t.topics = append(t.topics, topics.hashes)
   136  }
   137  
   138  // FilterQuery contains options for contract log filtering.
   139  type FilterQuery struct {
   140  	query ethereum.FilterQuery
   141  }
   142  
   143  // NewFilterQuery creates an empty filter query for contract log filtering.
   144  func NewFilterQuery() *FilterQuery {
   145  	return new(FilterQuery)
   146  }
   147  
   148  func (fq *FilterQuery) GetFromBlock() *BigInt    { return &BigInt{fq.query.FromBlock} }
   149  func (fq *FilterQuery) GetToBlock() *BigInt      { return &BigInt{fq.query.ToBlock} }
   150  func (fq *FilterQuery) GetAddresses() *Addresses { return &Addresses{fq.query.Addresses} }
   151  func (fq *FilterQuery) GetTopics() *Topics       { return &Topics{fq.query.Topics} }
   152  
   153  func (fq *FilterQuery) SetFromBlock(fromBlock *BigInt)    { fq.query.FromBlock = fromBlock.bigint }
   154  func (fq *FilterQuery) SetToBlock(toBlock *BigInt)        { fq.query.ToBlock = toBlock.bigint }
   155  func (fq *FilterQuery) SetAddresses(addresses *Addresses) { fq.query.Addresses = addresses.addresses }
   156  func (fq *FilterQuery) SetTopics(topics *Topics)          { fq.query.Topics = topics.topics }