github.com/aigarnetwork/aigar@v0.0.0-20191115204914-d59a6eb70f8e/mobile/ethereum.go (about)

     1  //  Copyright 2018 The go-ethereum Authors
     2  //  Copyright 2019 The go-aigar Authors
     3  //  This file is part of the go-aigar library.
     4  //
     5  //  The go-aigar library is free software: you can redistribute it and/or modify
     6  //  it under the terms of the GNU Lesser General Public License as published by
     7  //  the Free Software Foundation, either version 3 of the License, or
     8  //  (at your option) any later version.
     9  //
    10  //  The go-aigar library is distributed in the hope that it will be useful,
    11  //  but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  //  GNU Lesser General Public License for more details.
    14  //
    15  //  You should have received a copy of the GNU Lesser General Public License
    16  //  along with the go-aigar library. If not, see <http://www.gnu.org/licenses/>.
    17  
    18  // Contains all the wrappers from the go-ethereum root package.
    19  
    20  package geth
    21  
    22  import (
    23  	"errors"
    24  
    25  	ethereum "github.com/AigarNetwork/aigar"
    26  	"github.com/AigarNetwork/aigar/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 int64(msg.msg.Gas) }
    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 = uint64(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 = common.CopyBytes(data) }
    68  func (msg *CallMsg) SetTo(address *Address) {
    69  	if address == nil {
    70  		msg.msg.To = nil
    71  		return
    72  	}
    73  	msg.msg.To = &address.address
    74  }
    75  
    76  // SyncProgress gives progress indications when the node is synchronising with
    77  // the Ethereum network.
    78  type SyncProgress struct {
    79  	progress ethereum.SyncProgress
    80  }
    81  
    82  func (p *SyncProgress) GetStartingBlock() int64 { return int64(p.progress.StartingBlock) }
    83  func (p *SyncProgress) GetCurrentBlock() int64  { return int64(p.progress.CurrentBlock) }
    84  func (p *SyncProgress) GetHighestBlock() int64  { return int64(p.progress.HighestBlock) }
    85  func (p *SyncProgress) GetPulledStates() int64  { return int64(p.progress.PulledStates) }
    86  func (p *SyncProgress) GetKnownStates() int64   { return int64(p.progress.KnownStates) }
    87  
    88  // Topics is a set of topic lists to filter events with.
    89  type Topics struct{ topics [][]common.Hash }
    90  
    91  // NewTopics creates a slice of uninitialized Topics.
    92  func NewTopics(size int) *Topics {
    93  	return &Topics{
    94  		topics: make([][]common.Hash, size),
    95  	}
    96  }
    97  
    98  // NewTopicsEmpty creates an empty slice of Topics values.
    99  func NewTopicsEmpty() *Topics {
   100  	return NewTopics(0)
   101  }
   102  
   103  // Size returns the number of topic lists inside the set
   104  func (t *Topics) Size() int {
   105  	return len(t.topics)
   106  }
   107  
   108  // Get returns the topic list at the given index from the slice.
   109  func (t *Topics) Get(index int) (hashes *Hashes, _ error) {
   110  	if index < 0 || index >= len(t.topics) {
   111  		return nil, errors.New("index out of bounds")
   112  	}
   113  	return &Hashes{t.topics[index]}, nil
   114  }
   115  
   116  // Set sets the topic list at the given index in the slice.
   117  func (t *Topics) Set(index int, topics *Hashes) error {
   118  	if index < 0 || index >= len(t.topics) {
   119  		return errors.New("index out of bounds")
   120  	}
   121  	t.topics[index] = topics.hashes
   122  	return nil
   123  }
   124  
   125  // Append adds a new topic list to the end of the slice.
   126  func (t *Topics) Append(topics *Hashes) {
   127  	t.topics = append(t.topics, topics.hashes)
   128  }
   129  
   130  // FilterQuery contains options for contract log filtering.
   131  type FilterQuery struct {
   132  	query ethereum.FilterQuery
   133  }
   134  
   135  // NewFilterQuery creates an empty filter query for contract log filtering.
   136  func NewFilterQuery() *FilterQuery {
   137  	return new(FilterQuery)
   138  }
   139  
   140  func (fq *FilterQuery) GetFromBlock() *BigInt    { return &BigInt{fq.query.FromBlock} }
   141  func (fq *FilterQuery) GetToBlock() *BigInt      { return &BigInt{fq.query.ToBlock} }
   142  func (fq *FilterQuery) GetAddresses() *Addresses { return &Addresses{fq.query.Addresses} }
   143  func (fq *FilterQuery) GetTopics() *Topics       { return &Topics{fq.query.Topics} }
   144  
   145  func (fq *FilterQuery) SetFromBlock(fromBlock *BigInt)    { fq.query.FromBlock = fromBlock.bigint }
   146  func (fq *FilterQuery) SetToBlock(toBlock *BigInt)        { fq.query.ToBlock = toBlock.bigint }
   147  func (fq *FilterQuery) SetAddresses(addresses *Addresses) { fq.query.Addresses = addresses.addresses }
   148  func (fq *FilterQuery) SetTopics(topics *Topics)          { fq.query.Topics = topics.topics }