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