Skip to content

Commit c44be9e

Browse files
mergify[bot]JeancarloBarrios
authored andcommitted
fix: Allow --home to propagate to init command (backport cosmos#10104) (cosmos#10158)
1 parent c6af404 commit c44be9e

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
3838

3939
## [Unreleased]
4040

41+
### Bug Fixes
42+
43+
* (x/genutil) [#10104](https://github.com/cosmos/cosmos-sdk/pull/10104) Ensure the `init` command reads the `--home` flag value correctly.
44+
4145
## [v0.44.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.0) - 2021-09-01
4246

4347
### Features

client/cmd.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,12 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
315315
clientCtx = clientCtx.WithOutputFormat(flags.OutputFormatJSON)
316316
}
317317

318-
// If the user didn't explicitly set a --sign-mode flag, use DIRECT_AUX by default.
319-
if clientCtx.SignModeStr == "" || !flagSet.Changed(flags.FlagSignMode) {
320-
clientCtx = clientCtx.WithSignModeStr(flags.SignModeDirectAux)
321-
}
322-
}
318+
// ReadHomeFlag checks if home flag is changed. If this is a case, we update
319+
// HomeDir field of Client Context.
320+
func ReadHomeFlag(clientCtx Context, cmd *cobra.Command) Context {
321+
if cmd.Flags().Changed(flags.FlagHome) {
322+
rootDir, _ := cmd.Flags().GetString(flags.FlagHome)
323+
clientCtx = clientCtx.WithHomeDir(rootDir)
323324
}
324325

325326
return clientCtx, nil

x/genutil/client/cli/init.go

+13-20
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ func InitCmd(mm genesisMM) *cobra.Command {
7979
Args: cobra.ExactArgs(1),
8080
RunE: func(cmd *cobra.Command, args []string) error {
8181
clientCtx := client.GetClientContextFromCmd(cmd)
82+
cdc := clientCtx.Codec
83+
84+
serverCtx := server.GetServerContextFromCmd(cmd)
85+
config := serverCtx.Config
86+
87+
clientCtx = client.ReadHomeFlag(clientCtx, cmd)
88+
config.SetRoot(clientCtx.HomeDir)
8289

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

140-
// Overwrites the SDK default denom for side-effects
141-
if defaultDenom != "" {
142-
sdk.DefaultBondDenom = defaultDenom
143-
}
144-
appGenState := mm.DefaultGenesis()
145-
146-
appState, err := json.MarshalIndent(appGenState, "", " ")
147+
appState, err := json.MarshalIndent(mbm.DefaultGenesis(cdc), "", " ")
147148
if err != nil {
148149
return errorsmod.Wrap(err, "Failed to marshal default genesis state")
149150
}
@@ -160,20 +161,12 @@ func InitCmd(mm genesisMM) *cobra.Command {
160161
}
161162
}
162163

163-
appGenesis.AppName = version.AppName
164-
appGenesis.AppVersion = version.Version
165-
appGenesis.ChainID = chainID
166-
appGenesis.AppState = appState
167-
appGenesis.InitialHeight = initHeight
168-
appGenesis.Consensus = &types.ConsensusGenesis{
169-
Validators: nil,
170-
Params: cmttypes.DefaultConsensusParams(),
171-
}
172-
173-
appGenesis.Consensus.Params.Validator.PubKeyTypes = []string{consensusKey}
164+
genDoc.ChainID = chainID
165+
genDoc.Validators = nil
166+
genDoc.AppState = appState
174167

175-
if err = genutil.ExportGenesisFile(appGenesis, genFile); err != nil {
176-
return errorsmod.Wrap(err, "Failed to export genesis file")
168+
if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil {
169+
return errors.Wrap(err, "Failed to export gensis file")
177170
}
178171

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

0 commit comments

Comments
 (0)