2016-09-05 11:07:57 -05:00
|
|
|
// Copyright 2016 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// Contains all the wrappers from the go-ethereum root package.
|
|
|
|
|
|
|
|
package geth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2020-11-25 14:00:23 -06:00
|
|
|
"github.com/ethereum/go-ethereum"
|
2016-09-05 11:07:57 -05:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Subscription represents an event subscription where events are
|
|
|
|
// delivered on a data channel.
|
|
|
|
type Subscription struct {
|
|
|
|
sub ethereum.Subscription
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unsubscribe cancels the sending of events to the data channel
|
|
|
|
// and closes the error channel.
|
|
|
|
func (s *Subscription) Unsubscribe() {
|
|
|
|
s.sub.Unsubscribe()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CallMsg contains parameters for contract calls.
|
|
|
|
type CallMsg struct {
|
|
|
|
msg ethereum.CallMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewCallMsg creates an empty contract call parameter list.
|
|
|
|
func NewCallMsg() *CallMsg {
|
|
|
|
return new(CallMsg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *CallMsg) GetFrom() *Address { return &Address{msg.msg.From} }
|
2017-11-13 05:47:27 -06:00
|
|
|
func (msg *CallMsg) GetGas() int64 { return int64(msg.msg.Gas) }
|
2016-09-05 11:07:57 -05:00
|
|
|
func (msg *CallMsg) GetGasPrice() *BigInt { return &BigInt{msg.msg.GasPrice} }
|
|
|
|
func (msg *CallMsg) GetValue() *BigInt { return &BigInt{msg.msg.Value} }
|
|
|
|
func (msg *CallMsg) GetData() []byte { return msg.msg.Data }
|
|
|
|
func (msg *CallMsg) GetTo() *Address {
|
|
|
|
if to := msg.msg.To; to != nil {
|
|
|
|
return &Address{*msg.msg.To}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *CallMsg) SetFrom(address *Address) { msg.msg.From = address.address }
|
2017-11-13 05:47:27 -06:00
|
|
|
func (msg *CallMsg) SetGas(gas int64) { msg.msg.Gas = uint64(gas) }
|
2016-09-05 11:07:57 -05:00
|
|
|
func (msg *CallMsg) SetGasPrice(price *BigInt) { msg.msg.GasPrice = price.bigint }
|
|
|
|
func (msg *CallMsg) SetValue(value *BigInt) { msg.msg.Value = value.bigint }
|
2017-07-17 07:25:46 -05:00
|
|
|
func (msg *CallMsg) SetData(data []byte) { msg.msg.Data = common.CopyBytes(data) }
|
2016-09-05 11:07:57 -05:00
|
|
|
func (msg *CallMsg) SetTo(address *Address) {
|
|
|
|
if address == nil {
|
|
|
|
msg.msg.To = nil
|
2018-08-03 00:42:31 -05:00
|
|
|
return
|
2016-09-05 11:07:57 -05:00
|
|
|
}
|
|
|
|
msg.msg.To = &address.address
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyncProgress gives progress indications when the node is synchronising with
|
|
|
|
// the Ethereum network.
|
|
|
|
type SyncProgress struct {
|
|
|
|
progress ethereum.SyncProgress
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *SyncProgress) GetStartingBlock() int64 { return int64(p.progress.StartingBlock) }
|
|
|
|
func (p *SyncProgress) GetCurrentBlock() int64 { return int64(p.progress.CurrentBlock) }
|
|
|
|
func (p *SyncProgress) GetHighestBlock() int64 { return int64(p.progress.HighestBlock) }
|
|
|
|
func (p *SyncProgress) GetPulledStates() int64 { return int64(p.progress.PulledStates) }
|
|
|
|
func (p *SyncProgress) GetKnownStates() int64 { return int64(p.progress.KnownStates) }
|
|
|
|
|
|
|
|
// Topics is a set of topic lists to filter events with.
|
|
|
|
type Topics struct{ topics [][]common.Hash }
|
|
|
|
|
2017-05-23 04:16:25 -05:00
|
|
|
// NewTopics creates a slice of uninitialized Topics.
|
|
|
|
func NewTopics(size int) *Topics {
|
|
|
|
return &Topics{
|
|
|
|
topics: make([][]common.Hash, size),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTopicsEmpty creates an empty slice of Topics values.
|
|
|
|
func NewTopicsEmpty() *Topics {
|
|
|
|
return NewTopics(0)
|
|
|
|
}
|
|
|
|
|
2016-09-05 11:07:57 -05:00
|
|
|
// Size returns the number of topic lists inside the set
|
|
|
|
func (t *Topics) Size() int {
|
|
|
|
return len(t.topics)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get returns the topic list at the given index from the slice.
|
2016-12-08 06:09:26 -06:00
|
|
|
func (t *Topics) Get(index int) (hashes *Hashes, _ error) {
|
2016-09-05 11:07:57 -05:00
|
|
|
if index < 0 || index >= len(t.topics) {
|
|
|
|
return nil, errors.New("index out of bounds")
|
|
|
|
}
|
|
|
|
return &Hashes{t.topics[index]}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set sets the topic list at the given index in the slice.
|
|
|
|
func (t *Topics) Set(index int, topics *Hashes) error {
|
|
|
|
if index < 0 || index >= len(t.topics) {
|
|
|
|
return errors.New("index out of bounds")
|
|
|
|
}
|
|
|
|
t.topics[index] = topics.hashes
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-05-23 04:16:25 -05:00
|
|
|
// Append adds a new topic list to the end of the slice.
|
|
|
|
func (t *Topics) Append(topics *Hashes) {
|
|
|
|
t.topics = append(t.topics, topics.hashes)
|
|
|
|
}
|
|
|
|
|
2018-06-21 02:35:35 -05:00
|
|
|
// FilterQuery contains options for contract log filtering.
|
2016-09-05 11:07:57 -05:00
|
|
|
type FilterQuery struct {
|
|
|
|
query ethereum.FilterQuery
|
|
|
|
}
|
|
|
|
|
2018-06-21 02:35:35 -05:00
|
|
|
// NewFilterQuery creates an empty filter query for contract log filtering.
|
2016-09-05 11:07:57 -05:00
|
|
|
func NewFilterQuery() *FilterQuery {
|
|
|
|
return new(FilterQuery)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fq *FilterQuery) GetFromBlock() *BigInt { return &BigInt{fq.query.FromBlock} }
|
|
|
|
func (fq *FilterQuery) GetToBlock() *BigInt { return &BigInt{fq.query.ToBlock} }
|
|
|
|
func (fq *FilterQuery) GetAddresses() *Addresses { return &Addresses{fq.query.Addresses} }
|
|
|
|
func (fq *FilterQuery) GetTopics() *Topics { return &Topics{fq.query.Topics} }
|
2017-05-22 10:12:36 -05:00
|
|
|
|
|
|
|
func (fq *FilterQuery) SetFromBlock(fromBlock *BigInt) { fq.query.FromBlock = fromBlock.bigint }
|
|
|
|
func (fq *FilterQuery) SetToBlock(toBlock *BigInt) { fq.query.ToBlock = toBlock.bigint }
|
|
|
|
func (fq *FilterQuery) SetAddresses(addresses *Addresses) { fq.query.Addresses = addresses.addresses }
|
|
|
|
func (fq *FilterQuery) SetTopics(topics *Topics) { fq.query.Topics = topics.topics }
|