aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-23 21:33:15 +0800
committerobscuren <geffobscura@gmail.com>2014-12-23 21:33:15 +0800
commit9e5257b83b8572077b9c26e4ae9a9443f765bf6e (patch)
treef94a123cb02af8cebecef263290b0378cf3d78ac /cmd
parent4cd79d8ddd7608d60344b13fe4bda7315429d1d9 (diff)
downloaddexon-9e5257b83b8572077b9c26e4ae9a9443f765bf6e.tar.gz
dexon-9e5257b83b8572077b9c26e4ae9a9443f765bf6e.tar.zst
dexon-9e5257b83b8572077b9c26e4ae9a9443f765bf6e.zip
Chain importer
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ethereum/flags.go2
-rw-r--r--cmd/ethereum/main.go28
2 files changed, 29 insertions, 1 deletions
diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go
index 72f1db458..d27b739c3 100644
--- a/cmd/ethereum/flags.go
+++ b/cmd/ethereum/flags.go
@@ -58,6 +58,7 @@ var (
DumpHash string
DumpNumber int
VmType int
+ ImportChain string
)
// flags specific to cli client
@@ -104,6 +105,7 @@ func Init() {
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
+ flag.StringVar(&ImportChain, "chain", "", "Imports fiven chain")
flag.BoolVar(&Dump, "dump", false, "output the ethereum state in JSON format. Sub args [number, hash]")
flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")
diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go
index fff9aedf8..f16244a2d 100644
--- a/cmd/ethereum/main.go
+++ b/cmd/ethereum/main.go
@@ -18,6 +18,7 @@
package main
import (
+ "bytes"
"fmt"
"os"
"runtime"
@@ -26,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/rlp"
)
const (
@@ -38,6 +40,10 @@ var clilogger = logger.NewLogger("CLI")
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
+ defer func() {
+ logger.Flush()
+ }()
+
utils.HandleInterrupt()
// precedence: code-internal flag default < config file < environment variables < command line
@@ -112,6 +118,27 @@ func main() {
utils.StartMining(ethereum)
}
+ if len(ImportChain) > 0 {
+ clilogger.Infof("importing chain '%s'\n", ImportChain)
+ c, err := ethutil.ReadAllFile(ImportChain)
+ if err != nil {
+ clilogger.Infoln(err)
+ return
+ }
+ var chain types.Blocks
+ if err := rlp.Decode(bytes.NewReader([]byte(c)), &chain); err != nil {
+ clilogger.Infoln(err)
+ return
+ }
+
+ ethereum.ChainManager().Reset()
+ if err := ethereum.ChainManager().InsertChain(chain); err != nil {
+ clilogger.Infoln(err)
+ return
+ }
+ clilogger.Infof("imported %d blocks\n", len(chain))
+ }
+
// better reworked as cases
if StartJsConsole {
InitJsConsole(ethereum)
@@ -131,5 +158,4 @@ func main() {
// this blocks the thread
ethereum.WaitForShutdown()
- logger.Flush()
}