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

Backport 0.39.1: Launchpad Migration #6829 #6869

Merged
merged 7 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions x/auth/legacy/v0_38/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func Migrate(authGenState v036auth.GenesisState, genAccountsGenState v036genacco
accounts[i] = genAccount
}

accounts = sanitizeGenesisAccounts(accounts)
accounts = SanitizeGenesisAccounts(accounts)

if err := validateGenAccounts(accounts); err != nil {
if err := ValidateGenAccounts(accounts); err != nil {
panic(err)
}

Expand Down
18 changes: 9 additions & 9 deletions x/auth/legacy/v0_38/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ type (

BaseAccount struct {
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins" yaml:"coins"`
Coins sdk.Coins `json:"coins,omitempty" yaml:"coins,omitempty"`
PubKey crypto.PubKey `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
}

baseAccountPretty struct {
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins" yaml:"coins"`
Coins sdk.Coins `json:"coins,omitempty" yaml:"coins,omitempty"`
PubKey string `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
Expand All @@ -72,7 +72,7 @@ type (

vestingAccountPretty struct {
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins" yaml:"coins"`
Coins sdk.Coins `json:"coins,omitempty" yaml:"coins,omitempty"`
PubKey string `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
Expand Down Expand Up @@ -104,7 +104,7 @@ type (

moduleAccountPretty struct {
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins" yaml:"coins"`
Coins sdk.Coins `json:"coins,omitempty" yaml:"coins,omitempty"`
PubKey string `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
Expand Down Expand Up @@ -434,7 +434,7 @@ func NewModuleAccount(baseAccount *BaseAccount, name string, permissions ...stri
}

func (ma ModuleAccount) Validate() error {
if err := validatePermissions(ma.Permissions...); err != nil {
if err := ValidatePermissions(ma.Permissions...); err != nil {
return err
}

Expand Down Expand Up @@ -476,7 +476,7 @@ func (ma *ModuleAccount) UnmarshalJSON(bz []byte) error {
return nil
}

func validatePermissions(permissions ...string) error {
func ValidatePermissions(permissions ...string) error {
for _, perm := range permissions {
if strings.TrimSpace(perm) == "" {
return fmt.Errorf("module permission is empty")
Expand All @@ -486,7 +486,7 @@ func validatePermissions(permissions ...string) error {
return nil
}

func sanitizeGenesisAccounts(genAccounts GenesisAccounts) GenesisAccounts {
func SanitizeGenesisAccounts(genAccounts GenesisAccounts) GenesisAccounts {
sort.Slice(genAccounts, func(i, j int) bool {
return genAccounts[i].GetAccountNumber() < genAccounts[j].GetAccountNumber()
})
Expand All @@ -500,7 +500,7 @@ func sanitizeGenesisAccounts(genAccounts GenesisAccounts) GenesisAccounts {
return genAccounts
}

func validateGenAccounts(genAccounts GenesisAccounts) error {
func ValidateGenAccounts(genAccounts GenesisAccounts) error {
addrMap := make(map[string]bool, len(genAccounts))
for _, acc := range genAccounts {

Expand All @@ -524,7 +524,7 @@ func validateGenAccounts(genAccounts GenesisAccounts) error {
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterInterface((*GenesisAccount)(nil), nil)
cdc.RegisterInterface((*Account)(nil), nil)
cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/Account", nil)
cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil)
cdc.RegisterConcrete(&BaseVestingAccount{}, "cosmos-sdk/BaseVestingAccount", nil)
cdc.RegisterConcrete(&ContinuousVestingAccount{}, "cosmos-sdk/ContinuousVestingAccount", nil)
cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil)
Expand Down
60 changes: 60 additions & 0 deletions x/auth/legacy/v0_39/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package v039

import (
"fmt"

v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
)

// Migrate accepts exported genesis state from v0.38 and migrates it to v0.39
// genesis state.
func Migrate(oldAuthGenState v038auth.GenesisState) GenesisState {
accounts := make(v038auth.GenesisAccounts, len(oldAuthGenState.Accounts))

for i, acc := range oldAuthGenState.Accounts {
switch t := acc.(type) {
case *v038auth.BaseAccount:
accounts[i] = NewBaseAccount(t.Address, t.Coins, t.PubKey, t.AccountNumber, t.Sequence)

case *v038auth.BaseVestingAccount:
accounts[i] = NewBaseVestingAccount(
NewBaseAccount(t.Address, t.Coins, t.PubKey, t.AccountNumber, t.Sequence),
t.OriginalVesting, t.DelegatedFree, t.DelegatedVesting, t.EndTime,
)

case *v038auth.ContinuousVestingAccount:
accounts[i] = NewContinuousVestingAccountRaw(
NewBaseVestingAccount(
NewBaseAccount(t.Address, t.Coins, t.PubKey, t.AccountNumber, t.Sequence),
t.OriginalVesting, t.DelegatedFree, t.DelegatedVesting, t.EndTime,
),
t.StartTime,
)

case *v038auth.DelayedVestingAccount:
accounts[i] = NewDelayedVestingAccountRaw(
NewBaseVestingAccount(
NewBaseAccount(t.Address, t.Coins, t.PubKey, t.AccountNumber, t.Sequence),
t.OriginalVesting, t.DelegatedFree, t.DelegatedVesting, t.EndTime,
),
)

case *v038auth.ModuleAccount:
accounts[i] = NewModuleAccount(
NewBaseAccount(t.Address, t.Coins, t.PubKey, t.AccountNumber, t.Sequence),
t.Name, t.Permissions...,
)

default:
panic(fmt.Sprintf("unexpected account type: %T", acc))
}
}

accounts = v038auth.SanitizeGenesisAccounts(accounts)

if err := v038auth.ValidateGenAccounts(accounts); err != nil {
panic(err)
}

return NewGenesisState(oldAuthGenState.Params, accounts)
}
Loading