fix(simapp): fix default home (backport #19393) (#19399)

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
mergify[bot] 2024-02-12 11:07:59 +00:00 committed by GitHub
parent e738785539
commit fe2f853d98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 2 deletions

View File

@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]
### Improvements
* (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.
### Bug Fixes
* (baseapp) [#19338](https://github.com/cosmos/cosmos-sdk/pull/19338) Set HeaderInfo in context when calling `setState`.

View File

@ -46,6 +46,26 @@ func (c *ClientConfig) SetBroadcastMode(broadcastMode string) {
c.BroadcastMode = broadcastMode
}
// 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) (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 = ReadFromClientConfig(ctx)
if err != nil {
return ctx, fmt.Errorf("couldn't create client config: %w", err)
}
ctx.HomeDir = prevHomeDir
return ctx, nil
}
// ReadFromClientConfig reads values from client.toml file and updates them in client Context
func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
configPath := filepath.Join(ctx.HomeDir, "config")

View File

@ -100,7 +100,7 @@ func NewRootCmd() *cobra.Command {
// add keyring to autocli opts
autoCliOpts := tempApp.AutoCliOpts()
initClientCtx, _ = config.ReadFromClientConfig(initClientCtx)
initClientCtx, _ = config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx)
autoCliOpts.Keyring, _ = keyring.NewAutoCLIKeyring(initClientCtx.Keyring)
autoCliOpts.ClientCtx = initClientCtx

View File

@ -109,7 +109,7 @@ func ProvideClientContext(
WithViper("") // In simapp, we don't use any prefix for env variables.
// Read the config again to overwrite the default values with the values from the config file
clientCtx, _ = config.ReadFromClientConfig(clientCtx)
clientCtx, _ = config.ReadDefaultValuesFromDefaultClientConfig(clientCtx)
// textual is enabled by default, we need to re-create the tx config grpc instead of bank keeper.
txConfigOpts.TextualCoinMetadataQueryFn = authtxconfig.NewGRPCCoinMetadataQueryFn(clientCtx)