From 285d562f1786862c308e620bb94f4b187f919367 Mon Sep 17 00:00:00 2001 From: StrathCole Date: Tue, 14 May 2024 13:48:31 +0200 Subject: [PATCH] - add upgrade handler back again --- app/upgrades/v9/constants.go | 19 +++++++++++++++++ app/upgrades/v9/upgrades.go | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 app/upgrades/v9/constants.go create mode 100644 app/upgrades/v9/upgrades.go diff --git a/app/upgrades/v9/constants.go b/app/upgrades/v9/constants.go new file mode 100644 index 000000000..3d9c6f5fc --- /dev/null +++ b/app/upgrades/v9/constants.go @@ -0,0 +1,19 @@ +package v9 + +import ( + "github.com/classic-terra/core/v3/app/upgrades" + taxexemptiontypes "github.com/classic-terra/core/v3/x/taxexemption/types" + store "github.com/cosmos/cosmos-sdk/store/types" +) + +const UpgradeName = "v9" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateV9UpgradeHandler, + StoreUpgrades: store.StoreUpgrades{ + Added: []string{ + taxexemptiontypes.StoreKey, + }, + }, +} diff --git a/app/upgrades/v9/upgrades.go b/app/upgrades/v9/upgrades.go new file mode 100644 index 000000000..13e2b617e --- /dev/null +++ b/app/upgrades/v9/upgrades.go @@ -0,0 +1,41 @@ +package v9 + +import ( + "github.com/classic-terra/core/v3/app/keepers" + "github.com/classic-terra/core/v3/app/upgrades" + treasurytypes "github.com/classic-terra/core/v3/x/treasury/types" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +func CreateV9UpgradeHandler( + mm *module.Manager, + cfg module.Configurator, + _ upgrades.BaseAppParamManager, + k *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(c sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // migrate old treasurykeeper tax exemption to new tax exemption keeper + // tax exemption keeper is now a module + + // get old tax exemption keeper + sub := prefix.NewStore(c.KVStore(k.TreasuryKeeper.GetStoreKey()), treasurytypes.BurnTaxExemptionListPrefix) + + intoZone := "Binance" + + // iterate through all tax exemptions + iterator := sub.Iterator(nil, nil) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + // get tax exemption address + address := string(iterator.Key()) + + // add tax exemption address to new tax exemption keeper + k.TaxExemptionKeeper.AddTaxExemptionAddress(c, intoZone, address) + } + + return mm.RunMigrations(c, cfg, fromVM) + } +}