Skip to content

Commit

Permalink
Merge pull request #90 from comdex-official/feature/mainnet_release
Browse files Browse the repository at this point in the history
Enabled cosmwasm
  • Loading branch information
dheerajkd30 authored Feb 16, 2022
2 parents 43b5ff0 + e94ab0f commit c0a9b99
Show file tree
Hide file tree
Showing 15 changed files with 481 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .scripts/proto-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ for directory in ${directories}; do
--proto_path="proto" \
--proto_path="vendor/github.com/cosmos/cosmos-sdk/proto" \
--proto_path="vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--proto_path="vendor/github.com/cosmos/ibc-go/proto" \
--proto_path="vendor/github.com/cosmos/ibc-go/v2/proto" \
--gocosmos_out="plugins=interfacetype+grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:${GOPATH}/src" \
"${file}"

protoc \
--proto_path="proto" \
--proto_path="vendor/github.com/cosmos/cosmos-sdk/proto" \
--proto_path="vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--proto_path="vendor/github.com/cosmos/ibc-go/proto" \
--proto_path="vendor/github.com/cosmos/ibc-go/v2/proto" \
--grpc-gateway_out="logtostderr=true:${GOPATH}/src" \
"${file}"
done
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ clean:

all: verify build

install:
install: mod-vendor
ifeq (${OS},Windows_NT)
go build -mod=readonly ${BUILD_FLAGS} -o ${GOBIN}/comdex.exe ./node
else
Expand All @@ -49,7 +49,7 @@ go-lint:
.PHONY: mod-vendor
mod-vendor: tools
@go mod vendor
@modvendor -copy="**/*.proto" -include=github.com/cosmos/cosmos-sdk/proto,github.com/cosmos/cosmos-sdk/third_party/proto,github.com/cosmos/ibc-go/proto
@modvendor -copy="**/*.proto" -include=github.com/cosmos/cosmos-sdk/proto,github.com/cosmos/cosmos-sdk/third_party/proto,github.com/cosmos/ibc-go/v2/proto

.PHONY: proto-gen
proto-gen:
Expand Down
123 changes: 106 additions & 17 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package app

import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"io"
"os"
"path/filepath"
Expand All @@ -24,6 +28,7 @@ import (
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -64,14 +69,15 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibctransfer "github.com/cosmos/ibc-go/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/modules/core"
ibcclient "github.com/cosmos/ibc-go/modules/core/02-client"
ibcporttypes "github.com/cosmos/ibc-go/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/modules/core/keeper"
ibctransfer "github.com/cosmos/ibc-go/v2/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v2/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v2/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v2/modules/core"
ibcclient "github.com/cosmos/ibc-go/v2/modules/core/02-client"
ibcporttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibctypes "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"
"github.com/spf13/cast"
abcitypes "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand Down Expand Up @@ -115,6 +121,7 @@ var (
evidence.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
vesting.AppModuleBasic{},
wasm.AppModuleBasic{},
)
)

