Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate SetFullFundraiserPath in favor of SetPurpose and SetCoinType #8629

Merged
merged 13 commits into from
Feb 22, 2021
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/gov) [\#8473](https://github.com/cosmos/cosmos-sdk/pull/8473) On genesis init, if the gov module account balance, coming from bank module state, does not match the one in gov module state, the initialization will panic.
* (x/distribution) [\#8473](https://github.com/cosmos/cosmos-sdk/pull/8473) On genesis init, if the distribution module account balance, coming from bank module state, does not match the one in distribution module state, the initialization will panic.
* (client/keys) [\#8500](https://github.com/cosmos/cosmos-sdk/pull/8500) `InfoImporter` interface is removed from legacy keybase.
* [\#8629](https://github.com/cosmos/cosmos-sdk/pull/8629) Removed `SetFullFundraiserPath` from `Config` in favor of `SetPurpose` and `SetCoinType`.
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved

### State Machine Breaking

Expand Down
4 changes: 2 additions & 2 deletions client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
bech32PrefixConsAddr := "terravalcons"
bech32PrefixConsPub := "terravalconspub"

config.SetPurpose(44)
config.SetCoinType(330)
config.SetFullFundraiserPath("44'/330'/0'/0/0")
config.SetBech32PrefixForAccount(bech32PrefixAccAddr, bech32PrefixAccPub)
config.SetBech32PrefixForValidator(bech32PrefixValAddr, bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(bech32PrefixConsAddr, bech32PrefixConsPub)
Expand Down Expand Up @@ -77,8 +77,8 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
"terrapub1addwnpepqvpg7r26nl2pvqqern00m6s9uaax3hauu2rzg8qpjzq9hy6xve7sw0d84m6",
sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, key1.GetPubKey()))

config.SetPurpose(44)
config.SetCoinType(118)
config.SetFullFundraiserPath("44'/118'/0'/0/0")
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
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 @@ -31,7 +31,7 @@ func Test_runDeleteCmd(t *testing.T) {
fakeKeyName1 := "runDeleteCmd_Key1"
fakeKeyName2 := "runDeleteCmd_Key2"

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

kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn)
require.NoError(t, err)
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 @@ -31,7 +31,7 @@ func Test_runExportCmd(t *testing.T) {
kb.Delete("keyname1") // nolint:errcheck
})

path := sdk.GetConfig().GetFullFundraiserPath()
path := sdk.GetConfig().GetFullBIP44Path()
_, err = kb.NewAccount("keyname1", testutil.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 @@ -30,7 +30,7 @@ func Test_runListCmd(t *testing.T) {
clientCtx := client.Context{}.WithKeyring(kb)
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)

path := "" //sdk.GetConfig().GetFullFundraiserPath()
path := "" //sdk.GetConfig().GetFullBIP44Path()
_, err = kb.NewAccount("something", testutil.TestMnemonic, "", path, hd.Secp256k1)
require.NoError(t, err)

Expand Down
5 changes: 4 additions & 1 deletion types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ const (
// config.SetBech32PrefixForAccount(yourBech32PrefixAccAddr, yourBech32PrefixAccPub)
// config.SetBech32PrefixForValidator(yourBech32PrefixValAddr, yourBech32PrefixValPub)
// config.SetBech32PrefixForConsensusNode(yourBech32PrefixConsAddr, yourBech32PrefixConsPub)
// config.SetPurpose(yourPurpose)
// config.SetCoinType(yourCoinType)
// config.SetFullFundraiserPath(yourFullFundraiserPath)
// config.Seal()

// Bech32MainPrefix defines the main SDK Bech32 prefix of an account's address
Bech32MainPrefix = "cosmos"

// Purpose is the ATOM purpose as defined in SLIP44 (https://github.com/satoshilabs/slips/blob/master/slip-0044.md)
Purpose = 44

// CoinType is the ATOM coin type as defined in SLIP44 (https://github.com/satoshilabs/slips/blob/master/slip-0044.md)
CoinType = 118

Expand Down
49 changes: 38 additions & 11 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"context"
"fmt"
"sync"

"github.com/cosmos/cosmos-sdk/version"
Expand All @@ -18,9 +19,13 @@ type Config struct {
txEncoder TxEncoder
addressVerifier func([]byte) error
mtx sync.RWMutex
coinType uint32
sealed bool
sealedch chan struct{}

// SLIP-44 related
purpose uint32
coinType uint32

sealed bool
sealedch chan struct{}
}

// cosmos-sdk wide global singleton
Expand All @@ -41,9 +46,11 @@ func NewConfig() *Config {
"validator_pub": Bech32PrefixValPub,
"consensus_pub": Bech32PrefixConsPub,
},
coinType: CoinType,
fullFundraiserPath: FullFundraiserPath,
txEncoder: nil,

purpose: Purpose,
coinType: CoinType,
txEncoder: nil,
}
}

Expand Down Expand Up @@ -112,16 +119,24 @@ func (config *Config) SetAddressVerifier(addressVerifier func([]byte) error) {
config.addressVerifier = addressVerifier
}

// Set the BIP-0044 CoinType code on the config
func (config *Config) SetCoinType(coinType uint32) {
// Set the FullFundraiserPath (BIP44Prefix) on the config.
//
// Deprecated: This method is supported for backward compatibility only and will be removed in a future release. Use SetPurpose and SetCoinType instead.
func (config *Config) SetFullFundraiserPath(fullFundraiserPath string) {
config.assertNotSealed()
config.coinType = coinType
config.fullFundraiserPath = fullFundraiserPath
}

// Set the FullFundraiserPath (BIP44Prefix) on the config
func (config *Config) SetFullFundraiserPath(fullFundraiserPath string) {
// Set the BIP-0044 Purpose code on the config
func (config *Config) SetPurpose(purpose uint32) {
config.assertNotSealed()
config.fullFundraiserPath = fullFundraiserPath
config.purpose = purpose
}

// Set the BIP-0044 CoinType code on the config
func (config *Config) SetCoinType(coinType uint32) {
config.assertNotSealed()
config.coinType = coinType
}

// Seal seals the config such that the config state could not be modified further
Expand Down Expand Up @@ -181,16 +196,28 @@ func (config *Config) GetAddressVerifier() func([]byte) error {
return config.addressVerifier
}

// GetPurpose returns the BIP-0044 Purpose code on the config.
func (config *Config) GetPurpose() uint32 {
return config.purpose
}

// GetCoinType returns the BIP-0044 CoinType code on the config.
func (config *Config) GetCoinType() uint32 {
return config.coinType
}

// GetFullFundraiserPath returns the BIP44Prefix.
//
// Deprecated: This method is supported for backward compatibility only and will be removed in a future release. Use GetFullBIP44Path instead.
func (config *Config) GetFullFundraiserPath() string {
return config.fullFundraiserPath
}

// GetFullBIP44Path returns the BIP44Prefix.
func (config *Config) GetFullBIP44Path() string {
return fmt.Sprintf("m/%d'/%d'/0'/0/0", config.purpose, config.coinType)
}

func KeyringServiceName() string {
if len(version.Name) == 0 {
return DefaultKeyringServiceName
Expand Down
12 changes: 12 additions & 0 deletions types/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ func TestConfigTestSuite(t *testing.T) {
suite.Run(t, new(configTestSuite))
}

func (s *contextTestSuite) TestConfig_SetPurpose() {
config := sdk.NewConfig()
config.SetPurpose(44)
s.Require().Equal(uint32(44), config.GetPurpose())

config.SetPurpose(0)
s.Require().Equal(uint32(0), config.GetPurpose())

config.Seal()
s.Require().Panics(func() { config.SetPurpose(10) })
}

func (s *configTestSuite) TestConfig_SetCoinType() {
config := sdk.NewConfig()
config.SetCoinType(1)
Expand Down
3 changes: 2 additions & 1 deletion x/authz/types/authorization_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package types
import (
"time"

proto "github.com/gogo/protobuf/proto"

"github.com/cosmos/cosmos-sdk/codec/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/authz/exported"
proto "github.com/gogo/protobuf/proto"
)

// NewAuthorizationGrant returns new AuthrizationGrant
Expand Down
3 changes: 2 additions & 1 deletion x/staking/types/authz.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package types

import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authz "github.com/cosmos/cosmos-sdk/x/authz/exported"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion x/staking/types/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
)

var (
Expand Down