Skip to content

Commit

Permalink
refactor(templates): Set and seal SDK global config in app/config.go (
Browse files Browse the repository at this point in the history
#4199)

* refactor(templates): Set and seal SDK global config in `app/config.go`

* updates
  • Loading branch information
julienrbrt authored Jun 25, 2024
1 parent 967df1b commit dbbe52e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions ignite/templates/app/files/app/config.go.plush
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dbbe52e

Please sign in to comment.