From d65b64c8846636d3e58c1857eaff149d2f82a283 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Sat, 6 Jun 2015 00:02:32 -0400 Subject: Allow export command to take first and last args --- cmd/geth/chaincmd.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'cmd/geth') diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 947532f40..509356a90 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -26,6 +26,12 @@ var ( Action: exportChain, Name: "export", Usage: `export blockchain into file`, + Description: ` +Requires a first argument of the file to write to. +Optional second and third arguments control the first and +last block to write. In this mode, the file will be appended +if already existing. + `, } upgradedbCommand = cli.Command{ Action: upgradeDB, @@ -68,7 +74,21 @@ func exportChain(ctx *cli.Context) { } chain, _, _, _ := utils.MakeChain(ctx) start := time.Now() - if err := utils.ExportChain(chain, ctx.Args().First()); err != nil { + + var err error + if len(ctx.Args()) < 3 { + err = utils.ExportChain(chain, ctx.Args().First()) + } else { + // This can be improved to allow for numbers larger than 9223372036854775807 + first, ferr := strconv.ParseInt(ctx.Args().Get(1), 10, 64) + last, lerr := strconv.ParseInt(ctx.Args().Get(2), 10, 64) + if ferr != nil || lerr != nil { + utils.Fatalf("Export error in parsing parameters\n") + } + err = utils.ExportAppendChain(chain, ctx.Args().First(), uint64(first), uint64(last)) + } + + if err != nil { utils.Fatalf("Export error: %v\n", err) } fmt.Printf("Export done in %v", time.Since(start)) -- cgit From ed621aae333ac183acc29c396c708ae57301838a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Sat, 6 Jun 2015 09:50:23 -0400 Subject: Cleanup --- cmd/geth/chaincmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd/geth') diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 509356a90..2e90001af 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -69,7 +69,7 @@ func importChain(ctx *cli.Context) { } func exportChain(ctx *cli.Context) { - if len(ctx.Args()) != 1 { + if len(ctx.Args()) < 1 { utils.Fatalf("This command requires an argument.") } chain, _, _, _ := utils.MakeChain(ctx) -- cgit From 2729e6294a22c5f1adb547078a7391ca0537ccc9 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Sat, 6 Jun 2015 10:04:13 -0400 Subject: Improved error checking --- cmd/geth/chaincmd.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'cmd/geth') diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 2e90001af..8586e3b81 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -76,16 +76,20 @@ func exportChain(ctx *cli.Context) { start := time.Now() var err error + fp := ctx.Args().First() if len(ctx.Args()) < 3 { - err = utils.ExportChain(chain, ctx.Args().First()) + err = utils.ExportChain(chain, fp) } else { // This can be improved to allow for numbers larger than 9223372036854775807 first, ferr := strconv.ParseInt(ctx.Args().Get(1), 10, 64) last, lerr := strconv.ParseInt(ctx.Args().Get(2), 10, 64) if ferr != nil || lerr != nil { - utils.Fatalf("Export error in parsing parameters\n") + utils.Fatalf("Export error in parsing parameters: block number not an integer\n") } - err = utils.ExportAppendChain(chain, ctx.Args().First(), uint64(first), uint64(last)) + if first < 0 || last < 0 { + utils.Fatalf("Export error: block number must be greater than 0\n") + } + err = utils.ExportAppendChain(chain, fp, uint64(first), uint64(last)) } if err != nil { -- cgit