Skip to content

Commit 3556962

Browse files
authored
Merge pull request #14501 from sqli-nantes/master
mobile: manage FilterQuery enabling contract events subscription
2 parents 2a41e76 + 30cc1c3 commit 3556962

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

mobile/common.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ func (h *Hash) GetHex() string {
8989
// Hashes represents a slice of hashes.
9090
type Hashes struct{ hashes []common.Hash }
9191

92+
// NewHashes creates a slice of uninitialized Hashes.
93+
func NewHashes(size int) *Hashes {
94+
return &Hashes{
95+
hashes: make([]common.Hash, size),
96+
}
97+
}
98+
99+
// NewHashesEmpty creates an empty slice of Hashes values.
100+
func NewHashesEmpty() *Hashes {
101+
return NewHashes(0)
102+
}
103+
92104
// Size returns the number of hashes in the slice.
93105
func (h *Hashes) Size() int {
94106
return len(h.hashes)
@@ -102,6 +114,20 @@ func (h *Hashes) Get(index int) (hash *Hash, _ error) {
102114
return &Hash{h.hashes[index]}, nil
103115
}
104116

117+
// Set sets the Hash at the given index in the slice.
118+
func (h *Hashes) Set(index int, hash *Hash) error {
119+
if index < 0 || index >= len(h.hashes) {
120+
return errors.New("index out of bounds")
121+
}
122+
h.hashes[index] = hash.hash
123+
return nil
124+
}
125+
126+
// Append adds a new Hash element to the end of the slice.
127+
func (h *Hashes) Append(hash *Hash) {
128+
h.hashes = append(h.hashes, hash.hash)
129+
}
130+
105131
// Address represents the 20 byte address of an Ethereum account.
106132
type Address struct {
107133
address common.Address
@@ -164,6 +190,18 @@ func (a *Address) GetHex() string {
164190
// Addresses represents a slice of addresses.
165191
type Addresses struct{ addresses []common.Address }
166192

193+
// NewAddresses creates a slice of uninitialized addresses.
194+
func NewAddresses(size int) *Addresses {
195+
return &Addresses{
196+
addresses: make([]common.Address, size),
197+
}
198+
}
199+
200+
// NewAddressesEmpty creates an empty slice of Addresses values.
201+
func NewAddressesEmpty() *Addresses {
202+
return NewAddresses(0)
203+
}
204+
167205
// Size returns the number of addresses in the slice.
168206
func (a *Addresses) Size() int {
169207
return len(a.addresses)
@@ -185,3 +223,8 @@ func (a *Addresses) Set(index int, address *Address) error {
185223
a.addresses[index] = address.address
186224
return nil
187225
}
226+
227+
// Append adds a new address element to the end of the slice.
228+
func (a *Addresses) Append(address *Address) {
229+
a.addresses = append(a.addresses, address.address)
230+
}

mobile/ethereum.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ func (p *SyncProgress) GetKnownStates() int64 { return int64(p.progress.KnownS
8787
// Topics is a set of topic lists to filter events with.
8888
type Topics struct{ topics [][]common.Hash }
8989

90+
// NewTopics creates a slice of uninitialized Topics.
91+
func NewTopics(size int) *Topics {
92+
return &Topics{
93+
topics: make([][]common.Hash, size),
94+
}
95+
}
96+
97+
// NewTopicsEmpty creates an empty slice of Topics values.
98+
func NewTopicsEmpty() *Topics {
99+
return NewTopics(0)
100+
}
101+
90102
// Size returns the number of topic lists inside the set
91103
func (t *Topics) Size() int {
92104
return len(t.topics)
@@ -109,6 +121,11 @@ func (t *Topics) Set(index int, topics *Hashes) error {
109121
return nil
110122
}
111123

124+
// Append adds a new topic list to the end of the slice.
125+
func (t *Topics) Append(topics *Hashes) {
126+
t.topics = append(t.topics, topics.hashes)
127+
}
128+
112129
// FilterQuery contains options for contact log filtering.
113130
type FilterQuery struct {
114131
query ethereum.FilterQuery
@@ -123,3 +140,8 @@ func (fq *FilterQuery) GetFromBlock() *BigInt { return &BigInt{fq.query.FromB
123140
func (fq *FilterQuery) GetToBlock() *BigInt { return &BigInt{fq.query.ToBlock} }
124141
func (fq *FilterQuery) GetAddresses() *Addresses { return &Addresses{fq.query.Addresses} }
125142
func (fq *FilterQuery) GetTopics() *Topics { return &Topics{fq.query.Topics} }
143+
144+
func (fq *FilterQuery) SetFromBlock(fromBlock *BigInt) { fq.query.FromBlock = fromBlock.bigint }
145+
func (fq *FilterQuery) SetToBlock(toBlock *BigInt) { fq.query.ToBlock = toBlock.bigint }
146+
func (fq *FilterQuery) SetAddresses(addresses *Addresses) { fq.query.Addresses = addresses.addresses }
147+
func (fq *FilterQuery) SetTopics(topics *Topics) { fq.query.Topics = topics.topics }

0 commit comments

Comments
 (0)