Added bloom 9 point lookup and bloom test
This commit is contained in:
parent
81ec564ef6
commit
cc67a84e94
@ -3,6 +3,7 @@ package ethchain
|
|||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/ethereum.backup/ethutil-go"
|
||||||
"github.com/ethereum/go-ethereum/vm"
|
"github.com/ethereum/go-ethereum/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,7 +24,10 @@ func LogsBloom(logs []vm.Log) *big.Int {
|
|||||||
for _, topic := range log.Topics {
|
for _, topic := range log.Topics {
|
||||||
data = append(data, topic)
|
data = append(data, topic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if log.Data != nil {
|
||||||
data = append(data, log.Data)
|
data = append(data, log.Data)
|
||||||
|
}
|
||||||
|
|
||||||
for _, b := range data {
|
for _, b := range data {
|
||||||
bin.Or(bin, bloom9(b))
|
bin.Or(bin, bloom9(b))
|
||||||
@ -42,3 +46,10 @@ func bloom9(b []byte) *big.Int {
|
|||||||
|
|
||||||
return r
|
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
17
ethchain/bloom9_test.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user