mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
ethereum, mobile: nullable topics for filter criteria
This commit is contained in:
parent
4094fd874d
commit
0773893f4b
3 changed files with 62 additions and 7 deletions
|
|
@ -146,7 +146,7 @@ type FilterQuery struct {
|
|||
// {{}, {B}} matches any topic in first position, B in second position
|
||||
// {{A}}, {B}} matches topic A in first position, B in second position
|
||||
// {{A, B}}, {C, D}} matches topic (A OR B) in first position, (C OR D) in second position
|
||||
Topics [][]common.Hash
|
||||
Topics [][]*common.Hash
|
||||
}
|
||||
|
||||
// LogFilterer provides access to contract log events using a one-off query or continuous
|
||||
|
|
|
|||
|
|
@ -128,6 +128,61 @@ func (h *Hashes) Append(hash *Hash) {
|
|||
h.hashes = append(h.hashes, hash.hash)
|
||||
}
|
||||
|
||||
// NullableHashes represents a slice of hashes that can have the null value too.
|
||||
type NullableHashes struct{ hashes []*common.Hash }
|
||||
|
||||
// NewNullableHashes creates a slice of uninitialized NullableHashes.
|
||||
func NewNullableHashes(size int) *NullableHashes {
|
||||
return &NullableHashes{
|
||||
hashes: make([]*common.Hash, size),
|
||||
}
|
||||
}
|
||||
|
||||
// NewNullableHashesEmpty creates an empty slice of NullableHashes values.
|
||||
func NewNullableHashesEmpty() *NullableHashes {
|
||||
return NewNullableHashes(0)
|
||||
}
|
||||
|
||||
// Size returns the number of hashes in the slice.
|
||||
func (h *NullableHashes) Size() int {
|
||||
return len(h.hashes)
|
||||
}
|
||||
|
||||
// Get returns the hash at the given index from the slice.
|
||||
func (h *NullableHashes) Get(index int) (hash *Hash, _ error) {
|
||||
if index < 0 || index >= len(h.hashes) {
|
||||
return nil, errors.New("index out of bounds")
|
||||
}
|
||||
if h.hashes[index] == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return &Hash{*h.hashes[index]}, nil
|
||||
}
|
||||
|
||||
// Set sets the Hash at the given index in the slice.
|
||||
func (h *NullableHashes) Set(index int, hash *Hash) error {
|
||||
if index < 0 || index >= len(h.hashes) {
|
||||
return errors.New("index out of bounds")
|
||||
}
|
||||
if hash == nil {
|
||||
h.hashes[index] = nil
|
||||
return nil
|
||||
}
|
||||
copy := hash.hash
|
||||
h.hashes[index] = ©
|
||||
return nil
|
||||
}
|
||||
|
||||
// Append adds a new Hash element to the end of the slice.
|
||||
func (h *NullableHashes) Append(hash *Hash) {
|
||||
if hash == nil {
|
||||
h.hashes = append(h.hashes, nil)
|
||||
return
|
||||
}
|
||||
copy := hash.hash
|
||||
h.hashes = append(h.hashes, ©)
|
||||
}
|
||||
|
||||
// Address represents the 20 byte address of an Ethereum account.
|
||||
type Address struct {
|
||||
address common.Address
|
||||
|
|
|
|||
|
|
@ -85,12 +85,12 @@ func (p *SyncProgress) GetPulledStates() int64 { return int64(p.progress.Pulled
|
|||
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 }
|
||||
type Topics struct{ topics [][]*common.Hash }
|
||||
|
||||
// NewTopics creates a slice of uninitialized Topics.
|
||||
func NewTopics(size int) *Topics {
|
||||
return &Topics{
|
||||
topics: make([][]common.Hash, size),
|
||||
topics: make([][]*common.Hash, size),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,15 +105,15 @@ func (t *Topics) Size() int {
|
|||
}
|
||||
|
||||
// Get returns the topic list at the given index from the slice.
|
||||
func (t *Topics) Get(index int) (hashes *Hashes, _ error) {
|
||||
func (t *Topics) Get(index int) (hashes *NullableHashes, _ error) {
|
||||
if index < 0 || index >= len(t.topics) {
|
||||
return nil, errors.New("index out of bounds")
|
||||
}
|
||||
return &Hashes{t.topics[index]}, nil
|
||||
return &NullableHashes{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 {
|
||||
func (t *Topics) Set(index int, topics *NullableHashes) error {
|
||||
if index < 0 || index >= len(t.topics) {
|
||||
return errors.New("index out of bounds")
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ func (t *Topics) Set(index int, topics *Hashes) error {
|
|||
}
|
||||
|
||||
// Append adds a new topic list to the end of the slice.
|
||||
func (t *Topics) Append(topics *Hashes) {
|
||||
func (t *Topics) Append(topics *NullableHashes) {
|
||||
t.topics = append(t.topics, topics.hashes)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue