cmd, core, eth, common: genesis preparation

Implemented the --genesis flag thru which we can set a custom genesis
block, including the official Ethereum genesis block.
This commit is contained in:
Jeffrey Wilcke
2015-07-10 14:29:40 +02:00
parent 5a810758db
commit a32c51effd
15 changed files with 244 additions and 138 deletions

View File

@ -19,6 +19,7 @@ package core
import (
"bytes"
"math/big"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
@ -28,6 +29,11 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)
var (
blockHashPre = []byte("block-hash-")
blockNumPre = []byte("block-num-")
)
// CalcDifficulty is the difficulty adjustment algorithm. It returns
// the difficulty that a new block b should have when created at time
// given the parent block's time and difficulty.
@ -118,3 +124,22 @@ func WriteHead(db common.Database, block *types.Block) error {
}
return nil
}
// WriteBlock writes a block to the database
func WriteBlock(db common.Database, block *types.Block) error {
tstart := time.Now()
enc, _ := rlp.EncodeToBytes((*types.StorageBlock)(block))
key := append(blockHashPre, block.Hash().Bytes()...)
err := db.Put(key, enc)
if err != nil {
glog.Fatal("db write fail:", err)
return err
}
if glog.V(logger.Debug) {
glog.Infof("wrote block #%v %s. Took %v\n", block.Number(), common.PP(block.Hash().Bytes()), time.Since(tstart))
}
return nil
}