Skip to content

Commit

Permalink
feat(upgrade): v3 upgrade handler
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 committed Feb 8, 2024
1 parent b36f1a9 commit eb78631
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
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 eb78631

Please sign in to comment.