From 6cfa58f1cedf39f270361a580da4c6c0e06f9d18 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 15 Sep 2021 15:19:25 -0400 Subject: [PATCH] fix: Allow --home to propagate to init command (backport #10104) (#10158) --- CHANGELOG.md | 4 ++++ client/cmd.go | 8 ++------ x/genutil/client/cli/init.go | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da51f0a3bb65..cfe08c13ccf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Bug Fixes + +* (x/genutil) [#10104](https://github.com/cosmos/cosmos-sdk/pull/10104) Ensure the `init` command reads the `--home` flag value correctly. + ## [v0.44.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.0) - 2021-09-01 ### Features diff --git a/client/cmd.go b/client/cmd.go index 2a8dd498c5e1..c2e3ff8a4726 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -249,12 +249,8 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err return clientCtx, nil } -// ReadHomeFlag checks if home flag is changed. -// If this is a case, we update HomeDir field of Client Context -/* Discovered a bug with Cory -./build/simd init andrei --home ./test -cd test/config there is no client.toml configuration file -*/ +// ReadHomeFlag checks if home flag is changed. If this is a case, we update +// HomeDir field of Client Context. func ReadHomeFlag(clientCtx Context, cmd *cobra.Command) Context { if cmd.Flags().Changed(flags.FlagHome) { rootDir, _ := cmd.Flags().GetString(flags.FlagHome) diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index a51d4b90757b..dcc6f67b05f4 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -77,6 +77,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { serverCtx := server.GetServerContextFromCmd(cmd) config := serverCtx.Config + clientCtx = client.ReadHomeFlag(clientCtx, cmd) config.SetRoot(clientCtx.HomeDir) chainID, _ := cmd.Flags().GetString(flags.FlagChainID) @@ -113,6 +114,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { if !overwrite && tmos.FileExists(genFile) { return fmt.Errorf("genesis.json file already exists: %v", genFile) } + appState, err := json.MarshalIndent(mbm.DefaultGenesis(cdc), "", " ") if err != nil { return errors.Wrap(err, "Failed to marshall default genesis state") @@ -133,6 +135,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { genDoc.ChainID = chainID genDoc.Validators = nil genDoc.AppState = appState + if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil { return errors.Wrap(err, "Failed to export gensis file") }