github.com/Finschia/finschia-sdk@v0.49.1/x/fbridge/module/module.go (about) 1 package module 2 3 import ( 4 "context" 5 "encoding/json" 6 "fmt" 7 8 ocabci "github.com/Finschia/ostracon/abci/types" 9 "github.com/grpc-ecosystem/grpc-gateway/runtime" 10 "github.com/spf13/cobra" 11 abci "github.com/tendermint/tendermint/abci/types" 12 13 sdkclient "github.com/Finschia/finschia-sdk/client" 14 "github.com/Finschia/finschia-sdk/codec" 15 codectypes "github.com/Finschia/finschia-sdk/codec/types" 16 sdk "github.com/Finschia/finschia-sdk/types" 17 "github.com/Finschia/finschia-sdk/types/module" 18 "github.com/Finschia/finschia-sdk/x/fbridge/client/cli" 19 "github.com/Finschia/finschia-sdk/x/fbridge/keeper" 20 "github.com/Finschia/finschia-sdk/x/fbridge/types" 21 ) 22 23 const ( 24 consensusVersion uint64 = 1 25 ) 26 27 var ( 28 _ module.AppModuleBasic = AppModuleBasic{} 29 _ module.AppModuleGenesis = AppModule{} 30 _ module.AppModule = AppModule{} 31 _ module.BeginBlockAppModule = AppModule{} 32 _ module.EndBlockAppModule = AppModule{} 33 ) 34 35 // AppModuleBasic defines the basic application module used by the fbridge module. 36 type AppModuleBasic struct{} 37 38 // Name returns the ModuleName 39 func (AppModuleBasic) Name() string { 40 return types.ModuleName 41 } 42 43 // RegisterLegacyAminoCodec registers the fbridge types on the LegacyAmino codec 44 func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} 45 46 // DefaultGenesis returns default genesis state as raw bytes for the fbridge 47 // module. 48 func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { 49 return cdc.MustMarshalJSON(types.DefaultGenesisState()) 50 } 51 52 // ValidateGenesis performs genesis state validation for the fbridge module. 53 func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEncodingConfig, bz json.RawMessage) error { 54 var data types.GenesisState 55 if err := cdc.UnmarshalJSON(bz, &data); err != nil { 56 return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) 57 } 58 59 return types.ValidateGenesis(data) 60 } 61 62 // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the fbridge module. 63 func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { 64 if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { 65 panic(err) 66 } 67 } 68 69 // GetQueryCmd returns the cli query commands for this module 70 func (AppModuleBasic) GetQueryCmd() *cobra.Command { 71 return cli.NewQueryCmd() 72 } 73 74 // GetTxCmd returns the transaction commands for this module 75 func (AppModuleBasic) GetTxCmd() *cobra.Command { 76 return cli.NewTxCmd() 77 } 78 79 func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { 80 types.RegisterInterfaces(registry) 81 } 82 83 // ____________________________________________________________________________ 84 85 // AppModule implements an application module for the fbridge module. 86 type AppModule struct { 87 AppModuleBasic 88 89 keeper keeper.Keeper 90 } 91 92 // NewAppModule creates a new AppModule object 93 func NewAppModule(_ codec.Codec, keeper keeper.Keeper) AppModule { 94 return AppModule{ 95 keeper: keeper, 96 } 97 } 98 99 // RegisterServices registers a GRPC query service to respond to the 100 // module-specific GRPC queries. 101 func (am AppModule) RegisterServices(cfg module.Configurator) { 102 types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServer(am.keeper)) 103 types.RegisterQueryServer(cfg.QueryServer(), am.keeper) 104 } 105 106 // InitGenesis performs genesis initialization for the fbridge module. It returns 107 // no validator updates. 108 func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { 109 var genesisState types.GenesisState 110 cdc.MustUnmarshalJSON(data, &genesisState) 111 if err := am.keeper.InitGenesis(ctx, &genesisState); err != nil { 112 panic(err) 113 } 114 return []abci.ValidatorUpdate{} 115 } 116 117 // ExportGenesis returns the exported genesis state as raw bytes for the fbridge 118 // module. 119 func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { 120 gs := am.keeper.ExportGenesis(ctx) 121 return cdc.MustMarshalJSON(gs) 122 } 123 124 // ConsensusVersion implements AppModule/ConsensusVersion. 125 func (AppModule) ConsensusVersion() uint64 { return consensusVersion } 126 127 // BeginBlock returns the begin blocker for the fbridge module. 128 func (am AppModule) BeginBlock(ctx sdk.Context, _ ocabci.RequestBeginBlock) { 129 am.keeper.BeginBlocker(ctx) 130 } 131 132 // EndBlock returns the end blocker for the fbridge module. 133 // It returns no validator updates. 134 func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { 135 am.keeper.EndBlocker(ctx) 136 return []abci.ValidatorUpdate{} 137 } 138 139 // RegisterInvariants does nothing, there are no invariants to enforce 140 func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { 141 keeper.RegisterInvariants(ir, am.keeper) 142 } 143 144 // Deprecated: Route does nothing. 145 func (am AppModule) Route() sdk.Route { return sdk.NewRoute(types.RouterKey, nil) } 146 147 // Deprecated: QuerierRoute does nothing. 148 func (am AppModule) QuerierRoute() string { return types.QuerierRoute } 149 150 // Deprecated: LegacyQuerierHandler does nothing. 151 func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { return nil } 152 153 // ____________________________________________________________________________ 154 155 // AppModuleSimulation functions 156 157 // // GenerateGenesisState creates a randomized GenState of the fbridge module. 158 // func (AppModule) GenerateGenesisState(simState *module.SimulationState) { 159 // simulation.RandomizedGenState(simState) 160 // } 161 162 // // ProposalContents returns all the fbridge content functions used to 163 // // simulate fbridge proposals. 164 // func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { 165 // return simulation.ProposalContents() 166 // } 167 168 // // RegisterStoreDecoder registers a decoder for fbridge module's types 169 // func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { 170 // sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) 171 // } 172 173 //// WeightedOperations returns the all the gov module operations with their respective weights. 174 // func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { 175 // return simulation.WeightedOperations( 176 // simState.AppParams, simState.Cdc, simState.TxConfig, 177 // am.accountKeeper, am.bankKeeper, am.keeper, 178 // ) 179 //}