Skip to content

Commit

Permalink
fix: Allow --home to propagate to init command (backport #10104) (#10158
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mergify[bot] authored Sep 15, 2021
1 parent 8f49499 commit 6cfa58f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions x/genutil/client/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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")
}
Expand Down

0 comments on commit 6cfa58f

Please sign in to comment.