Skip to content

Commit

Permalink
feat(v3): add cosmwasm to omniflixhub (#152)
Browse files Browse the repository at this point in the history
* feat: integrate cosmwasm (#148)

* feat: integrate cosmwasm with bindings

* fix root command encoding config issue

* fix config seal panic

* fix genutil init issue

* fix tx counter ante

* update min nft id length

* fix nft id validation

* gofumpt lint

* [v3] - update app to v3 (#149)

* update app to v3

* chore(deps): bump up versions

* feat(upgrade): v3 upgrade handler (#150)

* feat(upgrade): v3 upgrade handler

* fix acc address validation issue (#151)

* fix lint
  • Loading branch information
harish551 authored Feb 12, 2024
1 parent 8f288bb commit e772c4c
Show file tree
Hide file tree
Showing 191 changed files with 2,489 additions and 410 deletions.
9 changes: 7 additions & 2 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package app

import (
errorsmod "cosmossdk.io/errors"
globalfeeante "github.com/OmniFlix/omniflixhub/v2/x/globalfee/ante"
globalfeekeeper "github.com/OmniFlix/omniflixhub/v2/x/globalfee/keeper"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
globalfeeante "github.com/OmniFlix/omniflixhub/v3/x/globalfee/ante"
globalfeekeeper "github.com/OmniFlix/omniflixhub/v3/x/globalfee/keeper"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -26,6 +28,7 @@ type HandlerOptions struct {
GovKeeper govkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
TxCounterStoreKey storetypes.StoreKey
WasmConfig wasmtypes.WasmConfig
Codec codec.BinaryCodec

BypassMinFeeMsgTypes []string
Expand All @@ -52,6 +55,8 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // Outermost AnteDecorator, SetUpContext must be called first
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
Expand Down
51 changes: 38 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (
"os"
"path/filepath"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"

"github.com/OmniFlix/omniflixhub/v2/app/openapiconsole"
appparams "github.com/OmniFlix/omniflixhub/v2/app/params"
"github.com/OmniFlix/omniflixhub/v2/docs"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/OmniFlix/omniflixhub/v3/app/openapiconsole"
appparams "github.com/OmniFlix/omniflixhub/v3/app/params"
"github.com/OmniFlix/omniflixhub/v3/docs"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
Expand Down Expand Up @@ -47,16 +50,29 @@ import (
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

"github.com/OmniFlix/omniflixhub/v2/app/keepers"
"github.com/OmniFlix/omniflixhub/v2/app/upgrades"
v012 "github.com/OmniFlix/omniflixhub/v2/app/upgrades/v012"
v2 "github.com/OmniFlix/omniflixhub/v2/app/upgrades/v2"
v2_1 "github.com/OmniFlix/omniflixhub/v2/app/upgrades/v2.1"
"github.com/OmniFlix/omniflixhub/v3/app/keepers"
"github.com/OmniFlix/omniflixhub/v3/app/upgrades"
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"
)

const Name = "omniflixhub"

var (
// ProposalsEnabled If EnabledSpecificProposals is "", and this is "true", then enable all x/wasm proposals.
// If EnabledSpecificProposals is "", and this is not "true", then disable all x/wasm proposals.
ProposalsEnabled = "true"
// EnableSpecificProposals If set to non-empty string it must be comma-separated list of values that are all a subset
// of "EnableAllProposals" (takes precedence over ProposalsEnabled)
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""

EmptyWasmOpts [][]wasmkeeper.Option
)

func getGovProposalHandlers() []govclient.ProposalHandler {
var govProposalHandlers []govclient.ProposalHandler
govProposalHandlers = append(govProposalHandlers,
Expand All @@ -73,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 Expand Up @@ -120,6 +136,7 @@ func NewOmniFlixApp(
invCheckPeriod uint,
encodingConfig appparams.EncodingConfig,
appOpts servertypes.AppOptions,
wasmOpts []wasmkeeper.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *OmniFlixApp {
appCodec := encodingConfig.Marshaler
Expand Down Expand Up @@ -154,6 +171,7 @@ func NewOmniFlixApp(
invCheckPeriod,
logger,
appOpts,
wasmOpts,
)

/**** Module Options ****/
Expand Down Expand Up @@ -205,6 +223,11 @@ func NewOmniFlixApp(
}
reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic("error while reading wasm config: " + err.Error())
}

anteHandler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
Expand All @@ -214,9 +237,11 @@ func NewOmniFlixApp(
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
GovKeeper: app.GovKeeper,
IBCKeeper: app.IBCKeeper,
Codec: appCodec,
GovKeeper: app.GovKeeper,
IBCKeeper: app.IBCKeeper,
Codec: appCodec,
WasmConfig: wasmConfig,
TxCounterStoreKey: app.AppKeepers.GetKey(wasmtypes.StoreKey),

BypassMinFeeMsgTypes: GetDefaultBypassFeeMessages(),
GlobalFeeKeeper: app.GlobalFeeKeeper,
Expand Down
2 changes: 1 addition & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"cosmossdk.io/math"

"github.com/OmniFlix/omniflixhub/v2/app"
"github.com/OmniFlix/omniflixhub/v3/app"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
Expand Down
2 changes: 1 addition & 1 deletion app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app

import (
"github.com/OmniFlix/omniflixhub/v2/app/params"
"github.com/OmniFlix/omniflixhub/v3/app/params"
"github.com/cosmos/cosmos-sdk/std"
)

Expand Down
87 changes: 71 additions & 16 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package keepers

import (
"github.com/OmniFlix/omniflixhub/v2/x/ics721nft"
"fmt"
"path/filepath"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/OmniFlix/omniflixhub/v3/x/ics721nft"
nfttransfer "github.com/bianjieai/nft-transfer"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
Expand All @@ -10,7 +16,6 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store/streaming"
storetypes "github.com/cosmos/cosmos-sdk/store/types"

icq "github.com/cosmos/ibc-apps/modules/async-icq/v7"
icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v7/keeper"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types"
Expand Down Expand Up @@ -47,9 +52,9 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

"github.com/OmniFlix/omniflixhub/v2/x/globalfee"
globalfeekeeper "github.com/OmniFlix/omniflixhub/v2/x/globalfee/keeper"
globalfeetypes "github.com/OmniFlix/omniflixhub/v2/x/globalfee/types"
"github.com/OmniFlix/omniflixhub/v3/x/globalfee"
globalfeekeeper "github.com/OmniFlix/omniflixhub/v3/x/globalfee/keeper"
globalfeetypes "github.com/OmniFlix/omniflixhub/v3/x/globalfee/types"

"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
Expand All @@ -67,8 +72,8 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

tokenfactorykeeper "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/keeper"
tokenfactorytypes "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types"
tokenfactorykeeper "github.com/OmniFlix/omniflixhub/v3/x/tokenfactory/keeper"
tokenfactorytypes "github.com/OmniFlix/omniflixhub/v3/x/tokenfactory/types"

"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
Expand All @@ -90,23 +95,25 @@ import (
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"

allockeeper "github.com/OmniFlix/omniflixhub/v2/x/alloc/keeper"
alloctypes "github.com/OmniFlix/omniflixhub/v2/x/alloc/types"
allockeeper "github.com/OmniFlix/omniflixhub/v3/x/alloc/keeper"
alloctypes "github.com/OmniFlix/omniflixhub/v3/x/alloc/types"

onftkeeper "github.com/OmniFlix/omniflixhub/v2/x/onft/keeper"
onfttypes "github.com/OmniFlix/omniflixhub/v2/x/onft/types"
onftkeeper "github.com/OmniFlix/omniflixhub/v3/x/onft/keeper"
onfttypes "github.com/OmniFlix/omniflixhub/v3/x/onft/types"

marketplacekeeper "github.com/OmniFlix/omniflixhub/v2/x/marketplace/keeper"
marketplacetypes "github.com/OmniFlix/omniflixhub/v2/x/marketplace/types"
marketplacekeeper "github.com/OmniFlix/omniflixhub/v3/x/marketplace/keeper"
marketplacetypes "github.com/OmniFlix/omniflixhub/v3/x/marketplace/types"

itckeeper "github.com/OmniFlix/omniflixhub/v2/x/itc/keeper"
itctypes "github.com/OmniFlix/omniflixhub/v2/x/itc/types"
itckeeper "github.com/OmniFlix/omniflixhub/v3/x/itc/keeper"
itctypes "github.com/OmniFlix/omniflixhub/v3/x/itc/types"

streampaykeeper "github.com/OmniFlix/streampay/v2/x/streampay/keeper"
streampaytypes "github.com/OmniFlix/streampay/v2/x/streampay/types"

ibcnfttransferkeeper "github.com/bianjieai/nft-transfer/keeper"
ibcnfttransfertypes "github.com/bianjieai/nft-transfer/types"

tfbindings "github.com/OmniFlix/omniflixhub/v3/x/tokenfactory/bindings"
)

var tokenFactoryCapabilities = []string{
Expand Down Expand Up @@ -146,13 +153,15 @@ type AppKeepers struct {
GroupKeeper groupkeeper.Keeper
TokenFactoryKeeper tokenfactorykeeper.Keeper
IBCNFTTransferKeeper ibcnfttransferkeeper.Keeper
WasmKeeper wasmkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedICQKeeper capabilitykeeper.ScopedKeeper
ScopedNFTTransferKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper

AllocKeeper allockeeper.Keeper
ONFTKeeper onftkeeper.Keeper
Expand All @@ -173,6 +182,7 @@ func NewAppKeeper(
invCheckPeriod uint,
logger log.Logger,
appOpts servertypes.AppOptions,
wasmOpts []wasmkeeper.Option,
) AppKeepers {
appKeepers := AppKeepers{}

Expand Down Expand Up @@ -213,7 +223,7 @@ func NewAppKeeper(
appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
appKeepers.ScopedICQKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icqtypes.ModuleName)
appKeepers.ScopedNFTTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibcnfttransfertypes.ModuleName)

appKeepers.ScopedWasmKeeper = appKeepers.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)
appKeepers.CapabilityKeeper.Seal()

appKeepers.CrisisKeeper = crisiskeeper.NewKeeper(
Expand Down Expand Up @@ -519,6 +529,50 @@ func NewAppKeeper(

appKeepers.IBCKeeper.SetRouter(ibcRouter)

// wasm configuration

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}

// custom tokenfactory messages
tfOpts := tfbindings.RegisterCustomPlugins(appKeepers.BankKeeper, &appKeepers.TokenFactoryKeeper)
wasmOpts = append(wasmOpts, tfOpts...)

querierOpts := wasmkeeper.WithQueryPlugins(
&wasmkeeper.QueryPlugins{
Stargate: wasmkeeper.AcceptListStargateQuerier(
AcceptedStargateQueries(),
bApp.GRPCQueryRouter(),
appCodec,
),
})

wasmOpts = append(wasmOpts, querierOpts)

appKeepers.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
keys[wasmtypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
distrkeeper.NewQuerier(appKeepers.DistrKeeper),
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedWasmKeeper,
appKeepers.TransferKeeper,
bApp.MsgServiceRouter(),
bApp.GRPCQueryRouter(),
wasmDir,
wasmConfig,
GetWasmCapabilities(),
govModAddress,
wasmOpts...,
)

return appKeepers
}

Expand Down Expand Up @@ -547,6 +601,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(packetforwardtypes.ModuleName)
paramsKeeper.Subspace(globalfee.ModuleName)
paramsKeeper.Subspace(tokenfactorytypes.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(alloctypes.ModuleName)
paramsKeeper.Subspace(onfttypes.ModuleName)
paramsKeeper.Subspace(marketplacetypes.ModuleName)
Expand Down
14 changes: 8 additions & 6 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package keepers

import (
alloctypes "github.com/OmniFlix/omniflixhub/v2/x/alloc/types"
globalfeetypes "github.com/OmniFlix/omniflixhub/v2/x/globalfee/types"
itctypes "github.com/OmniFlix/omniflixhub/v2/x/itc/types"
marketplacetypes "github.com/OmniFlix/omniflixhub/v2/x/marketplace/types"
onfttypes "github.com/OmniFlix/omniflixhub/v2/x/onft/types"
tokenfactorytypes "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
alloctypes "github.com/OmniFlix/omniflixhub/v3/x/alloc/types"
globalfeetypes "github.com/OmniFlix/omniflixhub/v3/x/globalfee/types"
itctypes "github.com/OmniFlix/omniflixhub/v3/x/itc/types"
marketplacetypes "github.com/OmniFlix/omniflixhub/v3/x/marketplace/types"
onfttypes "github.com/OmniFlix/omniflixhub/v3/x/onft/types"
tokenfactorytypes "github.com/OmniFlix/omniflixhub/v3/x/tokenfactory/types"
streampaytypes "github.com/OmniFlix/streampay/v2/x/streampay/types"
ibcnfttransfertypes "github.com/bianjieai/nft-transfer/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -56,6 +57,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
capabilitytypes.StoreKey,
crisistypes.StoreKey,
feegrant.StoreKey,
wasmtypes.StoreKey,
globalfeetypes.StoreKey,
group.StoreKey,
tokenfactorytypes.StoreKey,
Expand Down
Loading

0 comments on commit e772c4c

Please sign in to comment.