Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK v0.50>v0.50 - Add Cosmwasm v51 #1

Open
wants to merge 5 commits into
base: add-cosmwasm-to-v50
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"

// burnmoduletypes "github.com/BitCannaGlobal/bcna/x/burn/types"
// WASM upgrade/addition
v2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/baseapp"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// RegisterUpgradeHandlers registers upgrade handlers.
Expand All @@ -35,6 +49,10 @@ func (app *App) StickyFingers(_ upgradetypes.Plan) {
app.Logger().Info(fmt.Sprintf("Module: %s, Version: %d", moduleName, version))

}
// WASM
setupLegacyKeyTables(&app.ParamsKeeper)
app.GetStoreKeys()

versionMap, err := app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
if err != nil {
return nil, err
Expand All @@ -46,14 +64,14 @@ func (app *App) StickyFingers(_ upgradetypes.Plan) {
)
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

if upgradeInfo.Name == planName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
// circuittypes.ModuleName,
// ibcfeetypes.ModuleName,
// circuittypes.ModuleName, // commented at v0.50>v0.50 uncomment for v0.47>v0.50
// ibcfeetypes.ModuleName, // commented at v0.50>v0.50 uncomment for v0.47>v0.50
// nft.ModuleName,
wasmtypes.ModuleName,
// burnmoduletypes.ModuleName,
Expand All @@ -65,3 +83,41 @@ func (app *App) StickyFingers(_ upgradetypes.Plan) {
}

}

func setupLegacyKeyTables(k *paramskeeper.Keeper) {
for _, subspace := range k.GetSubspaces() {
subspace := subspace

var keyTable paramstypes.KeyTable
switch subspace.Name() {
case authtypes.ModuleName:
keyTable = authtypes.ParamKeyTable() //nolint:staticcheck
case banktypes.ModuleName:
keyTable = banktypes.ParamKeyTable() //nolint:staticcheck
case stakingtypes.ModuleName:
keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck
case minttypes.ModuleName:
keyTable = minttypes.ParamKeyTable() //nolint:staticcheck
case distrtypes.ModuleName:
keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck
case slashingtypes.ModuleName:
keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck
case govtypes.ModuleName:
keyTable = govv1.ParamKeyTable() //nolint:staticcheck
case crisistypes.ModuleName:
keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck
// wasm
case wasmtypes.ModuleName:
keyTable = v2.ParamKeyTable() //nolint:staticcheck
default:
continue
}

if !subspace.HasKeyTable() {
subspace.WithKeyTable(keyTable)
}
}
// sdk 47
k.Subspace(baseapp.Paramspace).
WithKeyTable(paramstypes.ConsensusParamsKeyTable())
}
31 changes: 16 additions & 15 deletions app/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

import (
"fmt"
"strings"
"path/filepath"

storetypes "cosmossdk.io/store/types"
"github.com/CosmWasm/wasmd/x/wasm"
Expand All @@ -25,17 +25,17 @@ import (
// AllCapabilities returns all capabilities available with the current wasmvm
// See https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES-BUILT-IN.md
// This functionality is going to be moved upstream: https://github.com/CosmWasm/wasmvm/issues/425
func AllCapabilities() []string {
return []string{
"iterator",
"staking",
"stargate",
"cosmwasm_1_1",
"cosmwasm_1_2",
"cosmwasm_1_3",
"cosmwasm_1_4",
}
}
// func AllCapabilities() []string {
// return []string{
// "iterator",
// "staking",
// "stargate",
// "cosmwasm_1_1",
// "cosmwasm_1_2",
// "cosmwasm_1_3",
// "cosmwasm_1_4",
// }
// }

// registerWasmModules register CosmWasm keepers and non dependency inject modules.
func (app *App) registerWasmModules(
Expand All @@ -50,6 +50,7 @@ func (app *App) registerWasmModules(
}

scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)
wasmDir := filepath.Join(DefaultNodeHome, "wasm")

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
Expand All @@ -58,7 +59,7 @@ func (app *App) registerWasmModules(

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := strings.Join(AllCapabilities(), ",")
// deprecated at v0.51 - availableCapabilities := strings.Join(AllCapabilities(), ",")
app.WasmKeeper = wasmkeeper.NewKeeper(
app.AppCodec(),
runtime.NewKVStoreService(app.GetKey(wasmtypes.StoreKey)),
Expand All @@ -73,9 +74,9 @@ func (app *App) registerWasmModules(
app.TransferKeeper,
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
DefaultNodeHome,
wasmDir,
wasmConfig,
availableCapabilities,
wasmkeeper.BuiltInCapabilities(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmOpts...,
)
Expand Down
36 changes: 29 additions & 7 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,42 @@ validation: sovereign
accounts:
- name: alice
coins:
- 20000token
- 200000000stake
- 300000000ubcna
- name: bob
coins:
- 10000token
- 100000000stake
- 200000000ubcna
client:
openapi:
path: docs/static/openapi.yml
faucet:
name: bob
coins:
- 5token
- 100000stake
- 100000ubcna
validators:
- name: alice
bonded: 100000000stake
bonded: 100000000ubcna
genesis:
app_state:
staking:
params:
bond_denom: "ubcna"
crisis:
constant_fee:
denom: "ubcna"
amount: "1000"
mint:
params:
mint_denom: "ubcna"
gov:
deposit_params:
min_deposit:
- denom: "ubcna"
amount: "10000000"
client:
vuex:
path: "vue/src/store"
openapi:
path: "docs/static/openapi.yml"
init:
client:
keyring-backend: test/os
Loading
Loading