aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-27 18:22:27 +0800
committerobscuren <geffobscura@gmail.com>2014-10-27 18:22:27 +0800
commit6623500c6b2e5fe9fa41a1ce75269955af6026e8 (patch)
treed866b09235dae04cc83993ca2eb0987c578b0a17 /ethchain
parent08c26ab8b0142778393924211188f0d06deef0ce (diff)
downloadgo-tangerine-6623500c6b2e5fe9fa41a1ce75269955af6026e8.tar
go-tangerine-6623500c6b2e5fe9fa41a1ce75269955af6026e8.tar.gz
go-tangerine-6623500c6b2e5fe9fa41a1ce75269955af6026e8.tar.bz2
go-tangerine-6623500c6b2e5fe9fa41a1ce75269955af6026e8.tar.lz
go-tangerine-6623500c6b2e5fe9fa41a1ce75269955af6026e8.tar.xz
go-tangerine-6623500c6b2e5fe9fa41a1ce75269955af6026e8.tar.zst
go-tangerine-6623500c6b2e5fe9fa41a1ce75269955af6026e8.zip
Implemented new bloom filter. Closes #156
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/bloom9.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/ethchain/bloom9.go b/ethchain/bloom9.go
new file mode 100644
index 000000000..eef0a9d3f
--- /dev/null
+++ b/ethchain/bloom9.go
@@ -0,0 +1,38 @@
+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 {
+ data := []byte{log.Address}
+ 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} {
+ r |= 1 << (b[i+1] + 256*(b[i]&1))
+ }
+
+ return r
+}