package app import ( "cosmossdk.io/api/tendermint/abci" "cosmossdk.io/client/v2/autocli" "github.com/cosmos/cosmos-sdk/client" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/bank" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/cosmos/cosmos-sdk/x/gov" govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/gogo/protobuf/codec" foomodule "github.com/username/test/x/foo" fookeeper "github.com/username/test/x/foo/keeper" ) // App modules are defined as NewBasicManager arguments var ModuleBasics = module.NewBasicManager( auth.AppModuleBasic{}, bank.AppModuleBasic{}, staking.AppModuleBasic{}, gov.NewAppModuleBasic([]govclient.ProposalHandler{ paramsclient.ProposalHandler, }), foomodule.AppModuleBasic{}, ) type Foo struct { *runtime.App AuthKeeper authkeeper.Keeper BankKeeper bankkeeper.Keeper StakingKeeper stakingkeeper.Keeper GovKeeper govkeeper.Keeper FooKeeper fookeeper.Keeper } func (Foo) Name() string { return "foo" } func (Foo) InterfaceRegistry() codectypes.InterfaceRegistry { return nil } func (Foo) TxConfig() client.TxConfig { return nil } func (Foo) AutoCliOpts() autocli.AppOptions { return autocli.AppOptions{} } func (Foo) BeginBlocker(sdk.Context, abci.RequestBeginBlock) abci.ResponseBeginBlock { return abci.ResponseBeginBlock{} } func (Foo) EndBlocker(sdk.Context, abci.RequestEndBlock) abci.ResponseEndBlock { return abci.ResponseEndBlock{} } func (app *Foo) RegisterAPIRoutes(s *api.Server, cfg config.APIConfig) { // This module should be discovered foomodule.RegisterGRPCGatewayRoutes(s.ClientCtx, s.GRPCGatewayRouter) // Runtime app modules for the current Cosmos SDK should be discovered too app.App.RegisterAPIRoutes(apiSvr, apiConfig) } func (Foo) GetKey(storeKey string) *storetypes.KVStoreKey { return nil } func (Foo) TxConfig() client.TxConfig { return nil } func (Foo) AppCodec() codec.Codec { return app.appCodec } // GetKey returns the KVStoreKey for the provided store key. func (Foo) GetKey(storeKey string) *storetypes.KVStoreKey { sk := app.UnsafeFindStoreKey(storeKey) kvStoreKey, ok := sk.(*storetypes.KVStoreKey) if !ok { return nil } return kvStoreKey } // GetMemKey returns the MemoryStoreKey for the provided store key. func (Foo) GetMemKey(storeKey string) *storetypes.MemoryStoreKey { key, ok := app.UnsafeFindStoreKey(storeKey).(*storetypes.MemoryStoreKey) if !ok { return nil } return key } // kvStoreKeys returns all the kv store keys registered inside App. func (Foo) kvStoreKeys() map[string]*storetypes.KVStoreKey { keys := make(map[string]*storetypes.KVStoreKey) for _, k := range app.GetStoreKeys() { if kv, ok := k.(*storetypes.KVStoreKey); ok { keys[kv.Name()] = kv } } return keys } // GetSubspace returns a param subspace for a given module name. func (Foo) GetSubspace(moduleName string) paramstypes.Subspace { subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) return subspace } // SimulationManager implements the SimulationApp interface func (Foo) SimulationManager() *module.SimulationManager { return app.sm } // RegisterAPIRoutes registers all application module routes with the provided // API server. func (Foo) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { app.App.RegisterAPIRoutes(apiSvr, apiConfig) // register swagger API in app.go so that other applications can override easily if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil { panic(err) } }