Expand Down Expand Up @@ -149,9 +156,6 @@ type App struct {
tkeys map[string]*sdk.TransientStoreKey
mkeys map[string]*sdk.MemoryStoreKey

// the module manager
mm *module.Manager

// keepers
accountKeeper authkeeper.AccountKeeper
freegrantKeeper freegrantkeeper.Keeper
Expand All @@ -172,7 +176,12 @@ type App struct {
// make scoped keepers public for test purposes
scopedIBCKeeper capabilitykeeper.ScopedKeeper
scopedIBCTransferKeeper capabilitykeeper.ScopedKeeper

scopedWasmKeeper capabilitykeeper.ScopedKeeper
wasmKeeper wasm.Keeper
// the module manager
mm *module.Manager
// Module configurator
configurator module.Configurator
}

// New returns a reference to an initialized App.
Expand All @@ -186,6 +195,7 @@ func New(
invCheckPeriod uint,
encoding EncodingConfig,
appOptions servertypes.AppOptions,
wasmOpts []wasm.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
var (
Expand All @@ -196,6 +206,7 @@ func New(
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
wasm.StoreKey,
)
)

Expand Down Expand Up @@ -233,6 +244,7 @@ func New(
app.paramsKeeper.Subspace(crisistypes.ModuleName)
app.paramsKeeper.Subspace(ibctransfertypes.ModuleName)
app.paramsKeeper.Subspace(ibchost.ModuleName)
app.paramsKeeper.Subspace(wasmtypes.ModuleName)

// set the BaseApp's parameter store
baseApp.SetParamStore(
Expand All @@ -252,6 +264,7 @@ func New(
var (
scopedIBCKeeper = app.capabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper = app.capabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper = app.capabilityKeeper.ScopeToModule(wasm.ModuleName)
)

// add keepers
Expand Down Expand Up @@ -314,7 +327,7 @@ func New(
homePath,
app.BaseApp,
)

app.registerUpgradeHandlers()
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.stakingKeeper = *stakingKeeper.SetHooks(
Expand Down Expand Up @@ -382,6 +395,30 @@ func New(
)
app.evidenceKeeper.SetRouter(evidenceRouter)

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOptions)
supportedFeatures := "iterator,staking,stargate"

app.wasmKeeper = wasmkeeper.NewKeeper(
app.cdc,
keys[wasmtypes.StoreKey],
app.GetSubspace(wasmtypes.ModuleName),
app.accountKeeper,
app.bankKeeper,
app.stakingKeeper,
app.distrKeeper,
app.ibcKeeper.ChannelKeeper,
&app.ibcKeeper.PortKeeper,
scopedWasmKeeper,
app.ibcTransferKeeper,
baseApp.MsgServiceRouter(),
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
supportedFeatures,
wasmOpts...,
)

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand All @@ -408,6 +445,7 @@ func New(
ibc.NewAppModule(app.ibcKeeper),
params.NewAppModule(app.paramsKeeper),
transferModule,
wasm.NewAppModule(app.cdc, &app.wasmKeeper, app.stakingKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -417,9 +455,16 @@ func New(
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
crisistypes.ModuleName, genutiltypes.ModuleName, authtypes.ModuleName, capabilitytypes.ModuleName,
transferModule.Name(), vesting.AppModuleBasic{}.Name(), paramstypes.ModuleName, wasmtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName,
)

app.mm.SetOrderEndBlockers(crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName, minttypes.ModuleName,
distrtypes.ModuleName, genutiltypes.ModuleName, vesting.AppModuleBasic{}.Name(), evidencetypes.ModuleName, ibchost.ModuleName,
wasmtypes.ModuleName, authtypes.ModuleName, slashingtypes.ModuleName, paramstypes.ModuleName,
capabilitytypes.ModuleName, upgradetypes.ModuleName, transferModule.Name(), banktypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
Expand All @@ -440,12 +485,16 @@ func New(
genutiltypes.ModuleName,
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
wasmtypes.ModuleName,
vesting.AppModuleBasic{}.Name(),
upgradetypes.ModuleName,
paramstypes.ModuleName,
)

app.mm.RegisterInvariants(&app.crisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encoding.Amino)
app.mm.RegisterServices(module.NewConfigurator(app.cdc, app.MsgServiceRouter(), app.GRPCQueryRouter()))

app.configurator = module.NewConfigurator(app.cdc, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)
// initialize stores
app.MountKVStores(app.keys)
app.MountTransientStores(app.tkeys)
Expand Down Expand Up @@ -489,7 +538,7 @@ func New(

app.scopedIBCKeeper = scopedIBCKeeper
app.scopedIBCTransferKeeper = scopedTransferKeeper

app.scopedWasmKeeper = scopedWasmKeeper
return app
}

Expand All @@ -512,6 +561,7 @@ func (a *App) InitChainer(ctx sdk.Context, req abcitypes.RequestInitChain) abcit
if err := tmjson.Unmarshal(req.AppStateBytes, &state); err != nil {
panic(err)
}
a.upgradeKeeper.SetModuleVersionMap(ctx, a.mm.GetVersionMap())
return a.mm.InitGenesis(ctx, a.cdc, state)
}

Expand Down Expand Up @@ -616,5 +666,44 @@ func (a *App) ModuleAccountsPermissions() map[string][]string {
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
wasm.ModuleName: {authtypes.Burner},
}
}
func (app *App) registerUpgradeHandlers() {
app.upgradeKeeper.SetUpgradeHandler("v0.1.0", func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
// 1st-time running in-store migrations, using 1 as fromVersion to
// avoid running InitGenesis.
fromVM := map[string]uint64{
authtypes.ModuleName: auth.AppModule{}.ConsensusVersion(),
banktypes.ModuleName: bank.AppModule{}.ConsensusVersion(),
capabilitytypes.ModuleName: capability.AppModule{}.ConsensusVersion(),
crisistypes.ModuleName: crisis.AppModule{}.ConsensusVersion(),
distrtypes.ModuleName: distr.AppModule{}.ConsensusVersion(),
evidencetypes.ModuleName: evidence.AppModule{}.ConsensusVersion(),
govtypes.ModuleName: gov.AppModule{}.ConsensusVersion(),
minttypes.ModuleName: mint.AppModule{}.ConsensusVersion(),
paramstypes.ModuleName: params.AppModule{}.ConsensusVersion(),
slashingtypes.ModuleName: slashing.AppModule{}.ConsensusVersion(),
stakingtypes.ModuleName: staking.AppModule{}.ConsensusVersion(),
upgradetypes.ModuleName: upgrade.AppModule{}.ConsensusVersion(),
vestingtypes.ModuleName: vesting.AppModule{}.ConsensusVersion(),
ibctypes.ModuleName: ibc.AppModule{}.ConsensusVersion(),
genutiltypes.ModuleName: genutil.AppModule{}.ConsensusVersion(),
ibctransfertypes.ModuleName: ibctransfer.AppModule{}.ConsensusVersion(),
}
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}
if upgradeInfo.Name == "v0.1.0" && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{wasmtypes.ModuleName},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
17 changes: 10 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ module github.com/comdex-official/comdex
go 1.16

require (
github.com/CosmWasm/wasmd v0.22.0
github.com/bandprotocol/bandchain-packet v0.0.2
github.com/cosmos/cosmos-sdk v0.44.3
github.com/cosmos/ibc-go v1.1.3
github.com/cosmos/cosmos-sdk v0.45.1
github.com/cosmos/ibc-go/v2 v2.0.2
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/spf13/cast v1.3.1
github.com/prometheus/client_golang v1.12.0
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.2.1
github.com/swaggo/swag v1.7.4
github.com/tendermint/tendermint v0.34.14
github.com/tendermint/tm-db v0.6.4
google.golang.org/genproto v0.0.0-20210722135532-667f2b7c528f
google.golang.org/grpc v1.40.0
github.com/tendermint/tendermint v0.34.15
github.com/tendermint/tm-db v0.6.6
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa
google.golang.org/grpc v1.43.0
google.golang.org/protobuf v1.27.1 // indirect
)

replace (
Expand Down
Loading

0 comments on commit c0a9b99

Please sign in to comment.