Skip to content

Commit

Permalink
fix: Allow --home to propagate to init command (backport cosmos#10104) (
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored and JeancarloBarrios committed Sep 28, 2024
1 parent c6af404 commit c44be9e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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
11 changes: 6 additions & 5 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
clientCtx = clientCtx.WithOutputFormat(flags.OutputFormatJSON)
}

// If the user didn't explicitly set a --sign-mode flag, use DIRECT_AUX by default.
if clientCtx.SignModeStr == "" || !flagSet.Changed(flags.FlagSignMode) {
clientCtx = clientCtx.WithSignModeStr(flags.SignModeDirectAux)
}
}
// 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)
clientCtx = clientCtx.WithHomeDir(rootDir)
}

return clientCtx, nil
Expand Down
33 changes: 13 additions & 20 deletions x/genutil/client/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ func InitCmd(mm genesisMM) *cobra.Command {
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
cdc := clientCtx.Codec

serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config

clientCtx = client.ReadHomeFlag(clientCtx, cmd)
config.SetRoot(clientCtx.HomeDir)

config := client.GetConfigFromCmd(cmd)
chainID, _ := cmd.Flags().GetString(flags.FlagChainID)
Expand Down Expand Up @@ -137,13 +144,7 @@ func InitCmd(mm genesisMM) *cobra.Command {
return fmt.Errorf("genesis.json file already exists: %v", genFile)
}

// Overwrites the SDK default denom for side-effects
if defaultDenom != "" {
sdk.DefaultBondDenom = defaultDenom
}
appGenState := mm.DefaultGenesis()

appState, err := json.MarshalIndent(appGenState, "", " ")
appState, err := json.MarshalIndent(mbm.DefaultGenesis(cdc), "", " ")
if err != nil {
return errorsmod.Wrap(err, "Failed to marshal default genesis state")
}
Expand All @@ -160,20 +161,12 @@ func InitCmd(mm genesisMM) *cobra.Command {
}
}

appGenesis.AppName = version.AppName
appGenesis.AppVersion = version.Version
appGenesis.ChainID = chainID
appGenesis.AppState = appState
appGenesis.InitialHeight = initHeight
appGenesis.Consensus = &types.ConsensusGenesis{
Validators: nil,
Params: cmttypes.DefaultConsensusParams(),
}

appGenesis.Consensus.Params.Validator.PubKeyTypes = []string{consensusKey}
genDoc.ChainID = chainID
genDoc.Validators = nil
genDoc.AppState = appState

if err = genutil.ExportGenesisFile(appGenesis, genFile); err != nil {
return errorsmod.Wrap(err, "Failed to export genesis file")
if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil {
return errors.Wrap(err, "Failed to export gensis file")
}

toPrint := newPrintInfo(config.Moniker, chainID, nodeID, "", appState)
Expand Down

0 comments on commit c44be9e

Please sign in to comment.