Skip to content

Commit

Permalink
Implemented new bloom filter. Closes #156
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed Oct 27, 2014
1 parent 08c26ab commit 6623500
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ethchain/bloom9.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ethchain

import "github.com/ethereum/go-ethereum/vm"

func CreateBloom(txs Transactions) uint64 {
var bin uint64
for _, tx := range txs {
bin |= logsBloom(tx.logs)
}

return bin
}

func logsBloom(logs []vm.Log) uint64 {
var bin uint64
for _, log := range logs {
data := []byte{log.Address}
for _, topic := range log.Topics {
data = append(data, topic.Bytes())
}
data = append(data, log.Data)

for _, b := range data {
bin |= bloom9(b)
}
}

return bin
}

func bloom9(b []byte) uint64 {
var r uint64
for _, i := range []int{0, 2, 4} {
r |= 1 << (b[i+1] + 256*(b[i]&1))
}

return r
}

0 comments on commit 6623500

Please sign in to comment.