From dbbe52e14ab0a71dd1c95b9bae3a7cb696b8cdb0 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 25 Jun 2024 11:16:04 +0200 Subject: [PATCH] refactor(templates): Set and seal SDK global config in `app/config.go` (#4199) * refactor(templates): Set and seal SDK global config in `app/config.go` * updates --- changelog.md | 1 + .../{{binaryNamePrefix}}d/cmd/root.go.plush | 2 -- .../templates/app/files/app/config.go.plush | 19 +++++++++++++++++++ .../{{binaryNamePrefix}}d/cmd/config.go.plush | 19 ------------------- .../{{binaryNamePrefix}}d/cmd/root.go.plush | 2 -- 5 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 ignite/templates/app/files/app/config.go.plush diff --git a/changelog.md b/changelog.md index bc07100998..57fcf1007b 100644 --- a/changelog.md +++ b/changelog.md @@ -53,6 +53,7 @@ - [#4128](https://github.com/ignite/cli/pull/4128) Check for duplicate proto fields in config - [#4184](https://github.com/ignite/cli/pull/4184) Set custom `InitChainer` because of manually registered modules - [#4198](https://github.com/ignite/cli/pull/4198) Set correct prefix overwriting in `buf.gen.pulsar.yaml` +- [#4199](https://github.com/ignite/cli/pull/4199) Set and seal SDK global config in `app/config.go` ## [`v28.4.0`](https://github.com/ignite/cli/releases/tag/v28.4.0) diff --git a/ignite/templates/app/files-consumer/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush b/ignite/templates/app/files-consumer/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush index 72ade797d1..d0935d9bad 100644 --- a/ignite/templates/app/files-consumer/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush +++ b/ignite/templates/app/files-consumer/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush @@ -26,8 +26,6 @@ import ( // NewRootCmd creates a new root command for <%= BinaryNamePrefix %>d. It is called once in the main function. func NewRootCmd() *cobra.Command { - initSDKConfig() - var ( autoCliOpts autocli.AppOptions moduleBasicManager module.BasicManager diff --git a/ignite/templates/app/files/app/config.go.plush b/ignite/templates/app/files/app/config.go.plush new file mode 100644 index 0000000000..a36981bf73 --- /dev/null +++ b/ignite/templates/app/files/app/config.go.plush @@ -0,0 +1,19 @@ +package app + +import sdk "github.com/cosmos/cosmos-sdk/types" + +func init() { + // Set prefixes + accountPubKeyPrefix := AccountAddressPrefix + "pub" + validatorAddressPrefix := AccountAddressPrefix + "valoper" + validatorPubKeyPrefix := AccountAddressPrefix + "valoperpub" + consNodeAddressPrefix := AccountAddressPrefix + "valcons" + consNodePubKeyPrefix := AccountAddressPrefix + "valconspub" + + // Set and seal config + config := sdk.GetConfig() + config.SetBech32PrefixForAccount(AccountAddressPrefix, accountPubKeyPrefix) + config.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix) + config.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix) + config.Seal() +} \ No newline at end of file diff --git a/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/config.go.plush b/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/config.go.plush index 87989cd04d..a14ebc57c3 100644 --- a/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/config.go.plush +++ b/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/config.go.plush @@ -3,27 +3,8 @@ package cmd import ( cmtcfg "github.com/cometbft/cometbft/config" serverconfig "github.com/cosmos/cosmos-sdk/server/config" - sdk "github.com/cosmos/cosmos-sdk/types" - - "<%= ModulePath %>/app" ) -func initSDKConfig() { - // Set prefixes - accountPubKeyPrefix := app.AccountAddressPrefix + "pub" - validatorAddressPrefix := app.AccountAddressPrefix + "valoper" - validatorPubKeyPrefix := app.AccountAddressPrefix + "valoperpub" - consNodeAddressPrefix := app.AccountAddressPrefix + "valcons" - consNodePubKeyPrefix := app.AccountAddressPrefix + "valconspub" - - // Set and seal config - config := sdk.GetConfig() - config.SetBech32PrefixForAccount(app.AccountAddressPrefix, accountPubKeyPrefix) - config.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix) - config.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix) - config.Seal() -} - // initCometBFTConfig helps to override default CometBFT Config values. // return cmtcfg.DefaultConfig if no custom configuration is required for the application. func initCometBFTConfig() *cmtcfg.Config { diff --git a/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush b/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush index d169668b63..b70ceeb846 100644 --- a/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush +++ b/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush @@ -25,8 +25,6 @@ import ( // NewRootCmd creates a new root command for <%= BinaryNamePrefix %>d. It is called once in the main function. func NewRootCmd() *cobra.Command { - initSDKConfig() - var ( autoCliOpts autocli.AppOptions moduleBasicManager module.BasicManager