diff --git a/cmd/tendermint/commands/init.go b/cmd/tendermint/commands/init.go index e8f22eb1..0bc9e626 100644 --- a/cmd/tendermint/commands/init.go +++ b/cmd/tendermint/commands/init.go @@ -1,8 +1,6 @@ package commands import ( - "os" - "github.com/spf13/cobra" "github.com/tendermint/tendermint/types" @@ -17,29 +15,34 @@ var InitFilesCmd = &cobra.Command{ } func initFiles(cmd *cobra.Command, args []string) { + // private validator privValFile := config.PrivValidatorFile() - if _, err := os.Stat(privValFile); os.IsNotExist(err) { - privValidator := types.GenPrivValidatorFS(privValFile) - privValidator.Save() - - genFile := config.GenesisFile() - - if _, err := os.Stat(genFile); os.IsNotExist(err) { - genDoc := types.GenesisDoc{ - ChainID: cmn.Fmt("test-chain-%v", cmn.RandStr(6)), - } - genDoc.Validators = []types.GenesisValidator{{ - PubKey: privValidator.GetPubKey(), - Power: 10, - }} - - if err := genDoc.SaveAs(genFile); err != nil { - panic(err) - } - } - - logger.Info("Initialized tendermint", "genesis", config.GenesisFile(), "priv_validator", config.PrivValidatorFile()) + var privValidator *types.PrivValidatorFS + if cmn.FileExists(privValFile) { + privValidator = types.LoadPrivValidatorFS(privValFile) + logger.Info("Found private validator", "path", privValFile) } else { - logger.Info("Already initialized", "priv_validator", config.PrivValidatorFile()) + privValidator = types.GenPrivValidatorFS(privValFile) + privValidator.Save() + logger.Info("Genetated private validator", "path", privValFile) + } + + // genesis file + genFile := config.GenesisFile() + if cmn.FileExists(genFile) { + logger.Info("Found genesis file", "path", genFile) + } else { + genDoc := types.GenesisDoc{ + ChainID: cmn.Fmt("test-chain-%v", cmn.RandStr(6)), + } + genDoc.Validators = []types.GenesisValidator{{ + PubKey: privValidator.GetPubKey(), + Power: 10, + }} + + if err := genDoc.SaveAs(genFile); err != nil { + panic(err) + } + logger.Info("Genetated genesis file", "path", genFile) } }