func upgradeDB(ctx *cli.Context) { glog.Infoln("Upgrading blockchain database") chain, chainDb := utils.MakeChain(ctx) v, _ := chainDb.Get([]byte("BlockchainVersion")) bcVersion := int(common.NewValue(v).Uint()) if bcVersion == 0 { bcVersion = core.BlockChainVersion } // Export the current chain. filename := fmt.Sprintf("blockchain_%d_%s.chain", bcVersion, time.Now().Format("20060102_150405")) exportFile := filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), filename) if err := utils.ExportChain(chain, exportFile); err != nil { utils.Fatalf("Unable to export chain for reimport %s", err) } chainDb.Close() os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "chaindata")) // Import the chain file. chain, chainDb = utils.MakeChain(ctx) chainDb.Put([]byte("BlockchainVersion"), common.NewValue(core.BlockChainVersion).Bytes()) err := utils.ImportChain(chain, exportFile) chainDb.Close() if err != nil { utils.Fatalf("Import error %v (a backup is made in %s, use the import command to import it)", err, exportFile) } else { os.Remove(exportFile) glog.Infoln("Import finished") } }
func importchain(ctx *cli.Context) { if len(ctx.Args()) != 1 { utils.Fatalf("This command requires an argument.") } cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) cfg.SkipBcVersionCheck = true ethereum, err := eth.New(cfg) if err != nil { utils.Fatalf("%v\n", err) } chainmgr := ethereum.ChainManager() start := time.Now() err = utils.ImportChain(chainmgr, ctx.Args().First()) if err != nil { utils.Fatalf("Import error: %v\n", err) } // force database flush ethereum.BlockDb().Close() ethereum.StateDb().Close() ethereum.ExtraDb().Close() fmt.Printf("Import done in %v", time.Since(start)) return }
func upgradeDb(ctx *cli.Context) { fmt.Println("Upgrade blockchain DB") cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) cfg.SkipBcVersionCheck = true ethereum, err := eth.New(cfg) if err != nil { utils.Fatalf("%v\n", err) } v, _ := ethereum.BlockDb().Get([]byte("BlockchainVersion")) bcVersion := int(common.NewValue(v).Uint()) if bcVersion == 0 { bcVersion = core.BlockChainVersion } filename := fmt.Sprintf("blockchain_%d_%s.chain", bcVersion, time.Now().Format("2006-01-02_15:04:05")) exportFile := path.Join(ctx.GlobalString(utils.DataDirFlag.Name), filename) err = utils.ExportChain(ethereum.ChainManager(), exportFile) if err != nil { utils.Fatalf("Unable to export chain for reimport %s\n", err) } ethereum.BlockDb().Close() ethereum.StateDb().Close() ethereum.ExtraDb().Close() os.RemoveAll(path.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain")) ethereum, err = eth.New(cfg) if err != nil { utils.Fatalf("%v\n", err) } ethereum.BlockDb().Put([]byte("BlockchainVersion"), common.NewValue(core.BlockChainVersion).Bytes()) err = utils.ImportChain(ethereum.ChainManager(), exportFile) if err != nil { utils.Fatalf("Import error %v (a backup is made in %s, use the import command to import it)\n", err, exportFile) } // force database flush ethereum.BlockDb().Close() ethereum.StateDb().Close() ethereum.ExtraDb().Close() os.Remove(exportFile) fmt.Println("Import finished") }
func importChain(ctx *cli.Context) { if len(ctx.Args()) != 1 { utils.Fatalf("This command requires an argument.") } chain, chainDb := utils.MakeChain(ctx) start := time.Now() err := utils.ImportChain(chain, ctx.Args().First()) chainDb.Close() if err != nil { utils.Fatalf("Import error: %v", err) } fmt.Printf("Import done in %v", time.Since(start)) }
func (js *jsre) importChain(call otto.FunctionCall) otto.Value { if len(call.ArgumentList) == 0 { fmt.Println("err: require file name") return otto.FalseValue() } fn, err := call.Argument(0).ToString() if err != nil { fmt.Println(err) return otto.FalseValue() } if err := utils.ImportChain(js.ethereum.ChainManager(), fn); err != nil { fmt.Println("Import error: ", err) return otto.FalseValue() } return otto.TrueValue() }