aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-08-14 23:02:39 +0800
committerobscuren <geffobscura@gmail.com>2014-08-14 23:02:39 +0800
commit07cfb7b64ac7932a4ff8c2480452114b84b421a6 (patch)
treebf017a7f76811593e3691c9ad3a0ecca2a0f5c16
parent0d733aa07197c8adbbaa92a12a4ad32e86676cc7 (diff)
downloaddexon-07cfb7b64ac7932a4ff8c2480452114b84b421a6.tar
dexon-07cfb7b64ac7932a4ff8c2480452114b84b421a6.tar.gz
dexon-07cfb7b64ac7932a4ff8c2480452114b84b421a6.tar.bz2
dexon-07cfb7b64ac7932a4ff8c2480452114b84b421a6.tar.lz
dexon-07cfb7b64ac7932a4ff8c2480452114b84b421a6.tar.xz
dexon-07cfb7b64ac7932a4ff8c2480452114b84b421a6.tar.zst
dexon-07cfb7b64ac7932a4ff8c2480452114b84b421a6.zip
updated filter so it accepts multiple from and to
-rw-r--r--ethchain/filter.go48
1 files changed, 38 insertions, 10 deletions
diff --git a/ethchain/filter.go b/ethchain/filter.go
index c3b0a7f94..65c41c42d 100644
--- a/ethchain/filter.go
+++ b/ethchain/filter.go
@@ -14,7 +14,7 @@ type Filter struct {
earliest []byte
latest []byte
skip int
- from, to []byte
+ from, to [][]byte
max int
}
@@ -53,14 +53,22 @@ func (self *Filter) SetLatestBlock(latest interface{}) {
}
}
-func (self *Filter) SetFrom(addr []byte) {
+func (self *Filter) SetFrom(addr [][]byte) {
self.from = addr
}
-func (self *Filter) SetTo(addr []byte) {
+func (self *Filter) AddFrom(addr []byte) {
+ self.from = append(self.from, addr)
+}
+
+func (self *Filter) SetTo(addr [][]byte) {
self.to = addr
}
+func (self *Filter) AddTo(addr []byte) {
+ self.from = append(self.to, addr)
+}
+
func (self *Filter) SetMax(max int) {
self.max = max
}
@@ -101,13 +109,22 @@ func (self *Filter) Find() []*ethstate.Message {
break
}
+ includes := func(addresses [][]byte, a []byte) (found bool) {
+ for _, addr := range addresses {
+ if bytes.Compare(addr, a) == 0 {
+ return true
+ }
+ }
+
+ return
+ }
// Filter the messages for interesting stuff
for _, message := range msgs {
- if len(self.to) > 0 && bytes.Compare(message.To, self.to) != 0 {
+ if len(self.to) > 0 && !includes(self.to, message.To) {
continue
}
- if len(self.from) > 0 && bytes.Compare(message.From, self.from) != 0 {
+ if len(self.from) > 0 && !includes(self.from, message.From) {
continue
}
@@ -130,17 +147,28 @@ func (self *Filter) bloomFilter(block *Block) bool {
bloom := NewBloomFilter(bin)
+ var fromIncluded, toIncluded bool
if len(self.from) > 0 {
- if !bloom.Search(self.from) {
- return false
+ for _, from := range self.from {
+ if bloom.Search(from) {
+ fromIncluded = true
+ break
+ }
}
+ } else {
+ fromIncluded = true
}
if len(self.to) > 0 {
- if !bloom.Search(self.to) {
- return false
+ for _, to := range self.to {
+ if bloom.Search(to) {
+ toIncluded = true
+ break
+ }
}
+ } else {
+ toIncluded = true
}
- return true
+ return fromIncluded && toIncluded
}