2014-10-27 05:22:27 -05:00
|
|
|
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 {
|
2014-10-27 05:44:28 -05:00
|
|
|
data := [][]byte{log.Address}
|
2014-10-27 05:22:27 -05:00
|
|
|
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} {
|
2014-10-27 05:44:28 -05:00
|
|
|
r |= 1 << (uint64(b[i+1]) + 256*(uint64(b[i])&1))
|
2014-10-27 05:22:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|