From 9b844575e55c6d659f3d5bb9ace9b983c9ff1992 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Wed, 29 Nov 2023 23:48:02 -0700 Subject: [PATCH] fix cmd --- cmd/horcrux/cmd/start.go | 9 ++++----- cmd/horcrux/cmd/state.go | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cmd/horcrux/cmd/start.go b/cmd/horcrux/cmd/start.go index f8820533..ef4fde1d 100644 --- a/cmd/horcrux/cmd/start.go +++ b/cmd/horcrux/cmd/start.go @@ -17,19 +17,18 @@ func startCmd() *cobra.Command { Args: cobra.NoArgs, SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - err := signer.RequireNotRunning(config.PidFile) + out := cmd.OutOrStdout() + logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)) + + err := signer.RequireNotRunning(logger, config.PidFile) if err != nil { return err } - out := cmd.OutOrStdout() - if _, err := legacyConfig(); err == nil { return fmt.Errorf("this is a legacy config. run `horcrux config migrate` to migrate to the latest format") } - logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)) - // create all directories up to the state directory if err = os.MkdirAll(config.StateDir, 0700); err != nil { return err diff --git a/cmd/horcrux/cmd/state.go b/cmd/horcrux/cmd/state.go index 5380da16..146f7e49 100644 --- a/cmd/horcrux/cmd/state.go +++ b/cmd/horcrux/cmd/state.go @@ -14,6 +14,7 @@ import ( "github.com/strangelove-ventures/horcrux/signer" cometjson "github.com/cometbft/cometbft/libs/json" + cometlog "github.com/cometbft/cometbft/libs/log" ) // Snippet Taken from https://raw.githubusercontent.com/cometbft/cometbft/main/privval/file.go @@ -82,6 +83,9 @@ func setStateCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { chainID := args[0] + out := cmd.OutOrStdout() + logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)) + if _, err := os.Stat(config.HomeDir); os.IsNotExist(err) { cmd.SilenceUsage = false return fmt.Errorf("%s does not exist, initialize config with horcrux config init and try again", config.HomeDir) @@ -89,7 +93,7 @@ func setStateCmd() *cobra.Command { // Resetting the priv_validator_state.json should only be allowed if the // signer is not running. - if err := signer.RequireNotRunning(config.PidFile); err != nil { + if err := signer.RequireNotRunning(logger, config.PidFile); err != nil { return err } @@ -109,7 +113,7 @@ func setStateCmd() *cobra.Command { return err } - fmt.Fprintf(cmd.OutOrStdout(), "Setting height %d\n", height) + fmt.Fprintf(out, "Setting height %d\n", height) pv.NoncePublic, cs.NoncePublic = nil, nil signState := signer.SignStateConsensus{ @@ -150,9 +154,12 @@ func importStateCmd() *cobra.Command { return fmt.Errorf("%s does not exist, initialize config with horcrux config init and try again", config.HomeDir) } + out := cmd.OutOrStdout() + logger := cometlog.NewTMLogger(cometlog.NewSyncWriter(out)) + // Resetting the priv_validator_state.json should only be allowed if the // signer is not running. - if err := signer.RequireNotRunning(config.PidFile); err != nil { + if err := signer.RequireNotRunning(logger, config.PidFile); err != nil { return err } @@ -170,11 +177,11 @@ func importStateCmd() *cobra.Command { // Allow user to paste in priv_validator_state.json - fmt.Println("IMPORTANT: Your validator should already be STOPPED. You must copy the latest state..") + fmt.Fprintln(out, "IMPORTANT: Your validator should already be STOPPED. You must copy the latest state..") <-time.After(2 * time.Second) - fmt.Println("") - fmt.Println("Paste your old priv_validator_state.json. Input a blank line after the pasted JSON to continue.") - fmt.Println("") + fmt.Fprintln(out, "") + fmt.Fprintln(out, "Paste your old priv_validator_state.json. Input a blank line after the pasted JSON to continue.") + fmt.Fprintln(out, "") var textBuffer strings.Builder