From 9e5257b83b8572077b9c26e4ae9a9443f765bf6e Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 23 Dec 2014 14:33:15 +0100 Subject: Chain importer --- cmd/ethereum/main.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'cmd/ethereum/main.go') 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() } -- cgit v1.2.3