Skip to content

Commit

Permalink
more NewConfig()
Browse files Browse the repository at this point in the history
  • Loading branch information
prasincs committed Jan 15, 2025
1 parent ac48388 commit aeb2e0f
Show file tree
Hide file tree
Showing 21 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions client/debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ func PrefixesCmd() *cobra.Command {
Long: "List prefixes used in Bech32 addresses.",
Example: fmt.Sprintf("$ %s debug prefixes", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Printf("Bech32 Acc: %s\n", sdk.GetConfig().GetBech32AccountAddrPrefix())
cmd.Printf("Bech32 Val: %s\n", sdk.GetConfig().GetBech32ValidatorAddrPrefix())
cmd.Printf("Bech32 Con: %s\n", sdk.GetConfig().GetBech32ConsensusAddrPrefix())
cmd.Printf("Bech32 Acc: %s\n", sdk.NewConfig().GetBech32AccountAddrPrefix())
cmd.Printf("Bech32 Val: %s\n", sdk.NewConfig().GetBech32ValidatorAddrPrefix())
cmd.Printf("Bech32 Con: %s\n", sdk.NewConfig().GetBech32ConsensusAddrPrefix())
return nil
},
}
Expand Down
4 changes: 2 additions & 2 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Example:
f.Bool(flagNoBackup, false, "Don't print out seed phrase (if others are watching the terminal)")
f.Bool(flags.FlagDryRun, false, "Perform action, but don't add key to local keystore")
f.String(flagHDPath, "", "Manual HD Path derivation (overrides BIP44 config)")
f.Uint32(flagCoinType, sdk.GetConfig().GetCoinType(), "coin type number for HD derivation")
f.Uint32(flagCoinType, sdk.NewConfig().GetCoinType(), "coin type number for HD derivation")
f.Uint32(flagAccount, 0, "Account number for HD derivation (less than equal 2147483647)")
f.Uint32(flagIndex, 0, "Address index number for HD derivation (less than equal 2147483647)")
f.String(flags.FlagKeyType, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for")
Expand Down Expand Up @@ -266,7 +266,7 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf

// If we're using ledger, only thing we need is the path and the bech32 prefix.
if useLedger {
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
bech32PrefixAccAddr := sdk.NewConfig().GetBech32AccountAddrPrefix()
k, err := kb.SaveLedgerKey(name, hd.Secp256k1, bech32PrefixAccAddr, coinType, account, index)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
config := sdk.GetConfig()
config := sdk.NewConfig()

bech32PrefixAccAddr := "terra"
bech32PrefixAccPub := "terrapub"
Expand Down
2 changes: 1 addition & 1 deletion client/keys/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func Test_runAddCmdDryRun(t *testing.T) {
WithKeyring(kb)
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)

path := sdk.GetConfig().GetFullBIP44Path()
path := sdk.NewConfig().GetFullBIP44Path()
_, err = kb.NewAccount("subkey", testdata.TestMnemonic, "", path, hd.Secp256k1)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion client/keys/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Test_runDeleteCmd(t *testing.T) {
fakeKeyName1 := "runDeleteCmd_Key1"
fakeKeyName2 := "runDeleteCmd_Key2"

path := sdk.GetConfig().GetFullBIP44Path()
path := sdk.NewConfig().GetFullBIP44Path()
cdc := moduletestutil.MakeTestEncodingConfig().Codec

cmd.SetArgs([]string{"blah", fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome)})
Expand Down
2 changes: 1 addition & 1 deletion client/keys/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func Test_runExportCmd(t *testing.T) {
require.NoError(t, err)
t.Cleanup(cleanupKeys(t, kb, "keyname1"))

path := sdk.GetConfig().GetFullBIP44Path()
path := sdk.NewConfig().GetFullBIP44Path()
_, err = kb.NewAccount("keyname1", testdata.TestMnemonic, "", path, hd.Secp256k1)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion client/keys/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func Test_runListCmd(t *testing.T) {
clientCtx := client.Context{}.WithKeyring(kb)
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)

path := "" // sdk.GetConfig().GetFullBIP44Path()
path := "" // sdk.NewConfig().GetFullBIP44Path()
_, err = kb.NewAccount("something", testdata.TestMnemonic, "", path, hd.Secp256k1)
assert.NilError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion client/keys/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Test_runRenameCmd(t *testing.T) {
fakeKeyName1 := "runRenameCmd_Key1"
fakeKeyName2 := "runRenameCmd_Key2"

path := sdk.GetConfig().GetFullBIP44Path()
path := sdk.NewConfig().GetFullBIP44Path()

cdc := moduletestutil.MakeTestEncodingConfig().Codec
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc)
Expand Down
2 changes: 1 addition & 1 deletion client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
return err
}

return ledger.ShowAddress(*ledgerItem.Path, pk, sdk.GetConfig().GetBech32AccountAddrPrefix())
return ledger.ShowAddress(*ledgerItem.Path, pk, sdk.NewConfig().GetBech32AccountAddrPrefix())
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion crypto/ledger/ledger_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (mock LedgerSECP256K1Mock) GetPublicKeySECP256K1(derivationPath []uint32) (
return nil, errors.New("invalid derivation path")
}

if derivationPath[1] != sdk.GetConfig().GetCoinType() {
if derivationPath[1] != sdk.NewConfig().GetCoinType() {
return nil, errors.New("invalid derivation path")
}

Expand Down
2 changes: 1 addition & 1 deletion crypto/ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestPublicKeySafe(t *testing.T) {

require.NoError(t, err)
require.NotNil(t, priv)
require.Nil(t, ShowAddress(path, priv.PubKey(), sdk.GetConfig().GetBech32AccountAddrPrefix()))
require.Nil(t, ShowAddress(path, priv.PubKey(), sdk.NewConfig().GetBech32AccountAddrPrefix()))
checkDefaultPubKey(t, priv)

addr2 := sdk.AccAddress(priv.PubKey().Address()).String()
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewGRPCServer(clientCtx client.Context, app types.Application, cfg config.G
return modes
}(),
ChainID: clientCtx.ChainID,
SdkConfig: sdk.GetConfig(),
SdkConfig: sdk.NewConfig(),
InterfaceRegistry: clientCtx.InterfaceRegistry,
})
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ func NewSimApp(
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
AddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
Bech32Prefix: sdk.NewConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
Bech32Prefix: sdk.NewConfig().GetBech32ValidatorAddrPrefix(),
},
},
})
Expand Down Expand Up @@ -674,9 +674,9 @@ func (app *SimApp) AutoCliOpts() autocli.AppOptions {
return autocli.AppOptions{
Modules: modules,
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.ModuleManager.Modules),
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
AddressCodec: authcodec.NewBech32Codec(sdk.NewConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.NewConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.NewConfig().GetBech32ConsensusAddrPrefix()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func initRootCmd(
txConfig client.TxConfig,
basicManager module.BasicManager,
) {
cfg := sdk.GetConfig()
cfg := sdk.NewConfig()
cfg.Seal()

rootCmd.AddCommand(
Expand Down
6 changes: 3 additions & 3 deletions testutil/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func GenerateCoinKey(algo keyring.SignatureAlgo, cdc codec.Codec) (sdk.AccAddres
info, secret, err := keyring.NewInMemory(cdc).NewMnemonic(
"name",
keyring.English,
sdk.GetConfig().GetFullBIP44Path(),
sdk.NewConfig().GetFullBIP44Path(),
keyring.DefaultBIP39Passphrase,
algo,
)
Expand Down Expand Up @@ -63,9 +63,9 @@ func GenerateSaveCoinKey(
// generate or recover a new account
if mnemonic != "" {
secret = mnemonic
record, err = keybase.NewAccount(keyName, mnemonic, keyring.DefaultBIP39Passphrase, sdk.GetConfig().GetFullBIP44Path(), algo)
record, err = keybase.NewAccount(keyName, mnemonic, keyring.DefaultBIP39Passphrase, sdk.NewConfig().GetFullBIP44Path(), algo)
} else {
record, secret, err = keybase.NewMnemonic(keyName, keyring.English, sdk.GetConfig().GetFullBIP44Path(), keyring.DefaultBIP39Passphrase, algo)
record, secret, err = keybase.NewMnemonic(keyName, keyring.English, sdk.NewConfig().GetFullBIP44Path(), keyring.DefaultBIP39Passphrase, algo)
}
if err != nil {
return sdk.AccAddress{}, "", err
Expand Down
2 changes: 1 addition & 1 deletion types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
// You can use the specific values for your project.
// Add the follow lines to the `main()` of your server.
//
// config := sdk.GetConfig()
// config := sdk.NewConfig()
// config.SetBech32PrefixForAccount(yourBech32PrefixAccAddr, yourBech32PrefixAccPub)
// config.SetBech32PrefixForValidator(yourBech32PrefixValAddr, yourBech32PrefixValPub)
// config.SetBech32PrefixForConsensusNode(yourBech32PrefixConsAddr, yourBech32PrefixConsPub)
Expand Down
2 changes: 1 addition & 1 deletion types/bech32/legacybech32/pk.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func MustMarshalPubKey(pkt Bech32PubKeyType, pubkey cryptotypes.PubKey) string {
}

func getPrefix(pkt Bech32PubKeyType) string {
cfg := sdk.GetConfig()
cfg := sdk.NewConfig()
switch pkt {
case AccPK:
return cfg.GetBech32AccountPubPrefix()
Expand Down
2 changes: 1 addition & 1 deletion x/auth/tx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMod
// NewDefaultSigningOptions returns the sdk default signing options used by x/tx. This includes account and
// validator address prefix enabled codecs.
func NewDefaultSigningOptions() (*txsigning.Options, error) {
sdkConfig := sdk.GetConfig()
sdkConfig := sdk.NewConfig()
return &txsigning.Options{
AddressCodec: authcodec.NewBech32Codec(sdkConfig.GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdkConfig.GetBech32ValidatorAddrPrefix()),
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func newSplitAndApply(

// NewWithdrawRewardsCmd returns a CLI command handler for creating a MsgWithdrawDelegatorReward transaction.
func NewWithdrawRewardsCmd(valCodec, ac address.Codec) *cobra.Command {
bech32PrefixValAddr := sdk.GetConfig().GetBech32ValidatorAddrPrefix()
bech32PrefixValAddr := sdk.NewConfig().GetBech32ValidatorAddrPrefix()

cmd := &cobra.Command{
Use: "withdraw-rewards [validator-addr]",
Expand Down Expand Up @@ -191,7 +191,7 @@ $ %[1]s tx distribution withdraw-all-rewards --from mykey

// NewSetWithdrawAddrCmd returns a CLI command handler for creating a MsgSetWithdrawAddress transaction.
func NewSetWithdrawAddrCmd(ac address.Codec) *cobra.Command {
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
bech32PrefixAccAddr := sdk.NewConfig().GetBech32AccountAddrPrefix()

cmd := &cobra.Command{
Use: "set-withdraw-addr [withdraw-addr]",
Expand Down
4 changes: 2 additions & 2 deletions x/evidence/types/evidence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func TestEquivocationValidateBasic(t *testing.T) {
}

func TestEvidenceAddressConversion(t *testing.T) {
sdk.GetConfig().SetBech32PrefixForConsensusNode("testcnclcons", "testcnclconspub")
sdk.NewConfig().SetBech32PrefixForConsensusNode("testcnclcons", "testcnclconspub")
tmEvidence := NewCometMisbehavior(1, 100, time.Now(), comet.DuplicateVote,
validator{address: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, power: 100})

evidence := types.FromABCIEvidence(tmEvidence, address.NewBech32Codec("testcnclcons"))
consAddr := evidence.GetConsensusAddress(address.NewBech32Codec("testcnclcons"))
// Check the address is the same after conversion
require.Equal(t, tmEvidence.Validator().Address(), consAddr.Bytes())
sdk.GetConfig().SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
sdk.NewConfig().SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
}

type Misbehavior struct {
Expand Down
4 changes: 2 additions & 2 deletions x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ $ %s tx staking redelegate cosmosvalopers1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj

// NewUnbondCmd returns a CLI command handler for creating a MsgUndelegate transaction.
func NewUnbondCmd(valAddrCodec, ac address.Codec) *cobra.Command {
bech32PrefixValAddr := sdk.GetConfig().GetBech32ValidatorAddrPrefix()
bech32PrefixValAddr := sdk.NewConfig().GetBech32ValidatorAddrPrefix()

cmd := &cobra.Command{
Use: "unbond [validator-addr] [amount]",
Expand Down Expand Up @@ -326,7 +326,7 @@ $ %s tx staking unbond %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100stake --from

// NewCancelUnbondingDelegation returns a CLI command handler for creating a MsgCancelUnbondingDelegation transaction.
func NewCancelUnbondingDelegation(valAddrCodec, ac address.Codec) *cobra.Command {
bech32PrefixValAddr := sdk.GetConfig().GetBech32ValidatorAddrPrefix()
bech32PrefixValAddr := sdk.NewConfig().GetBech32ValidatorAddrPrefix()

cmd := &cobra.Command{
Use: "cancel-unbond [validator-addr] [amount] [creation-height]",
Expand Down

0 comments on commit aeb2e0f

Please sign in to comment.