From 8daa916729e9fddd46c3577561c2f3c8d263950a Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 22 May 2017 13:30:42 +0200 Subject: [PATCH] 88: Correct functioning of unsafe_reset_all to mirror tendermint --- cmd/commands/reset.go | 15 ++++++--------- cmd/commands/start.go | 12 ++++++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cmd/commands/reset.go b/cmd/commands/reset.go index 296e58ad12..4d38f94bfe 100644 --- a/cmd/commands/reset.go +++ b/cmd/commands/reset.go @@ -1,13 +1,9 @@ package commands import ( - "os" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "github.com/tendermint/tendermint/config" - "github.com/tendermint/tmlibs/cli" + tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" ) var UnsafeResetAllCmd = &cobra.Command{ @@ -17,9 +13,10 @@ var UnsafeResetAllCmd = &cobra.Command{ } func unsafeResetAllCmd(cmd *cobra.Command, args []string) error { - rootDir := viper.GetString(cli.HomeFlag) - // wipe out rootdir if it exists before recreating it - os.RemoveAll(rootDir) - config.EnsureRoot(rootDir) + cfg, err := getTendermintConfig() + if err != nil { + return err + } + tmcmd.ResetAll(cfg.DBDir(), cfg.PrivValidatorFile(), logger) return nil } diff --git a/cmd/commands/start.go b/cmd/commands/start.go index 053e6e400f..7a15f59df5 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -122,14 +122,22 @@ func startBasecoinABCI(basecoinApp *app.Basecoin) error { return nil } -func startTendermint(dir string, basecoinApp *app.Basecoin) error { +func getTendermintConfig() (*config.Config, error) { cfg := config.DefaultConfig() err := viper.Unmarshal(cfg) if err != nil { - return err + return nil, err } cfg.SetRoot(cfg.RootDir) config.EnsureRoot(cfg.RootDir) + return cfg, nil +} + +func startTendermint(dir string, basecoinApp *app.Basecoin) error { + cfg, err := getTendermintConfig() + if err != nil { + return err + } // TODO: parse the log level from the config properly (multi modules) // but some tm code must be refactored for better usability