Skip to content

Commit

Permalink
rollback last commit and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslopezf committed Mar 30, 2024
1 parent fde3134 commit 7da2294
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 37 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### Improvements

* (client) [#19905](https://github.com/cosmos/cosmos-sdk/pull/19905) Enhanced configuration template customization mechanism to use a placeholder-based approach, ensuring proper categorization and scalability of custom settings within the configuration file.
* (types) [#19869](https://github.com/cosmos/cosmos-sdk/pull/19869) Removed `Any` type from `codec/types` and replaced it with an alias for `cosmos/gogoproto/types/any`.
* (server) [#19854](https://github.com/cosmos/cosmos-sdk/pull/19854) Add customizability to start command.
* Add `StartCmdOptions` in `server.AddCommands` instead of `servertypes.ModuleInitFlags`. To set custom flags set them in the `StartCmdOptions` struct on the `AddFlags` field.
Expand Down
17 changes: 3 additions & 14 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand All @@ -24,10 +23,6 @@ func DefaultConfig() *Config {
Output: "text",
Node: "tcp://localhost:26657",
BroadcastMode: "sync",
GRPC: GRPCConfig{
Address: "",
Insecure: false,
},
}
}

Expand All @@ -42,13 +37,13 @@ type Config struct {
Output string `mapstructure:"output" json:"output"`
Node string `mapstructure:"node" json:"node"`
BroadcastMode string `mapstructure:"broadcast-mode" json:"broadcast-mode"`
GRPC GRPCConfig `mapstructure:"grpc" json:"grpc"`
GRPC GRPCConfig `mapstructure:",squash"`
}

// GRPCConfig holds the gRPC client configuration.
type GRPCConfig struct {
Address string `mapstructure:"address" json:"address"`
Insecure bool `mapstructure:"insecure" json:"insecure"`
Address string `mapstructure:"grpc-address" json:"grpc-address"`
Insecure bool `mapstructure:"grpc-insecure" json:"grpc-insecure"`
}

// ReadFromClientConfig reads values from client.toml file and updates them in client.Context
Expand Down Expand Up @@ -167,12 +162,6 @@ func CreateClientConfig(ctx client.Context, customClientTemplate string, customC
return ctx, nil
}

// CustomizeConfigTemplate inserts custom configuration settings into the default config template by replacing a predefined placeholder
// This approach prevents issues that could arise from direct concatenation, such as incorrect section categorization of custom settings.
func CustomizeConfigTemplate(customConfig string) string {
return strings.ReplaceAll(DefaultClientConfigTemplate, CustomConfigKey, customConfig)
}

// getGRPCClient creates and returns a new gRPC client connection based on the GRPCConfig.
// It determines the type of connection (secure or insecure) from the GRPCConfig and
// uses the specified server address to establish the connection.
Expand Down
7 changes: 3 additions & 4 deletions client/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ func TestCustomTemplateAndConfig(t *testing.T) {
Note: "Sent from the CLI.",
}

customConfig := `
customClientConfigTemplate := config.DefaultClientConfigTemplate + `
# This is the gas adjustment factor used by the tx commands.
# Sets the default and can be overwritten by the --gas-adjustment flag in tx commands.
gas-adjustment = {{ .GasConfig.GasAdjustment }}
# Memo to include in all transactions.
note = "{{ .Note }}"
`
customClientConfigTemplate := config.CustomizeConfigTemplate(customConfig)
t.Run("custom template and config provided", func(t *testing.T) {
clientCtx, cleanup, err := initClientContextWithTemplate(t, "", customClientConfigTemplate, customClientConfig)
defer func() {
Expand Down Expand Up @@ -197,7 +196,7 @@ func TestGRPCConfig(t *testing.T) {

require.NoError(t, err)

require.Equal(t, expectedGRPCConfig.Address, clientCtx.Viper.GetString("grpc.address"))
require.Equal(t, expectedGRPCConfig.Insecure, clientCtx.Viper.GetBool("grpc.insecure"))
require.Equal(t, expectedGRPCConfig.Address, clientCtx.Viper.GetString("grpc-address"))
require.Equal(t, expectedGRPCConfig.Insecure, clientCtx.Viper.GetBool("grpc-insecure"))
})
}
14 changes: 2 additions & 12 deletions client/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

const (
CustomConfigKey = "#{CustomConfigs}"
DefaultClientConfigTemplate = `# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
Expand All @@ -30,26 +29,17 @@ node = "{{ .Node }}"
# Transaction broadcasting mode (sync|async)
broadcast-mode = "{{ .BroadcastMode }}"
###############################################################################
### custom config ###
###############################################################################
### Custom Configurations
# The placeholder below is used for injecting custom configurations.
#{CustomConfigs}
###############################################################################
### gRPC Configuration ###
###############################################################################
[grpc]
# gRPC server endpoint to which the client will connect.
# It can be overwritten by the --grpc-addr flag in each command.
address = "{{ .GRPC.Address }}"
grpc-address = "{{ .GRPC.Address }}"
# Allow the gRPC client to connect over insecure channels.
# It can be overwritten by the --grpc-insecure flag in each command.
insecure = {{ .GRPC.Insecure }}
grpc-insecure = {{ .GRPC.Insecure }}
`
)

Expand Down
10 changes: 4 additions & 6 deletions simapp/simd/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,15 @@ func initClientConfig() (string, interface{}) {
},
}

// Create a customConfig to define specific settings.
customConfig := strings.TrimSpace(`
// The default SDK app template is defined in serverconfig.DefaultConfigTemplate.
// We append the custom config template to the default one.
// And we set the default config to the custom app template.
customClientConfigTemplate := clientconfig.DefaultClientConfigTemplate + strings.TrimSpace(`
# This is default the gas adjustment factor used in tx commands.
# It can be overwritten by the --gas-adjustment flag in each tx command.
gas-adjustment = {{ .GasConfig.GasAdjustment }}
`)

// The CustomizeConfigTemplate function is then employed to seamlessly integrate these custom settings
// into the default configuration template.
customClientConfigTemplate := clientconfig.CustomizeConfigTemplate(customConfig)

return customClientConfigTemplate, customClientConfig
}

Expand Down

0 comments on commit 7da2294

Please sign in to comment.