Skip to content

Commit

Permalink
feat: delete x/claim states on upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcre committed Jun 21, 2023
1 parent 86caa73 commit effd294
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,5 +1121,6 @@ func (app *App) SetUpgradeHandlers(mm *module.Manager, configurator module.Confi
app.UpgradeKeeper.SetUpgradeHandler(
v5.UpgradeName, v5.UpgradeHandler(
mm, configurator, app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.LiquidityKeeper,
app.LPFarmKeeper, app.ExchangeKeeper, app.AMMKeeper, app.MarkerKeeper, app.FarmingKeeper))
app.LPFarmKeeper, app.ExchangeKeeper, app.AMMKeeper, app.MarkerKeeper, app.FarmingKeeper,
app.ClaimKeeper))
}
18 changes: 17 additions & 1 deletion app/upgrades/mainnet/v5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
utils "github.com/crescent-network/crescent/v5/types"
ammkeeper "github.com/crescent-network/crescent/v5/x/amm/keeper"
ammtypes "github.com/crescent-network/crescent/v5/x/amm/types"
claimkeeper "github.com/crescent-network/crescent/v5/x/claim/keeper"
claimtypes "github.com/crescent-network/crescent/v5/x/claim/types"
exchangekeeper "github.com/crescent-network/crescent/v5/x/exchange/keeper"
exchangetypes "github.com/crescent-network/crescent/v5/x/exchange/types"
farmingkeeper "github.com/crescent-network/crescent/v5/x/farming/keeper"
Expand All @@ -43,7 +45,7 @@ func UpgradeHandler(
mm *module.Manager, configurator module.Configurator, accountKeeper authkeeper.AccountKeeper,
bankKeeper bankkeeper.Keeper, distrKeeper distrkeeper.Keeper, liquidityKeeper liquiditykeeper.Keeper,
lpFarmKeeper lpfarmkeeper.Keeper, exchangeKeeper exchangekeeper.Keeper, ammKeeper ammkeeper.Keeper,
markerKeeper markerkeeper.Keeper, farmingKeeper farmingkeeper.Keeper) upgradetypes.UpgradeHandler {
markerKeeper markerkeeper.Keeper, farmingKeeper farmingkeeper.Keeper, claimKeeper claimkeeper.Keeper) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
vm, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
Expand Down Expand Up @@ -396,6 +398,20 @@ func UpgradeHandler(
return false
})

// Delete airdrops and claim records.
var airdrops []claimtypes.Airdrop
claimKeeper.IterateAllAirdrops(ctx, func(airdrop claimtypes.Airdrop) (stop bool) {
airdrops = append(airdrops, airdrop)
return false
})
for _, airdrop := range airdrops {
claimKeeper.IterateAllClaimRecordsByAirdropId(ctx, airdrop.Id, func(record claimtypes.ClaimRecord) (stop bool) {
claimKeeper.DeleteClaimRecord(ctx, record)
return false
})
claimKeeper.DeleteAirdrop(ctx, airdrop.Id)
}

return vm, nil
}
}
Expand Down
10 changes: 10 additions & 0 deletions x/claim/keeper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,13 @@ func (k Keeper) IterateAllClaimRecordsByAirdropId(ctx sdk.Context, airdropId uin
}
}
}

func (k Keeper) DeleteAirdrop(ctx sdk.Context, airdropId uint64) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.GetAirdropKey(airdropId))
}

func (k Keeper) DeleteClaimRecord(ctx sdk.Context, record types.ClaimRecord) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.GetClaimRecordKey(record.AirdropId, record.GetRecipient()))
}

0 comments on commit effd294

Please sign in to comment.