Official Go implementation of the Ethereum protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-ethereum/block.go

65 lines
1.2 KiB

11 years ago
package main
import (
_"fmt"
11 years ago
"time"
11 years ago
)
type Block struct {
11 years ago
RlpSerializer
number uint32
prevHash string
uncles []*Block
coinbase string
// state xxx
difficulty int
time time.Time
nonce int
transactions []*Transaction
11 years ago
}
func NewBlock(/* TODO use raw data */transactions []*Transaction) *Block {
block := &Block{
// Slice of transactions to include in this block
transactions: transactions,
11 years ago
time: time.Now(),
11 years ago
}
return block
}
func (block *Block) Update() {
}
11 years ago
func (block *Block) Hash() string {
return Sha256Hex(block.MarshalRlp())
}
func (block *Block) MarshalRlp() []byte {
// Encoding method requires []interface{} type. It's actual a slice of strings
encTx := make([]string, len(block.transactions))
for i, tx := range block.transactions {
encTx[i] = string(tx.MarshalRlp())
}
enc := RlpEncode([]interface{}{
block.number,
block.prevHash,
// Sha of uncles
block.coinbase,
// root state
Sha256Bin([]byte(RlpEncode(encTx))),
block.difficulty,
block.time,
block.nonce,
// extra?
})
return []byte(enc)
}
func (block *Block) UnmarshalRlp(data []byte) {
}