package app import ( "io" clienthelpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" circuitkeeper "cosmossdk.io/x/circuit/keeper" upgradekeeper "cosmossdk.io/x/upgrade/keeper" abci "git.cw.tr/mukan-network/mukan-consensus/abci/types" dbm "github.com/cosmos/cosmos-db" "git.cw.tr/mukan-network/mukan-sdk/baseapp" "git.cw.tr/mukan-network/mukan-sdk/client" "git.cw.tr/mukan-network/mukan-sdk/codec" codectypes "git.cw.tr/mukan-network/mukan-sdk/codec/types" "git.cw.tr/mukan-network/mukan-sdk/runtime" "git.cw.tr/mukan-network/mukan-sdk/server" "git.cw.tr/mukan-network/mukan-sdk/server/api" "git.cw.tr/mukan-network/mukan-sdk/server/config" servertypes "git.cw.tr/mukan-network/mukan-sdk/server/types" sdk "git.cw.tr/mukan-network/mukan-sdk/types" "git.cw.tr/mukan-network/mukan-sdk/types/module" "git.cw.tr/mukan-network/mukan-sdk/x/auth" authkeeper "git.cw.tr/mukan-network/mukan-sdk/x/auth/keeper" authsims "git.cw.tr/mukan-network/mukan-sdk/x/auth/simulation" authtypes "git.cw.tr/mukan-network/mukan-sdk/x/auth/types" authzkeeper "git.cw.tr/mukan-network/mukan-sdk/x/authz/keeper" bankkeeper "git.cw.tr/mukan-network/mukan-sdk/x/bank/keeper" consensuskeeper "git.cw.tr/mukan-network/mukan-sdk/x/consensus/keeper" "git.cw.tr/mukan-network/mukan-sdk/x/genutil" genutiltypes "git.cw.tr/mukan-network/mukan-sdk/x/genutil/types" paramskeeper "git.cw.tr/mukan-network/mukan-sdk/x/params/keeper" paramstypes "git.cw.tr/mukan-network/mukan-sdk/x/params/types" slashingkeeper "git.cw.tr/mukan-network/mukan-sdk/x/slashing/keeper" stakingkeeper "git.cw.tr/mukan-network/mukan-sdk/x/staking/keeper" icacontrollerkeeper "git.cw.tr/mukan-network/mukan-ibc/modules/apps/27-interchain-accounts/controller/keeper" icahostkeeper "git.cw.tr/mukan-network/mukan-ibc/modules/apps/27-interchain-accounts/host/keeper" ibctransferkeeper "git.cw.tr/mukan-network/mukan-ibc/modules/apps/transfer/keeper" ibckeeper "git.cw.tr/mukan-network/mukan-ibc/modules/core/keeper" "mukan/docs" mukanmodulekeeper "mukan/x/mukan/keeper" pojmodulekeeper "mukan/x/poj/keeper" qposmodulekeeper "mukan/x/qpos/keeper" ) const ( // Name is the name of the application. Name = "mukan" // AccountAddressPrefix is the prefix for accounts addresses. AccountAddressPrefix = "mukan" // ChainCoinType is the coin type of the chain. ChainCoinType = 118 ) // DefaultNodeHome default home directories for the application daemon var DefaultNodeHome string var ( _ runtime.AppI = (*App)(nil) _ servertypes.Application = (*App)(nil) ) // App extends an ABCI application, but with most of its parameters exported. // They are exported for convenience in creating helper functions, as object // capabilities aren't needed for testing. type App struct { *runtime.App legacyAmino *codec.LegacyAmino appCodec codec.Codec txConfig client.TxConfig interfaceRegistry codectypes.InterfaceRegistry // keepers // only keepers required by the app are exposed // the list of all modules is available in the app_config AuthKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper StakingKeeper *stakingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper UpgradeKeeper *upgradekeeper.Keeper AuthzKeeper authzkeeper.Keeper ConsensusParamsKeeper consensuskeeper.Keeper CircuitBreakerKeeper circuitkeeper.Keeper ParamsKeeper paramskeeper.Keeper // ibc keepers IBCKeeper *ibckeeper.Keeper ICAControllerKeeper icacontrollerkeeper.Keeper ICAHostKeeper icahostkeeper.Keeper TransferKeeper ibctransferkeeper.Keeper // simulation manager sm *module.SimulationManager MukanKeeper mukanmodulekeeper.Keeper PojKeeper pojmodulekeeper.Keeper QposKeeper qposmodulekeeper.Keeper } func init() { var err error clienthelpers.EnvPrefix = Name DefaultNodeHome, err = clienthelpers.GetNodeHomeDirectory("." + Name) if err != nil { panic(err) } } // AppConfig returns the default app config. func AppConfig() depinject.Config { return depinject.Configs( appConfig, depinject.Supply( // supply custom module basics map[string]module.AppModuleBasic{ genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), }, ), ) } // New returns a reference to an initialized App. func New( logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *App { var ( app = &App{} appBuilder *runtime.AppBuilder // merge the AppConfig and other configuration in one config appConfig = depinject.Configs( AppConfig(), depinject.Supply( appOpts, // supply app options logger, // supply logger // Supply with IBC keeper getter for the IBC modules with App Wiring. // The IBC Keeper cannot be passed because it has not been initiated yet. // Passing the getter, the app IBC Keeper will always be accessible. // This needs to be removed after IBC supports App Wiring. app.GetIBCKeeper, // here alternative options can be supplied to the DI container. // those options can be used f.e to override the default behavior of some modules. // for instance supplying a custom address codec for not using bech32 addresses. // read the depinject documentation and depinject module wiring for more information // on available options and how to use them. ), ) ) var appModules map[string]appmodule.AppModule if err := depinject.Inject(appConfig, &appBuilder, &appModules, &app.appCodec, &app.legacyAmino, &app.txConfig, &app.interfaceRegistry, &app.AuthKeeper, &app.BankKeeper, &app.StakingKeeper, &app.SlashingKeeper, &app.UpgradeKeeper, &app.AuthzKeeper, &app.ConsensusParamsKeeper, &app.CircuitBreakerKeeper, &app.ParamsKeeper, &app.MukanKeeper, &app.PojKeeper, &app.QposKeeper, ); err != nil { panic(err) } // Stake Lock: Intercept messages to block staking during bootstrapping // We'll use a simple approach by checking messages in a custom AnteHandler if needed, // but for Phase 1, we can also do it in the PojKeeper's logic. // add to default baseapp options // enable optimistic execution baseAppOptions = append(baseAppOptions, baseapp.SetOptimisticExecution()) // build app app.App = appBuilder.Build(db, traceStore, baseAppOptions...) // register legacy modules if err := app.registerIBCModules(appOpts); err != nil { panic(err) } /**** Module Options ****/ // create the simulation manager and define the order of the modules for deterministic simulations overrideModules := map[string]module.AppModuleSimulation{ authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AuthKeeper, authsims.RandomGenesisAccounts, nil), } app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules) app.sm.RegisterStoreDecoders() // A custom InitChainer sets if extra pre-init-genesis logic is required. // This is necessary for manually registered modules that do not support app wiring. // Manually set the module version map as shown below. // The upgrade module will automatically handle de-duplication of the module version map. app.SetInitChainer(func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()); err != nil { return nil, err } return app.App.InitChainer(ctx, req) }) if err := app.Load(loadLatest); err != nil { panic(err) } return app } // GetSubspace returns a param subspace for a given module name. func (app *App) GetSubspace(moduleName string) paramstypes.Subspace { subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) return subspace } // LegacyAmino returns App's amino codec. func (app *App) LegacyAmino() *codec.LegacyAmino { return app.legacyAmino } // AppCodec returns App's app codec. func (app *App) AppCodec() codec.Codec { return app.appCodec } // InterfaceRegistry returns App's InterfaceRegistry. func (app *App) InterfaceRegistry() codectypes.InterfaceRegistry { return app.interfaceRegistry } // TxConfig returns App's TxConfig func (app *App) TxConfig() client.TxConfig { return app.txConfig } // GetKey returns the KVStoreKey for the provided store key. func (app *App) GetKey(storeKey string) *storetypes.KVStoreKey { kvStoreKey, ok := app.UnsafeFindStoreKey(storeKey).(*storetypes.KVStoreKey) if !ok { return nil } return kvStoreKey } // SimulationManager implements the SimulationApp interface func (app *App) SimulationManager() *module.SimulationManager { return app.sm } // RegisterAPIRoutes registers all application module routes with the provided // API server. func (app *App) 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) } // register app's OpenAPI routes. docs.RegisterOpenAPIService(Name, apiSvr.Router) } // GetMaccPerms returns a copy of the module account permissions // // NOTE: This is solely to be used for testing purposes. func GetMaccPerms() map[string][]string { dup := make(map[string][]string) for _, perms := range moduleAccPerms { dup[perms.GetAccount()] = perms.GetPermissions() } return dup } // BlockedAddresses returns all the app's blocked account addresses. func BlockedAddresses() map[string]bool { result := make(map[string]bool) if len(blockAccAddrs) > 0 { for _, addr := range blockAccAddrs { result[addr] = true } } else { for addr := range GetMaccPerms() { result[addr] = true } } return result }