aboutsummaryrefslogtreecommitdiffstats
path: root/core/types/common.go
blob: cb57ef053dd4a69be484fdc0867500f9600d4499 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package types

import (
    "fmt"
    "math/big"

    "github.com/ethereum/go-ethereum/common"
)

type BlockProcessor interface {
    Process(*Block) (*big.Int, error)
}

const bloomLength = 256

type Bloom [bloomLength]byte

func BytesToBloom(b []byte) Bloom {
    var bloom Bloom
    bloom.SetBytes(b)
    return bloom
}

func (b *Bloom) SetBytes(d []byte) {
    if len(b) < len(d) {
        panic(fmt.Sprintf("bloom bytes too big %d %d", len(b), len(d)))
    }

    // reverse loop
    for i := len(d) - 1; i >= 0; i-- {
        b[bloomLength-len(d)+i] = b[i]
    }
}

func (b Bloom) Big() *big.Int {
    return common.Bytes2Big(b[:])
}