-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 0.39 x/auth Migration Types (#6870)
* types: add coins to JSON * add migrate test * finish test * Add panic * fix test
- Loading branch information
1 parent
3ff3e58
commit 72f6bf0
Showing
8 changed files
with
217 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.