github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/mobile/ethereum.go (about)

     1  // Contains all the wrappers from the quickchain root package.
     2  
     3  package geth
     4  
     5  import (
     6  	"errors"
     7  
     8  	quickchain "github.com/quickchainproject/quickchain"
     9  	"github.com/quickchainproject/quickchain/common"
    10  )
    11  
    12  // Subscription represents an event subscription where events are
    13  // delivered on a data channel.
    14  type Subscription struct {
    15  	sub quickchain.Subscription
    16  }
    17  
    18  // Unsubscribe cancels the sending of events to the data channel
    19  // and closes the error channel.
    20  func (s *Subscription) Unsubscribe() {
    21  	s.sub.Unsubscribe()
    22  }
    23  
    24  // CallMsg contains parameters for contract calls.
    25  type CallMsg struct {
    26  	msg quickchain.CallMsg
    27  }
    28  
    29  // NewCallMsg creates an empty contract call parameter list.
    30  func NewCallMsg() *CallMsg {
    31  	return new(CallMsg)
    32  }
    33  
    34  func (msg *CallMsg) GetFrom() *Address    { return &Address{msg.msg.From} }
    35  func (msg *CallMsg) GetGas() int64        { return int64(msg.msg.Gas) }
    36  func (msg *CallMsg) GetGasPrice() *BigInt { return &BigInt{msg.msg.GasPrice} }
    37  func (msg *CallMsg) GetValue() *BigInt    { return &BigInt{msg.msg.Value} }
    38  func (msg *CallMsg) GetData() []byte      { return msg.msg.Data }
    39  func (msg *CallMsg) GetTo() *Address {
    40  	if to := msg.msg.To; to != nil {
    41  		return &Address{*msg.msg.To}
    42  	}
    43  	return nil
    44  }
    45  
    46  func (msg *CallMsg) SetFrom(address *Address)  { msg.msg.From = address.address }
    47  func (msg *CallMsg) SetGas(gas int64)          { msg.msg.Gas = uint64(gas) }
    48  func (msg *CallMsg) SetGasPrice(price *BigInt) { msg.msg.GasPrice = price.bigint }
    49  func (msg *CallMsg) SetValue(value *BigInt)    { msg.msg.Value = value.bigint }
    50  func (msg *CallMsg) SetData(data []byte)       { msg.msg.Data = common.CopyBytes(data) }
    51  func (msg *CallMsg) SetTo(address *Address) {
    52  	if address == nil {
    53  		msg.msg.To = nil
    54  	}
    55  	msg.msg.To = &address.address
    56  }
    57  
    58  // SyncProgress gives progress indications when the node is synchronising with
    59  // the quickchain network.
    60  type SyncProgress struct {
    61  	progress quickchain.SyncProgress
    62  }
    63  
    64  func (p *SyncProgress) GetStartingBlock() int64 { return int64(p.progress.StartingBlock) }
    65  func (p *SyncProgress) GetCurrentBlock() int64  { return int64(p.progress.CurrentBlock) }
    66  func (p *SyncProgress) GetHighestBlock() int64  { return int64(p.progress.HighestBlock) }
    67  func (p *SyncProgress) GetPulledStates() int64  { return int64(p.progress.PulledStates) }
    68  func (p *SyncProgress) GetKnownStates() int64   { return int64(p.progress.KnownStates) }
    69  
    70  // Topics is a set of topic lists to filter events with.
    71  type Topics struct{ topics [][]common.Hash }
    72  
    73  // NewTopics creates a slice of uninitialized Topics.
    74  func NewTopics(size int) *Topics {
    75  	return &Topics{
    76  		topics: make([][]common.Hash, size),
    77  	}
    78  }
    79  
    80  // NewTopicsEmpty creates an empty slice of Topics values.
    81  func NewTopicsEmpty() *Topics {
    82  	return NewTopics(0)
    83  }
    84  
    85  // Size returns the number of topic lists inside the set
    86  func (t *Topics) Size() int {
    87  	return len(t.topics)
    88  }
    89  
    90  // Get returns the topic list at the given index from the slice.
    91  func (t *Topics) Get(index int) (hashes *Hashes, _ error) {
    92  	if index < 0 || index >= len(t.topics) {
    93  		return nil, errors.New("index out of bounds")
    94  	}
    95  	return &Hashes{t.topics[index]}, nil
    96  }
    97  
    98  // Set sets the topic list at the given index in the slice.
    99  func (t *Topics) Set(index int, topics *Hashes) error {
   100  	if index < 0 || index >= len(t.topics) {
   101  		return errors.New("index out of bounds")
   102  	}
   103  	t.topics[index] = topics.hashes
   104  	return nil
   105  }
   106  
   107  // Append adds a new topic list to the end of the slice.
   108  func (t *Topics) Append(topics *Hashes) {
   109  	t.topics = append(t.topics, topics.hashes)
   110  }
   111  
   112  // FilterQuery contains options for contact log filtering.
   113  type FilterQuery struct {
   114  	query quickchain.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} }
   126  
   127  func (fq *FilterQuery) SetFromBlock(fromBlock *BigInt)    { fq.query.FromBlock = fromBlock.bigint }
   128  func (fq *FilterQuery) SetToBlock(toBlock *BigInt)        { fq.query.ToBlock = toBlock.bigint }
   129  func (fq *FilterQuery) SetAddresses(addresses *Addresses) { fq.query.Addresses = addresses.addresses }
   130  func (fq *FilterQuery) SetTopics(topics *Topics)          { fq.query.Topics = topics.topics }