Skip to content

Commit

Permalink
✨ Add migration for vesting account types
Browse files Browse the repository at this point in the history
  • Loading branch information
nnkken authored and elise-ng committed Apr 20, 2022
1 parent daa8651 commit 870a70d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions bech32-migration/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"

"github.com/likecoin/likechain/bech32-migration/utils"
)

func MigrateAddressBech32(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) {
ctx.Logger().Info("Migration of address bech32 for auth module begin")
migratedAccountCount := uint64(0)
migratedAccountTypesStat := map[string]uint64{}
utils.IterateStoreByPrefix(ctx, storeKey, types.AddressStoreKeyPrefix, func(bz []byte) []byte {
var accountI types.AccountI
err := cdc.UnmarshalInterface(bz, &accountI)
Expand All @@ -22,9 +24,31 @@ func MigrateAddressBech32(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.Bina
case *types.BaseAccount:
acc := accountI.(*types.BaseAccount)
acc.Address = utils.ConvertAccAddr(acc.Address)
migratedAccountTypesStat["BaseAccount"]++
case *types.ModuleAccount:
acc := accountI.(*types.ModuleAccount)
acc.Address = utils.ConvertAccAddr(acc.Address)
migratedAccountTypesStat["ModuleAccount"]++
case *vestingtypes.BaseVestingAccount:
acc := accountI.(*vestingtypes.BaseVestingAccount)
acc.Address = utils.ConvertAccAddr(acc.Address)
migratedAccountTypesStat["BaseVestingAccount"]++
case *vestingtypes.ContinuousVestingAccount:
acc := accountI.(*vestingtypes.ContinuousVestingAccount)
acc.Address = utils.ConvertAccAddr(acc.Address)
migratedAccountTypesStat["ContinuousVestingAccount"]++
case *vestingtypes.DelayedVestingAccount:
acc := accountI.(*vestingtypes.DelayedVestingAccount)
acc.Address = utils.ConvertAccAddr(acc.Address)
migratedAccountTypesStat["DelayedVestingAccount"]++
case *vestingtypes.PeriodicVestingAccount:
acc := accountI.(*vestingtypes.PeriodicVestingAccount)
acc.Address = utils.ConvertAccAddr(acc.Address)
migratedAccountTypesStat["PeriodicVestingAccount"]++
case *vestingtypes.PermanentLockedAccount:
acc := accountI.(*vestingtypes.PermanentLockedAccount)
acc.Address = utils.ConvertAccAddr(acc.Address)
migratedAccountTypesStat["PermanentLockedAccount"]++
default:
ctx.Logger().Info(
"Warning: unknown account type, skipping migration",
Expand All @@ -45,5 +69,6 @@ func MigrateAddressBech32(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.Bina
ctx.Logger().Info(
"Migration of address bech32 for auth module done",
"migrated_account_count", migratedAccountCount,
"migrated_account_types_stat", migratedAccountTypesStat,
)
}

0 comments on commit 870a70d

Please sign in to comment.