Skip to content

Commit

Permalink
refactor: remove unnecessary upgrade handler
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed Apr 25, 2024
1 parent b701c7c commit 3045939
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 77 deletions.
2 changes: 0 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import (
v6 "github.com/sge-network/sge/app/upgrades/v6"
v7 "github.com/sge-network/sge/app/upgrades/v7"
v8 "github.com/sge-network/sge/app/upgrades/v8"
v9 "github.com/sge-network/sge/app/upgrades/v9"

abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand Down Expand Up @@ -85,7 +84,6 @@ var (
v6.Upgrade,
v7.Upgrade,
v8.Upgrade,
v9.Upgrade,
}
)

Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v8/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/sge-network/sge/app/upgrades"
)

// UpgradeName defines the on-chain upgrade name for the v1.6.1 upgrade.
const UpgradeName = "v1.6.1"
// UpgradeName defines the on-chain upgrade name for the v1.6.2 upgrade.
const UpgradeName = "v1.6.2"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
Expand Down
71 changes: 41 additions & 30 deletions app/upgrades/v8/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/sge-network/sge/app/keepers"
"github.com/sge-network/sge/x/reward/types"
)
Expand All @@ -17,42 +18,52 @@ func CreateUpgradeHandler(
k *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
allCampaigns := k.RewardKeeper.GetAllCampaign(ctx)
promoters := make(map[string]struct{})
for _, c := range allCampaigns {
c.CapCount = 0 // infinite cap for all campaigns
c.Pool.Withdrawn = sdkmath.ZeroInt()
k.RewardKeeper.SetCampaign(ctx, c)
promoters[c.Promoter] = struct{}{}
}
allPromoters := k.RewardKeeper.GetAllPromoter(ctx)
promoterUID := "f0630627-9e4e-48f3-8cd5-1422b46d2175"
if len(allPromoters) == 0 {
allCampaigns := k.RewardKeeper.GetAllCampaign(ctx)
promoters := make(map[string]struct{})
for _, c := range allCampaigns {
c.CapCount = 0 // infinite cap for all campaigns
c.Pool.Withdrawn = sdkmath.ZeroInt()
k.RewardKeeper.SetCampaign(ctx, c)
promoters[c.Promoter] = struct{}{}
}

promoterAddresses := []string{}
for addr := range promoters {
promoterAddresses = append(promoterAddresses, addr)
}
sort.Strings(promoterAddresses)

if len(promoterAddresses) > 0 {
promoterUID := "f0630627-9e4e-48f3-8cd5-1422b46d2175"
k.RewardKeeper.SetPromoter(ctx, types.Promoter{
Creator: promoterAddresses[0],
UID: promoterUID,
Addresses: promoterAddresses,
Conf: types.PromoterConf{
CategoryCap: []types.CategoryCap{
{Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1},
},
},
})
promoterAddresses := []string{}
for addr := range promoters {
promoterAddresses = append(promoterAddresses, addr)
}
sort.Strings(promoterAddresses)

for _, addr := range promoterAddresses {
k.RewardKeeper.SetPromoterByAddress(ctx, types.PromoterByAddress{
PromoterUID: promoterUID,
Address: addr,
if len(promoterAddresses) > 0 {
promoterUID := promoterUID
k.RewardKeeper.SetPromoter(ctx, types.Promoter{
Creator: promoterAddresses[0],
UID: promoterUID,
Addresses: promoterAddresses,
Conf: types.PromoterConf{
CategoryCap: []types.CategoryCap{
{Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1},
},
},
})

for _, addr := range promoterAddresses {
k.RewardKeeper.SetPromoterByAddress(ctx, types.PromoterByAddress{
PromoterUID: promoterUID,
Address: addr,
})
}
}
}

allByCat := k.RewardKeeper.GetAllRewardsOfReceiverByPromoterAndCategory(ctx)
for _, rc := range allByCat {
k.RewardKeeper.RemoveRewardOfReceiverByPromoterAndCategory(ctx, "", rc)
k.RewardKeeper.SetRewardOfReceiverByPromoterAndCategory(ctx, promoterUID, rc)
}

return mm.RunMigrations(ctx, configurator, fromVM)
}
}
19 changes: 0 additions & 19 deletions app/upgrades/v9/consts.go

This file was deleted.

24 changes: 0 additions & 24 deletions app/upgrades/v9/upgrades.go

This file was deleted.

0 comments on commit 3045939

Please sign in to comment.