Added bloom 9 point lookup and bloom test

This commit is contained in:
obscuren 2014-10-29 20:16:18 +01:00
parent 81ec564ef6
commit cc67a84e94
2 changed files with 29 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package ethchain
import (
"math/big"
"github.com/ethereum.backup/ethutil-go"
"github.com/ethereum/go-ethereum/vm"
)
@ -23,7 +24,10 @@ func LogsBloom(logs []vm.Log) *big.Int {
for _, topic := range log.Topics {
data = append(data, topic)
}
if log.Data != nil {
data = append(data, log.Data)
}
for _, b := range data {
bin.Or(bin, bloom9(b))
@ -42,3 +46,10 @@ func bloom9(b []byte) *big.Int {
return r
}
func BloomLookup(bin, topic []byte) bool {
bloom := ethutil.BigD(bin)
cmp := bloom9(topic)
return bloom.And(bloom, cmp).Cmp(cmp) == 0
}

17
ethchain/bloom9_test.go Normal file
View File

@ -0,0 +1,17 @@
package ethchain
import (
"testing"
"github.com/ethereum/go-ethereum/vm"
)
func TestBloom9(t *testing.T) {
testCase := []byte("testtest")
bin := LogsBloom([]vm.Log{vm.Log{testCase, nil, nil}}).Bytes()
res := BloomLookup(bin, testCase)
if !res {
t.Errorf("Bloom lookup failed")
}
}