diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-07-10 20:29:40 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-07-10 23:37:41 +0800 |
commit | a32c51effda8682b292d04863aae7811f78abf7e (patch) | |
tree | d721822cc10c929d5a2def0865c366e085ef99be /core/chain_util.go | |
parent | 5a810758dbe75dce9537d464ac0e5b5385b0e78f (diff) | |
download | dexon-a32c51effda8682b292d04863aae7811f78abf7e.tar.gz dexon-a32c51effda8682b292d04863aae7811f78abf7e.tar.zst dexon-a32c51effda8682b292d04863aae7811f78abf7e.zip |
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.
Diffstat (limited to 'core/chain_util.go')
-rw-r--r-- | core/chain_util.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/core/chain_util.go b/core/chain_util.go index 7e3d8eba8..253396ed7 100644 --- a/core/chain_util.go +++ b/core/chain_util.go @@ -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 +} |