diff --git a/interfaces.go b/interfaces.go index 67f236ef75..8eb655f807 100644 --- a/interfaces.go +++ b/interfaces.go @@ -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 diff --git a/mobile/common.go b/mobile/common.go index 047d8e1f65..35eaec129c 100644 --- a/mobile/common.go +++ b/mobile/common.go @@ -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 diff --git a/mobile/ethereum.go b/mobile/ethereum.go index c9bb3013c2..c433789554 100644 --- a/mobile/ethereum.go +++ b/mobile/ethereum.go @@ -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) }