updated blockpool

This commit is contained in:
obscuren
2015-03-16 23:10:26 +01:00
parent 4e181c5764
commit 843db4978e
11 changed files with 151 additions and 106 deletions

View File

@ -106,14 +106,14 @@ func NewBlock(parentHash common.Hash, coinbase common.Address, root common.Hash,
GasUsed: new(big.Int),
GasLimit: new(big.Int),
}
header.setNonce(nonce)
header.SetNonce(nonce)
block := &Block{header: header, Reward: new(big.Int)}
return block
}
func (self *Header) setNonce(nonce uint64) {
func (self *Header) SetNonce(nonce uint64) {
binary.BigEndian.PutUint64(self.Nonce[:], nonce)
}
@ -203,7 +203,7 @@ func (self *Block) Nonce() uint64 {
return binary.BigEndian.Uint64(self.header.Nonce[:])
}
func (self *Block) SetNonce(nonce uint64) {
self.header.setNonce(nonce)
self.header.SetNonce(nonce)
}
func (self *Block) Bloom() Bloom { return self.header.Bloom }

View File

@ -20,15 +20,15 @@ func CreateBloom(receipts Receipts) Bloom {
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())+1)
data[0] = log.Address().Hash()
for i, topic := range log.Topics() {
data[i+1] = topic
}
for _, b := range data {
bin.Or(bin, common.BigD(bloom9(crypto.Sha3(b)).Bytes()))
bin.Or(bin, common.BigD(bloom9(crypto.Sha3(b[:])).Bytes()))
}
}

View File

@ -3,9 +3,11 @@ package types
import (
"bytes"
"fmt"
"io"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/state"
)
@ -20,34 +22,26 @@ func NewReceipt(root []byte, cumalativeGasUsed *big.Int) *Receipt {
return &Receipt{PostState: common.CopyBytes(root), CumulativeGasUsed: new(big.Int).Set(cumalativeGasUsed)}
}
func NewRecieptFromValue(val *common.Value) *Receipt {
r := &Receipt{}
r.RlpValueDecode(val)
return r
}
func (self *Receipt) SetLogs(logs state.Logs) {
self.logs = logs
}
func (self *Receipt) RlpValueDecode(decoder *common.Value) {
self.PostState = decoder.Get(0).Bytes()
self.CumulativeGasUsed = decoder.Get(1).BigInt()
self.Bloom = decoder.Get(2).Bytes()
it := decoder.Get(3).NewIterator()
for it.Next() {
self.logs = append(self.logs, state.NewLogFromValue(it.Value()))
}
func (self *Receipt) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, []interface{}{self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs})
}
/*
func (self *Receipt) RlpData() interface{} {
return []interface{}{self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs.RlpData()}
}
*/
func (self *Receipt) RlpEncode() []byte {
return common.Encode(self.RlpData())
bytes, err := rlp.EncodeToBytes(self)
if err != nil {
fmt.Println("TMP -- RECEIPT ENCODE ERROR", err)
}
return bytes
}
func (self *Receipt) Cmp(other *Receipt) bool {
@ -64,6 +58,7 @@ func (self *Receipt) String() string {
type Receipts []*Receipt
/*
func (self Receipts) RlpData() interface{} {
data := make([]interface{}, len(self))
for i, receipt := range self {
@ -72,9 +67,14 @@ func (self Receipts) RlpData() interface{} {
return data
}
*/
func (self Receipts) RlpEncode() []byte {
return common.Encode(self.RlpData())
bytes, err := rlp.EncodeToBytes(self)
if err != nil {
fmt.Println("TMP -- RECEIPTS ENCODE ERROR", err)
}
return bytes
}
func (self Receipts) Len() int { return len(self) }