|
| 1 | +package v11_15_0 |
| 2 | + |
| 3 | +import ( |
| 4 | + "cosmossdk.io/errors" |
| 5 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 6 | + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" |
| 7 | + "github.com/cosmos/cosmos-sdk/types/module" |
| 8 | + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" |
| 9 | + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" |
| 10 | + |
| 11 | + "github.com/persistenceOne/persistenceCore/v11/app/upgrades" |
| 12 | +) |
| 13 | + |
| 14 | +func CreateUpgradeHandler(args upgrades.UpgradeHandlerArgs) upgradetypes.UpgradeHandler { |
| 15 | + return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { |
| 16 | + ctx.Logger().Info("running module migrations...") |
| 17 | + err := MigrateVestingAccounts(ctx, args) |
| 18 | + if err != nil { |
| 19 | + return vm, err |
| 20 | + } |
| 21 | + return args.ModuleManager.RunMigrations(ctx, args.Configurator, vm) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +func MigrateVestingAccounts(ctx sdk.Context, args upgrades.UpgradeHandlerArgs) error { |
| 26 | + accounts := args.Keepers.AccountKeeper.GetAllAccounts(ctx) |
| 27 | + for _, account := range accounts { |
| 28 | + switch account.(type) { |
| 29 | + case *vestingtypes.PeriodicVestingAccount: |
| 30 | + a, ok := account.(*vestingtypes.PeriodicVestingAccount) |
| 31 | + if !ok { |
| 32 | + return errors.Wrapf(sdkerrors.ErrInvalidType, "invalid account type: %T", account) |
| 33 | + } |
| 34 | + args.Keepers.AccountKeeper.SetAccount(ctx, a.BaseAccount) |
| 35 | + case *vestingtypes.ContinuousVestingAccount: |
| 36 | + a, ok := account.(*vestingtypes.ContinuousVestingAccount) |
| 37 | + if !ok { |
| 38 | + return errors.Wrapf(sdkerrors.ErrInvalidType, "invalid account type: %T", account) |
| 39 | + } |
| 40 | + args.Keepers.AccountKeeper.SetAccount(ctx, a.BaseAccount) |
| 41 | + case *vestingtypes.DelayedVestingAccount: |
| 42 | + a, ok := account.(*vestingtypes.DelayedVestingAccount) |
| 43 | + if !ok { |
| 44 | + return errors.Wrapf(sdkerrors.ErrInvalidType, "invalid account type: %T", account) |
| 45 | + } |
| 46 | + args.Keepers.AccountKeeper.SetAccount(ctx, a.BaseAccount) |
| 47 | + default: |
| 48 | + } |
| 49 | + } |
| 50 | + return nil |
| 51 | +} |
0 commit comments