aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_util.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-07-10 20:29:40 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-07-10 23:37:41 +0800
commita32c51effda8682b292d04863aae7811f78abf7e (patch)
treed721822cc10c929d5a2def0865c366e085ef99be /core/chain_util.go
parent5a810758dbe75dce9537d464ac0e5b5385b0e78f (diff)
downloadgo-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar.gz
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar.bz2
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar.lz
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar.xz
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar.zst
go-tangerine-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.go25
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
+}