|
26 | 26 | Action: exportChain,
|
27 | 27 | Name: "export",
|
28 | 28 | Usage: `export blockchain into file`,
|
| 29 | + Description: ` |
| 30 | +Requires a first argument of the file to write to. |
| 31 | +Optional second and third arguments control the first and |
| 32 | +last block to write. In this mode, the file will be appended |
| 33 | +if already existing. |
| 34 | + `, |
29 | 35 | }
|
30 | 36 | upgradedbCommand = cli.Command{
|
31 | 37 | Action: upgradeDB,
|
@@ -63,12 +69,30 @@ func importChain(ctx *cli.Context) {
|
63 | 69 | }
|
64 | 70 |
|
65 | 71 | func exportChain(ctx *cli.Context) {
|
66 |
| - if len(ctx.Args()) != 1 { |
| 72 | + if len(ctx.Args()) < 1 { |
67 | 73 | utils.Fatalf("This command requires an argument.")
|
68 | 74 | }
|
69 | 75 | chain, _, _, _ := utils.MakeChain(ctx)
|
70 | 76 | start := time.Now()
|
71 |
| - if err := utils.ExportChain(chain, ctx.Args().First()); err != nil { |
| 77 | + |
| 78 | + var err error |
| 79 | + fp := ctx.Args().First() |
| 80 | + if len(ctx.Args()) < 3 { |
| 81 | + err = utils.ExportChain(chain, fp) |
| 82 | + } else { |
| 83 | + // This can be improved to allow for numbers larger than 9223372036854775807 |
| 84 | + first, ferr := strconv.ParseInt(ctx.Args().Get(1), 10, 64) |
| 85 | + last, lerr := strconv.ParseInt(ctx.Args().Get(2), 10, 64) |
| 86 | + if ferr != nil || lerr != nil { |
| 87 | + utils.Fatalf("Export error in parsing parameters: block number not an integer\n") |
| 88 | + } |
| 89 | + if first < 0 || last < 0 { |
| 90 | + utils.Fatalf("Export error: block number must be greater than 0\n") |
| 91 | + } |
| 92 | + err = utils.ExportAppendChain(chain, fp, uint64(first), uint64(last)) |
| 93 | + } |
| 94 | + |
| 95 | + if err != nil { |
72 | 96 | utils.Fatalf("Export error: %v\n", err)
|
73 | 97 | }
|
74 | 98 | fmt.Printf("Export done in %v", time.Since(start))
|
|
0 commit comments