1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| var ( // default home directories for hub DefaultNodeHome = os.ExpandEnv("$HOME/.hub")
// The module BasicManager is in charge of setting up basic, // non-dependant module elements, such as codec registration // and genesis verification. ModuleBasics = module.NewBasicManager( genutil.AppModuleBasic{}, auth.AppModuleBasic{}, bank.AppModuleBasic{}, staking.AppModuleBasic{}, mint.AppModuleBasic{}, distr.AppModuleBasic{}, gov.NewAppModuleBasic(paramsclient.ProposalHandler, distr.ProposalHandler), params.AppModuleBasic{}, crisis.AppModuleBasic{}, slashing.AppModuleBasic{}, supply.AppModuleBasic{}, ibc.AppModuleBasic{}, user.NewAppModuleBasic(), ) )
NewApp(){ // NOTE: Any module instantiated in the module manager that is later modified must be passed by reference here. app.manager = module.NewManager( genutil.NewAppModule(app.accountKeeper, app.stakingKeeper, app.BaseApp.DeliverTx), auth.NewAppModule(app.accountKeeper), bank.NewAppModule(app.bankKeeper, app.accountKeeper), crisis.NewAppModule(&app.crisisKeeper), supply.NewAppModule(app.supplyKeeper, app.accountKeeper), distr.NewAppModule(app.distrKeeper, app.supplyKeeper), gov.NewAppModule(app.govKeeper, app.supplyKeeper), mint.NewAppModule(app.mintKeeper), slashing.NewAppModule(app.slashingKeeper, app.stakingKeeper), staking.NewAppModule(app.stakingKeeper, app.accountKeeper, app.supplyKeeper), ibc.NewAppModule(app.ibcKeeper), user.NewAppModule(app.userKeeper), )
//... //配置路由和handler(包括Tx和查询) app.manager.RegisterRoutes(app.Router(), app.QueryRouter()) // 配置EndBlock\BeginBlock等回调 app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) //AnteHandler是特殊的实现,CheckTx和DeliverTx一般只会执行到对应的模块中,AnteHandler会在进入对应模块前执行,如验签等操作.. app.SetAnteHandler(auth.NewAnteHandler(app.accountKeeper, app.supplyKeeper, auth.DefaultSigVerificationGasConsumer)) app.SetEndBlocker(app.EndBlocker) }
//ModuleBasics定义在上面,使用在main中 //main rootCmd := &cobra.Command{ Use: "hub", Short: "Hub Daemon (server)", PersistentPreRunE: server.PersistentPreRunEFn(ctx), } rootCmd.AddCommand(server.StartCmd(ctx, newApp)) rootCmd.AddCommand(cmd.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome)) rootCmd.AddCommand(cmd.AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome)) rootCmd.AddCommand(cmd.GenerateTxCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome)) rootCmd.AddCommand(cmd.CollectGenTxsCmd(ctx, cdc, app.DefaultNodeHome)) rootCmd.AddCommand(cmd.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics))
|