Skip to content

Commit

Permalink
Merge pull request cosmos#185 from scrtlabs/lior-export-to-file
Browse files Browse the repository at this point in the history
Export now only exports to file
  • Loading branch information
Cashmaney authored Aug 23, 2022
2 parents ac08f6c + f45b8d2 commit 45cac6c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const (
FlagHeight = "height"
FlagForZeroHeight = "for-zero-height"
FlagJailAllowedAddrs = "jail-allowed-addrs"
FlagOutputFilePath = "output-file-path"
)

// ExportCmd dumps app state to JSON.
func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "export",
Short: "Export state to JSON",
Long: "Export state to JSON. The state will be printed to a file based on the provided path. Default path is ./exported_secret_state.json",
RunE: func(cmd *cobra.Command, args []string) error {
serverCtx := GetServerContextFromCmd(cmd)
config := serverCtx.Config
Expand Down Expand Up @@ -105,6 +107,13 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
return err
}

outputFilePath, _ := cmd.Flags().GetString(FlagOutputFilePath)
outputFile, err := os.OpenFile(outputFilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0444)
if err != nil {
return err
}

cmd.SetOut(outputFile)
cmd.Println(string(sdk.MustSortJSON(encoded)))
return nil
},
Expand All @@ -114,6 +123,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
cmd.Flags().Int64(FlagHeight, -1, "Export state from a particular height (-1 means latest height)")
cmd.Flags().Bool(FlagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)")
cmd.Flags().StringSlice(FlagJailAllowedAddrs, []string{}, "Comma-separated list of operator addresses of jailed validators to unjail")
cmd.Flags().String(FlagOutputFilePath, "./exported_secret_state.json", "The file that the output will be written to")

return cmd
}

0 comments on commit 45cac6c

Please sign in to comment.