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

feat: integrate cosmwasm #148

Merged
merged 10 commits into from
Feb 8, 2024
Merged
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
5 changes: 5 additions & 0 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package app

import (
errorsmod "cosmossdk.io/errors"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
globalfeeante "github.com/OmniFlix/omniflixhub/v2/x/globalfee/ante"
globalfeekeeper "github.com/OmniFlix/omniflixhub/v2/x/globalfee/keeper"
"github.com/cosmos/cosmos-sdk/codec"
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
32 changes: 28 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
"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"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/OmniFlix/omniflixhub/v2/app/openapiconsole"
appparams "github.com/OmniFlix/omniflixhub/v2/app/params"
"github.com/OmniFlix/omniflixhub/v2/docs"
Expand Down Expand Up @@ -57,6 +60,18 @@

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 []wasm.Option

Check failure on line 72 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: wasm.Option is deprecated: Do not use. (staticcheck)
)

func getGovProposalHandlers() []govclient.ProposalHandler {
var govProposalHandlers []govclient.ProposalHandler
govProposalHandlers = append(govProposalHandlers,
Expand Down Expand Up @@ -120,6 +135,7 @@
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 +170,7 @@
invCheckPeriod,
logger,
appOpts,
wasmOpts,
)

/**** Module Options ****/
Expand Down Expand Up @@ -205,6 +222,11 @@
}
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 +236,11 @@
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
59 changes: 57 additions & 2 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package keepers

import (
"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/v2/x/ics721nft"
nfttransfer "github.com/bianjieai/nft-transfer"
"github.com/cometbft/cometbft/libs/log"
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 @@ -107,6 +112,8 @@ import (

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

tfbindings "github.com/OmniFlix/omniflixhub/v2/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
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keepers

import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
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"
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
97 changes: 97 additions & 0 deletions app/keepers/wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package keepers

import (
"strings"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
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"
streampaytypes "github.com/OmniFlix/streampay/v2/x/streampay/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
)

// 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
var wasmCapabilities = []string{
"iterator",
"staking",
"stargate",
"cosmwasm_1_1",
"cosmwasm_1_2",
"cosmwasm_1_3",
"cosmwasm_1_4",
"cosmwasm_1_5",
"token_factory",
}

func AcceptedStargateQueries() wasmkeeper.AcceptedStargateQueries {
return wasmkeeper.AcceptedStargateQueries{
// ibc
"/ibc.core.client.v1.Query/ClientState": &ibcclienttypes.QueryClientStateResponse{},
"/ibc.core.client.v1.Query/ConsensusState": &ibcclienttypes.QueryConsensusStateResponse{},
"/ibc.core.connection.v1.Query/Connection": &ibcconnectiontypes.QueryConnectionResponse{},

// governance
"/cosmos.gov.v1beta1.Query/Vote": &govv1.QueryVoteResponse{},

// distribution
"/cosmos.distribution.v1beta1.Query/DelegationRewards": &distrtypes.QueryDelegationRewardsResponse{},

// staking
"/cosmos.staking.v1beta1.Query/Delegation": &stakingtypes.QueryDelegationResponse{},
"/cosmos.staking.v1beta1.Query/Redelegations": &stakingtypes.QueryRedelegationsResponse{},
"/cosmos.staking.v1beta1.Query/UnbondingDelegation": &stakingtypes.QueryUnbondingDelegationResponse{},
"/cosmos.staking.v1beta1.Query/Validator": &stakingtypes.QueryValidatorResponse{},
"/cosmos.staking.v1beta1.Query/Params": &stakingtypes.QueryParamsResponse{},
"/cosmos.staking.v1beta1.Query/Pool": &stakingtypes.QueryPoolResponse{},

// onft
"/OmniFlix.onft.v1beta1.Query/Denoms": &onfttypes.QueryDenomsResponse{},
"/OmniFlix.onft.v1beta1.Query/Denom": &onfttypes.QueryDenomResponse{},
"/OmniFlix.onft.v1beta1.Query/IBCDenom": &onfttypes.QueryDenomResponse{},
"/OmniFlix.onft.v1beta1.Query/Collection": &onfttypes.QueryCollectionResponse{},
"/OmniFlix.onft.v1beta1.Query/IBCCollection": &onfttypes.QueryCollectionResponse{},
"/OmniFlix.onft.v1beta1.Query/OwnerONFTs": &onfttypes.QueryOwnerONFTsResponse{},
"/OmniFlix.onft.v1beta1.Query/ONFT": &onfttypes.QueryONFTResponse{},
"/OmniFlix.onft.v1beta1.Query/Supply": &onfttypes.QuerySupplyResponse{},
"/OmniFlix.onft.v1beta1.Query/Params": &onfttypes.QueryParamsResponse{},

// marketplace
"/OmniFlix.marketplace.v1beta1.Query/Listings": &marketplacetypes.QueryListingsResponse{},
"/OmniFlix.marketplace.v1beta1.Query/Listing": &marketplacetypes.QueryListingResponse{},
"/OmniFlix.marketplace.v1beta1.Query/ListingsByOwner": &marketplacetypes.QueryListingsByOwnerResponse{},
"/OmniFlix.marketplace.v1beta1.Query/Auctions": &marketplacetypes.QueryAuctionsResponse{},
"/OmniFlix.marketplace.v1beta1.Query/Auction": &marketplacetypes.QueryAuctionResponse{},
"/OmniFlix.marketplace.v1beta1.Query/AuctionsByOwner": &marketplacetypes.QueryAuctionsResponse{},
"/OmniFlix.marketplace.v1beta1.Query/Bids": &marketplacetypes.QueryBidsResponse{},
"/OmniFlix.marketplace.v1beta1.Query/Bid": &marketplacetypes.QueryBidResponse{},
"/OmniFlix.marketplace.v1beta1.Query/Params": &marketplacetypes.QueryParamsResponse{},

// itc
"/OmniFlix.itc.v1.Query/Campaigns": &itctypes.QueryCampaignsResponse{},
"/OmniFlix.itc.v1.Query/Campaign": &itctypes.QueryCampaignResponse{},
"/OmniFlix.itc.v1.Query/Claims": &itctypes.QueryClaimsResponse{},
"/OmniFlix.itc.v1.Query/Params": &itctypes.QueryParamsResponse{},

// streampay
"/OmniFlix.streampay.v1.Query/StreamPayments": &streampaytypes.QueryStreamPaymentsResponse{},
"/OmniFlix.streampay.v1.Query/StreamPayment": &streampaytypes.QueryStreamPaymentResponse{},
"/OmniFlix.streampay.v1.Query/Params": &streampaytypes.QueryParamsResponse{},

// tokenfactory queries
"/osmosis.tokenfactory.v1beta1.Query/Params": &tokenfactorytypes.QueryParamsResponse{},
"/osmosis.tokenfactory.v1beta1.Query/DenomAuthorityMetadata": &tokenfactorytypes.QueryDenomAuthorityMetadataResponse{},
"/osmosis.tokenfactory.v1beta1.Query/DenomsFromCreator": &tokenfactorytypes.QueryDenomsFromCreatorResponse{},
}
}

func GetWasmCapabilities() string {
return strings.Join(wasmCapabilities, ",")
}
Loading
Loading