core/bloombits: use general filters instead of addresses and topics

This commit is contained in:
Zsolt Felfoldi
2017-09-06 02:33:10 +02:00
committed by Péter Szilágyi
parent 6ff2c02991
commit 451ffdb62b
3 changed files with 34 additions and 47 deletions

View File

@ -60,6 +60,23 @@ type Filter struct {
// New creates a new filter which uses a bloom filter on blocks to figure out whether
// a particular block is interesting or not.
func New(backend Backend, begin, end int64, addresses []common.Address, topics [][]common.Hash) *Filter {
// Flatten the address and topic filter clauses into a single filter system
var filters [][][]byte
if len(addresses) > 0 {
filter := make([][]byte, len(addresses))
for i, address := range addresses {
filter[i] = address.Bytes()
}
filters = append(filters, filter)
}
for _, topicList := range topics {
filter := make([][]byte, len(topicList))
for i, topic := range topicList {
filter[i] = topic.Bytes()
}
filters = append(filters, filter)
}
// Assemble and return the filter
size, _ := backend.BloomStatus()
return &Filter{
@ -69,7 +86,7 @@ func New(backend Backend, begin, end int64, addresses []common.Address, topics [
addresses: addresses,
topics: topics,
db: backend.ChainDb(),
matcher: bloombits.NewMatcher(size, addresses, topics),
matcher: bloombits.NewMatcher(size, filters),
}
}