aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-02 02:08:26 +0800
committerobscuren <geffobscura@gmail.com>2015-03-02 02:08:26 +0800
commit6e50a1e9f59532671eaa2bb2f2081a67f659bd0d (patch)
tree9dcb5fa46e7500f98e54458564a0409a2b77de80 /core
parentac88ae86a3f6fa5d5a957bac9d96e0a2027ac068 (diff)
downloadgo-tangerine-6e50a1e9f59532671eaa2bb2f2081a67f659bd0d.tar
go-tangerine-6e50a1e9f59532671eaa2bb2f2081a67f659bd0d.tar.gz
go-tangerine-6e50a1e9f59532671eaa2bb2f2081a67f659bd0d.tar.bz2
go-tangerine-6e50a1e9f59532671eaa2bb2f2081a67f659bd0d.tar.lz
go-tangerine-6e50a1e9f59532671eaa2bb2f2081a67f659bd0d.tar.xz
go-tangerine-6e50a1e9f59532671eaa2bb2f2081a67f659bd0d.tar.zst
go-tangerine-6e50a1e9f59532671eaa2bb2f2081a67f659bd0d.zip
Filter accepts multiple topics per entry. Fixes #403
Diffstat (limited to 'core')
-rw-r--r--core/filter.go35
1 files changed, 26 insertions, 9 deletions
diff --git a/core/filter.go b/core/filter.go
index cdf7b282d..c61c9e998 100644
--- a/core/filter.go
+++ b/core/filter.go
@@ -17,7 +17,7 @@ type FilterOptions struct {
Latest int64
Address [][]byte
- Topics [][]byte
+ Topics [][][]byte
Skip int
Max int
@@ -31,7 +31,7 @@ type Filter struct {
skip int
address [][]byte
max int
- topics [][]byte
+ topics [][][]byte
BlockCallback func(*types.Block)
PendingCallback func(*types.Block)
@@ -44,6 +44,8 @@ func NewFilter(eth Backend) *Filter {
return &Filter{eth: eth}
}
+// SetOptions copies the filter options to the filter it self. The reason for this "silly" copy
+// is simply because named arguments in this case is extremely nice and readable.
func (self *Filter) SetOptions(options FilterOptions) {
self.earliest = options.Earliest
self.latest = options.Latest
@@ -69,7 +71,7 @@ func (self *Filter) SetAddress(addr [][]byte) {
self.address = addr
}
-func (self *Filter) SetTopics(topics [][]byte) {
+func (self *Filter) SetTopics(topics [][][]byte) {
self.topics = topics
}
@@ -149,10 +151,18 @@ Logs:
continue
}
- max := int(math.Min(float64(len(self.topics)), float64(len(log.Topics()))))
- for i := 0; i < max; i++ {
- if !bytes.Equal(log.Topics()[i], self.topics[i]) {
- continue Logs
+ logTopics := make([][]byte, len(self.topics))
+ copy(logTopics, log.Topics())
+
+ for i, topics := range self.topics {
+ for _, topic := range topics {
+ var match bool
+ if bytes.Equal(log.Topics()[i], topic) {
+ match = true
+ }
+ if !match {
+ continue Logs
+ }
}
}
@@ -177,8 +187,15 @@ func (self *Filter) bloomFilter(block *types.Block) bool {
}
}
- for _, topic := range self.topics {
- if !types.BloomLookup(block.Bloom(), topic) {
+ for _, sub := range self.topics {
+ var included bool
+ for _, topic := range sub {
+ if types.BloomLookup(block.Bloom(), topic) {
+ included = true
+ break
+ }
+ }
+ if !included {
return false
}
}