Skip to content

Commit

Permalink
feat(upgrade): v3 upgrade handler (#150)
Browse files Browse the repository at this point in the history
* feat(upgrade): v3 upgrade handler
  • Loading branch information
harish551 authored Feb 8, 2024
1 parent 0236d0c commit 46254aa
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
v012 "github.com/OmniFlix/omniflixhub/v3/app/upgrades/v012"
v2 "github.com/OmniFlix/omniflixhub/v3/app/upgrades/v2"
v2_1 "github.com/OmniFlix/omniflixhub/v3/app/upgrades/v2.1"
v3 "github.com/OmniFlix/omniflixhub/v3/app/upgrades/v3"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

Expand All @@ -69,7 +70,7 @@ var (
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""

EmptyWasmOpts []wasm.Option
EmptyWasmOpts [][]wasmkeeper.Option
)

func getGovProposalHandlers() []govclient.ProposalHandler {
Expand All @@ -88,7 +89,7 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
Upgrades = []upgrades.Upgrade{v012.Upgrade, v2.Upgrade, v2_1.Upgrade}
Upgrades = []upgrades.Upgrade{v012.Upgrade, v2.Upgrade, v2_1.Upgrade, v3.Upgrade}
Forks []upgrades.Fork
)

Expand Down
17 changes: 17 additions & 0 deletions app/upgrades/v3/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v3

import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/OmniFlix/omniflixhub/v3/app/upgrades"
store "github.com/cosmos/cosmos-sdk/store/types"
)

const UpgradeName = "v3-dev"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV3UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{wasmtypes.ModuleName},
},
}
44 changes: 44 additions & 0 deletions app/upgrades/v3/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package v3

import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/OmniFlix/omniflixhub/v3/app/keepers"
"github.com/OmniFlix/omniflixhub/v3/app/upgrades"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func CreateV3UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
_ upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("running migrations ...")
// Run migrations before applying any other state changes.
// NOTE: DO NOT PUT ANY STATE CHANGES BEFORE RunMigrations().
versionMap, err := mm.RunMigrations(ctx, cfg, fromVM)
if err != nil {
return nil, err
}

params := wasmtypes.DefaultParams()
params.CodeUploadAccess = wasmtypes.AccessConfig{
Permission: wasmtypes.AccessTypeAnyOfAddresses,
Addresses: []string{
// test addrs
"omniflix18fw35sd99ksgcylrxqz555hk2ffnp9dx3gzv9a",
"omniflix1fua9pv84yfqp7gjpv8vmsrygqa9prtsm3y95vm",
},
}
params.InstantiateDefaultPermission = wasmtypes.AccessTypeEverybody
if err := keepers.WasmKeeper.SetParams(ctx, params); err != nil {
return nil, err
}

ctx.Logger().Info("Upgrade complete")
return versionMap, nil
}
}

0 comments on commit 46254aa

Please sign in to comment.