Skip to content

Commit

Permalink
fix(simapp): fix default home (#19393)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Feb 10, 2024
1 parent d3120f5 commit 72a56d9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (abci): [#19200](https://github.com/cosmos/cosmos-sdk/pull/19200) Ensure that sdk side ve math matches cometbft
* (server) [#18994](https://github.com/cosmos/cosmos-sdk/pull/18994) Update server context directly rather than a reference to a sub-object
* (crypto) [#19371](https://github.com/cosmos/cosmos-sdk/pull/19371) Avoid cli redundant log in stdout, log to stderr instead.

* (client) [#19393](https://github.com/cosmos/cosmos-sdk/pull/19393/) Add `ReadDefaultValuesFromDefaultClientConfig` to populate the default values from the default client config in client.Context without creating a app folder.

### API Breaking Changes

* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `x/genutil` now handles the application export. `server.AddCommands` does not take an `AppExporter` but instead `genutilcli.Commands` does.
Expand Down
21 changes: 21 additions & 0 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,31 @@ type Config struct {

// ReadFromClientConfig reads values from client.toml file and updates them in client.Context
// It uses CreateClientConfig internally with no custom template and custom config.
// Deprecated: use CreateClientConfig instead.
func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
return CreateClientConfig(ctx, "", nil)
}

// ReadDefaultValuesFromDefaultClientConfig reads default values from default client.toml file and updates them in client.Context
// The client.toml is then discarded.
func ReadDefaultValuesFromDefaultClientConfig(ctx client.Context, customClientTemplate string, customConfig interface{}) (client.Context, error) {
prevHomeDir := ctx.HomeDir
dir, err := os.MkdirTemp("", "simapp")
if err != nil {
return ctx, fmt.Errorf("couldn't create temp dir: %w", err)
}
defer os.RemoveAll(dir)

ctx.HomeDir = dir
ctx, err = CreateClientConfig(ctx, customClientTemplate, customConfig)
if err != nil {
return ctx, fmt.Errorf("couldn't create client config: %w", err)
}

ctx.HomeDir = prevHomeDir
return ctx, nil
}

// CreateClientConfig reads the client.toml file and returns a new populated client.Context
// If the client.toml file does not exist, it creates one with default values.
// It takes a customClientTemplate and customConfig as input that can be used to overwrite the default config and enhance the client.toml file.
Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func NewRootCmd() *cobra.Command {
// autocli opts
customClientTemplate, customClientConfig := initClientConfig()
var err error
initClientCtx, err = config.CreateClientConfig(initClientCtx, customClientTemplate, customClientConfig)
initClientCtx, err = config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx, customClientTemplate, customClientConfig)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/root_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func ProvideClientContext(

// Read the config to overwrite the default values with the values from the config file
customClientTemplate, customClientConfig := initClientConfig()
clientCtx, err = config.CreateClientConfig(clientCtx, customClientTemplate, customClientConfig)
clientCtx, err = config.ReadDefaultValuesFromDefaultClientConfig(clientCtx, customClientTemplate, customClientConfig)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 72a56d9

Please sign in to comment.