quorum/core/types/common.go

42 lines
637 B
Go
Raw Normal View History

package types
2015-03-17 03:19:23 -07:00
import (
2015-03-17 10:00:03 -07:00
"fmt"
2015-03-17 03:19:23 -07:00
"math/big"
"github.com/ethereum/go-ethereum/common"
)
type BlockProcessor interface {
2015-02-04 15:05:47 -08:00
Process(*Block) (*big.Int, error)
}
2015-03-16 09:27:23 -07:00
2015-03-17 10:00:03 -07:00
const bloomLength = 256
type Bloom [bloomLength]byte
2015-03-16 09:27:23 -07:00
func BytesToBloom(b []byte) Bloom {
var bloom Bloom
bloom.SetBytes(b)
return bloom
}
func (b *Bloom) SetBytes(d []byte) {
2015-03-17 10:00:03 -07:00
if len(b) < len(d) {
panic(fmt.Sprintf("bloom bytes too big %d %d", len(b), len(d)))
2015-03-16 09:27:23 -07:00
}
// reverse loop
for i := len(d) - 1; i >= 0; i-- {
2015-03-17 10:00:03 -07:00
b[bloomLength-len(d)+i] = b[i]
2015-03-16 09:27:23 -07:00
}
}
2015-03-17 03:19:23 -07:00
func (b Bloom) Big() *big.Int {
return common.Bytes2Big(b[:])
}
2015-03-18 03:44:25 -07:00
func (b Bloom) Bytes() []byte {
return b[:]
}