Skip to content

Commit cc67a84

Browse files
committed
Added bloom 9 point lookup and bloom test
1 parent 81ec564 commit cc67a84

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎ethchain/bloom9.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ethchain
33
import (
44
"math/big"
55

6+
"github.com/ethereum.backup/ethutil-go"
67
"github.com/ethereum/go-ethereum/vm"
78
)
89

@@ -23,7 +24,10 @@ func LogsBloom(logs []vm.Log) *big.Int {
2324
for _, topic := range log.Topics {
2425
data = append(data, topic)
2526
}
26-
data = append(data, log.Data)
27+
28+
if log.Data != nil {
29+
data = append(data, log.Data)
30+
}
2731

2832
for _, b := range data {
2933
bin.Or(bin, bloom9(b))
@@ -42,3 +46,10 @@ func bloom9(b []byte) *big.Int {
4246

4347
return r
4448
}
49+
50+
func BloomLookup(bin, topic []byte) bool {
51+
bloom := ethutil.BigD(bin)
52+
cmp := bloom9(topic)
53+
54+
return bloom.And(bloom, cmp).Cmp(cmp) == 0
55+
}

‎ethchain/bloom9_test.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ethchain
2+
3+
import (
4+
"testing"
5+
6+
"github.com/ethereum/go-ethereum/vm"
7+
)
8+
9+
func TestBloom9(t *testing.T) {
10+
testCase := []byte("testtest")
11+
bin := LogsBloom([]vm.Log{vm.Log{testCase, nil, nil}}).Bytes()
12+
res := BloomLookup(bin, testCase)
13+
14+
if !res {
15+
t.Errorf("Bloom lookup failed")
16+
}
17+
}

0 commit comments

Comments
 (0)