ethereum.go 5.2 KB

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