diff --git a/CHANGELOG.md b/CHANGELOG.md index ad97108cf7c..d647e313834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/client/config/config.go b/client/config/config.go index 4cb0faa1203..efe65bd34ec 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -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. diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index d66a4accfda..24ed158ee4b 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -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) } diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_v2.go index aacf8a21d57..3b207a1a015 100644 --- a/simapp/simd/cmd/root_v2.go +++ b/simapp/simd/cmd/root_v2.go @@ -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) }