diff --git a/app/upgrades/v3/constants.go b/app/upgrades/v3/constants.go new file mode 100644 index 00000000..6886a33f --- /dev/null +++ b/app/upgrades/v3/constants.go @@ -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}, + }, +} diff --git a/app/upgrades/v3/upgrades.go b/app/upgrades/v3/upgrades.go new file mode 100644 index 00000000..6b305f65 --- /dev/null +++ b/app/upgrades/v3/upgrades.go @@ -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 + } +}