|
| 1 | +package v1_8 |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + upgradetypes "cosmossdk.io/x/upgrade/types" |
| 7 | + |
| 8 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 9 | + "github.com/cosmos/cosmos-sdk/types/module" |
| 10 | + |
| 11 | + "github.com/xpladev/xpla/app/keepers" |
| 12 | + authkeeper "github.com/xpladev/xpla/x/auth/keeper" |
| 13 | +) |
| 14 | + |
| 15 | +func CreateUpgradeHandler( |
| 16 | + mm *module.Manager, |
| 17 | + configurator module.Configurator, |
| 18 | + keepers *keepers.AppKeepers, |
| 19 | +) upgradetypes.UpgradeHandler { |
| 20 | + return func(c context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { |
| 21 | + ctx := sdk.UnwrapSDKContext(c) |
| 22 | + |
| 23 | + ctx.Logger().Info("Starting migrateSlicedAccount") |
| 24 | + migrateSlicedAccount(ctx, keepers.AccountKeeper) |
| 25 | + |
| 26 | + ctx.Logger().Info("Starting module migrations...") |
| 27 | + vm, err := mm.RunMigrations(ctx, configurator, fromVM) |
| 28 | + if err != nil { |
| 29 | + return vm, err |
| 30 | + } |
| 31 | + |
| 32 | + ctx.Logger().Info("Upgrading v1_8 has completed") |
| 33 | + return vm, nil |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +// If the length of the address exceeds 20 (for example, a cosmwasm address), |
| 38 | +// set the sliceAddress for it. |
| 39 | +func migrateSlicedAccount(ctx sdk.Context, ak authkeeper.AccountKeeper) { |
| 40 | + ak.IterateAccounts(ctx, func(acc sdk.AccountI) (stop bool) { |
| 41 | + address := acc.GetAddress() |
| 42 | + if len(address) != 20 { |
| 43 | + sliceAddress := address[len(address)-20:] |
| 44 | + ak.SliceAddresses.Set(ctx, sliceAddress, address) |
| 45 | + } |
| 46 | + |
| 47 | + return false |
| 48 | + }) |
| 49 | +} |
0 commit comments