aboutsummaryrefslogtreecommitdiffstats
path: root/core/types/bloom9.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/types/bloom9.go')
-rw-r--r--core/types/bloom9.go28
1 files changed, 16 insertions, 12 deletions
diff --git a/core/types/bloom9.go b/core/types/bloom9.go
index af76f226f..64a8ff49a 100644
--- a/core/types/bloom9.go
+++ b/core/types/bloom9.go
@@ -3,32 +3,32 @@ package types
import (
"math/big"
- "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/state"
)
-func CreateBloom(receipts Receipts) []byte {
+func CreateBloom(receipts Receipts) Bloom {
bin := new(big.Int)
for _, receipt := range receipts {
bin.Or(bin, LogsBloom(receipt.logs))
}
- return common.LeftPadBytes(bin.Bytes(), 256)
+ return BytesToBloom(bin.Bytes())
}
func LogsBloom(logs state.Logs) *big.Int {
bin := new(big.Int)
for _, log := range logs {
- data := make([][]byte, len(log.Topics())+1)
- data[0] = log.Address()
+ data := make([]common.Hash, len(log.Topics()))
+ bin.Or(bin, bloom9(log.Address().Bytes()))
for i, topic := range log.Topics() {
- data[i+1] = topic
+ data[i] = topic
}
for _, b := range data {
- bin.Or(bin, common.BigD(bloom9(crypto.Sha3(b)).Bytes()))
+ bin.Or(bin, bloom9(b[:]))
}
}
@@ -36,20 +36,24 @@ func LogsBloom(logs state.Logs) *big.Int {
}
func bloom9(b []byte) *big.Int {
+ b = crypto.Sha3(b[:])
+
r := new(big.Int)
- for i := 0; i < 16; i += 2 {
+ for i := 0; i < 6; i += 2 {
t := big.NewInt(1)
- b := uint(b[i+1]) + 1024*(uint(b[i])&1)
+ b := (uint(b[i+1]) + (uint(b[i]) << 8)) & 2047
r.Or(r, t.Lsh(t, b))
}
return r
}
-func BloomLookup(bin, topic []byte) bool {
- bloom := common.BigD(bin)
- cmp := bloom9(crypto.Sha3(topic))
+var Bloom9 = bloom9
+
+func BloomLookup(bin Bloom, topic common.Hash) bool {
+ bloom := bin.Big()
+ cmp := bloom9(topic[:])
return bloom.And(bloom, cmp).Cmp(cmp) == 0
}