Skip to content

Commit

Permalink
marketplace: auctions & upgrade handler (#23)
Browse files Browse the repository at this point in the history
marketplace: auctions & upgrade handler
  • Loading branch information
harish551 authored Aug 25, 2022
2 parents 690948c + c833fc4 commit ee04850
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.18
env:
GOOS: ${{ matrix.targetos }}
GOARCH: ${{ matrix.arch }}
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.idea
secret.yml
.build/*
._build/*
.envrc
/build
/_build
.vscode
12 changes: 7 additions & 5 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
channelkeeper "github.com/cosmos/ibc-go/v2/modules/core/04-channel/keeper"
ibcante "github.com/cosmos/ibc-go/v2/modules/core/ante"
ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions

IBCChannelkeeper channelkeeper.Keeper
Codec codec.BinaryCodec
IBCKeeper *ibckeeper.Keeper
TxCounterStoreKey sdk.StoreKey
Codec codec.BinaryCodec
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand All @@ -36,6 +37,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // Outermost AnteDecorator, SetUpContext must be called first
decorators.NewMinCommissionDecorator(options.Codec),
ante.NewRejectExtensionOptionsDecorator(),
ante.NewMempoolFeeDecorator(),
Expand All @@ -50,7 +52,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCChannelkeeper),
ibcante.NewAnteDecorator(options.IBCKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
80 changes: 54 additions & 26 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package app

import (
"fmt"
appparams "github.com/OmniFlix/omniflixhub/app/params"
"io"
"net/http"
"os"
"path/filepath"

appparams "github.com/OmniFlix/omniflixhub/app/params"
customAuthRest "github.com/OmniFlix/omniflixhub/custom/auth/client/rest"
"github.com/OmniFlix/omniflixhub/docs"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -77,15 +77,16 @@ 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"
"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"
ibcclientclient "github.com/cosmos/ibc-go/v2/modules/core/02-client/client"
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"
transfer "github.com/cosmos/ibc-go/v3/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v3/modules/core"
ibcclient "github.com/cosmos/ibc-go/v3/modules/core/02-client"
ibcclientclient "github.com/cosmos/ibc-go/v3/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
"github.com/spf13/cast"
"github.com/tendermint/spm/openapiconsole"
abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -108,12 +109,9 @@ import (

const Name = "omniflixhub"

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals

func getGovProposalHandlers() []govclient.ProposalHandler {
var govProposalHandlers []govclient.ProposalHandler
// this line is used by starport scaffolding # stargate/app/govProposalHandlers

govProposalHandlers = append(govProposalHandlers,
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
Expand Down Expand Up @@ -153,6 +151,7 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
//ica.AppModuleBasic{},

alloc.AppModuleBasic{},
onft.AppModuleBasic{},
Expand Down Expand Up @@ -225,8 +224,11 @@ type App struct {
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper

//ICAHostKeeper icahostkeeper.Keeper

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

AllocKeeper allockeeper.Keeper
Expand All @@ -247,10 +249,17 @@ type App struct {
// New returns a reference to an initialized app.

func NewOmniFlixApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig,
logger log.Logger,
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig appparams.EncodingConfig,
// this line is used by starport scaffolding # stargate/app/newArgument
appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {

appCodec := encodingConfig.Marshaler
Expand Down Expand Up @@ -394,20 +403,35 @@ func NewOmniFlixApp(
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
app.BankKeeper,
scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)

/* app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec,
keys[icahosttypes.StoreKey],
app.GetSubspace(icahosttypes.SubModuleName),
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
scopedICAHostKeeper,
app.MsgServiceRouter(),
)
icaModule := ica.NewAppModule(nil, &app.ICAHostKeeper)
icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper) */

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
Expand Down Expand Up @@ -462,7 +486,7 @@ func NewOmniFlixApp(

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -497,11 +521,11 @@ func NewOmniFlixApp(
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
//icaModule,
allocModule,
onftModule,
marketplaceModule,
// this line is used by starport scaffolding # stargate/app/appModule

)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -571,19 +595,19 @@ func NewOmniFlixApp(
govtypes.ModuleName,
minttypes.ModuleName,
crisistypes.ModuleName,
ibchost.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
feegrant.ModuleName,
authz.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
feegrant.ModuleName,
alloctypes.ModuleName,
onfttypes.ModuleName,
marketplacetypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
ibchost.ModuleName,
ibctransfertypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -630,14 +654,16 @@ func NewOmniFlixApp(
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
IBCChannelkeeper: app.IBCKeeper.ChannelKeeper,
IBCKeeper: app.IBCKeeper,
Codec: appCodec,
},
)
if err != nil {
panic(fmt.Errorf("failed to create AnteHandler: %s", err))
}
app.SetAnteHandler(anteHandler)
app.SetEndBlocker(app.EndBlocker)
app.RegisterUpgradeHandlers(app.configurator)

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand All @@ -648,7 +674,6 @@ func NewOmniFlixApp(
app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
// this line is used by starport scaffolding # stargate/app/beforeInitReturn

return app
}

Expand All @@ -671,6 +696,8 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}

app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}

Expand Down Expand Up @@ -802,6 +829,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(alloctypes.ModuleName)
paramsKeeper.Subspace(onfttypes.ModuleName)
paramsKeeper.Subspace(marketplacetypes.ModuleName)

// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
5 changes: 3 additions & 2 deletions app/sim_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package app_test

import (
"encoding/hex"
Expand Down Expand Up @@ -68,6 +68,7 @@ func TestFullAppSimulation(t *testing.T) {
simapp.PrintStats(db)
}
}

// fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of
// an IAVLStore for faster simulation speed.
func fauxMerkleModeOpt(bapp *baseapp.BaseApp) {
Expand Down Expand Up @@ -142,4 +143,4 @@ func TestAppStateDeterminism(t *testing.T) {
}
}
}
}
}
39 changes: 39 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package app

import (
"fmt"

marketplacetypes "github.com/OmniFlix/marketplace/x/marketplace/types"
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// next upgrade name
const upgradeName = "v2"

// RegisterUpgradeHandlers returns upgrade handlers
func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
app.UpgradeKeeper.SetUpgradeHandler(upgradeName, func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
app.MarketplaceKeeper.SetParams(ctx, marketplacetypes.DefaultParams())
app.MarketplaceKeeper.SetNextAuctionNumber(ctx, 1)

fromVM := app.mm.GetVersionMap()
ctx.Logger().Info("running migrations ...")
return app.mm.RunMigrations(ctx, cfg, fromVM)
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := store.StoreUpgrades{
Added: []string{},
}
// configure store loader that checks if hight == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
Loading

0 comments on commit ee04850

Please sign in to comment.