From 51eed7964ec35bbdc23dd8a4a8fffedad247e33d Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 8 Mar 2015 22:44:48 +0700 Subject: add export blockchain subcommand, remove BlockDo --- cmd/ethereum/main.go | 31 +++++++++++++++++++++++++------ cmd/utils/cmd.go | 41 +++++++++++++++++------------------------ 2 files changed, 42 insertions(+), 30 deletions(-) (limited to 'cmd') diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index 8b361f7ae..f3f428156 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -87,6 +87,11 @@ runtime will execute the file and exit. Name: "import", Usage: `import a blockchain file`, }, + { + Action: exportchain, + Name: "export", + Usage: `export blockchain into file`, + }, } app.Author = "" app.Email = "" @@ -171,25 +176,39 @@ func importchain(ctx *cli.Context) { if len(ctx.Args()) != 1 { utils.Fatalf("This command requires an argument.") } - chain, _, _ := utils.GetChain(ctx) + chainmgr, _, _ := utils.GetChain(ctx) start := time.Now() - err := utils.ImportChain(chain, ctx.Args().First()) + err := utils.ImportChain(chainmgr, ctx.Args().First()) if err != nil { utils.Fatalf("Import error: %v\n", err) } - fmt.Printf("Import done in", time.Since(start)) + fmt.Printf("Import done in %v", time.Since(start)) + return +} + +func exportchain(ctx *cli.Context) { + if len(ctx.Args()) != 1 { + utils.Fatalf("This command requires an argument.") + } + chainmgr, _, _ := utils.GetChain(ctx) + start := time.Now() + err := utils.ExportChain(chainmgr, ctx.Args().First()) + if err != nil { + utils.Fatalf("Export error: %v\n", err) + } + fmt.Printf("Export done in %v", time.Since(start)) return } func dump(ctx *cli.Context) { - chain, _, stateDb := utils.GetChain(ctx) + chainmgr, _, stateDb := utils.GetChain(ctx) for _, arg := range ctx.Args() { var block *types.Block if hashish(arg) { - block = chain.GetBlock(ethutil.Hex2Bytes(arg)) + block = chainmgr.GetBlock(ethutil.Hex2Bytes(arg)) } else { num, _ := strconv.Atoi(arg) - block = chain.GetBlockByNumber(uint64(num)) + block = chainmgr.GetBlockByNumber(uint64(num)) } if block == nil { fmt.Println("{}") diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 99e60ff9e..8e516748e 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -35,7 +35,6 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/rlp" rpchttp "github.com/ethereum/go-ethereum/rpc/http" - "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/xeth" ) @@ -188,27 +187,8 @@ func FormatTransactionData(data string) []byte { return d } -// Replay block -func BlockDo(ethereum *eth.Ethereum, hash []byte) error { - block := ethereum.ChainManager().GetBlock(hash) - if block == nil { - return fmt.Errorf("unknown block %x", hash) - } - - parent := ethereum.ChainManager().GetBlock(block.ParentHash()) - - statedb := state.New(parent.Root(), ethereum.StateDb()) - _, err := ethereum.BlockProcessor().TransitionState(statedb, parent, block, true) - if err != nil { - return err - } - - return nil - -} - -func ImportChain(chain *core.ChainManager, fn string) error { - fmt.Printf("importing chain '%s'\n", fn) +func ImportChain(chainmgr *core.ChainManager, fn string) error { + fmt.Printf("importing blockchain '%s'\n", fn) fh, err := os.OpenFile(fn, os.O_RDONLY, os.ModePerm) if err != nil { return err @@ -220,11 +200,24 @@ func ImportChain(chain *core.ChainManager, fn string) error { return err } - chain.Reset() - if err := chain.InsertChain(blocks); err != nil { + chainmgr.Reset() + if err := chainmgr.InsertChain(blocks); err != nil { return err } fmt.Printf("imported %d blocks\n", len(blocks)) return nil } + +func ExportChain(chainmgr *core.ChainManager, fn string) error { + fmt.Printf("exporting blockchain '%s'\n", fn) + + data := chainmgr.Export() + + if err := ethutil.WriteFile(fn, data); err != nil { + return err + } + fmt.Printf("exported blockchain\n") + + return nil +} -- cgit v1.2.3 From 41a89e18f68f4b12b8212544be01a4e0a6716976 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 8 Mar 2015 22:50:27 +0700 Subject: version output - make version output more verbose - include NetworkId - go version and os not displayed like env vars (confusing) --- cmd/ethereum/main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'cmd') diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index f3f428156..12e205f37 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -228,11 +228,13 @@ func hashish(x string) bool { } func version(c *cli.Context) { - fmt.Printf(`%v %v -PV=%d -GOOS=%s -GO=%s + fmt.Printf(`%v +Version: %v +Protocol Version: %d +Network Id: %d +GO: %s +OS: %s GOPATH=%s GOROOT=%s -`, ClientIdentifier, Version, eth.ProtocolVersion, runtime.GOOS, runtime.Version(), os.Getenv("GOPATH"), runtime.GOROOT()) +`, ClientIdentifier, Version, eth.ProtocolVersion, eth.NetworkId, runtime.Version(), runtime.GOOS, os.Getenv("GOPATH"), runtime.GOROOT()) } -- cgit v1.2.3