module.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package ibc_composability_mw
  2. import (
  3. "encoding/json"
  4. "math/rand"
  5. "github.com/wormhole-foundation/wormchain/x/ibc-composability-mw/keeper"
  6. "github.com/wormhole-foundation/wormchain/x/ibc-composability-mw/types"
  7. "github.com/gorilla/mux"
  8. "github.com/grpc-ecosystem/grpc-gateway/runtime"
  9. "github.com/spf13/cobra"
  10. abci "github.com/tendermint/tendermint/abci/types"
  11. "github.com/cosmos/cosmos-sdk/client"
  12. "github.com/cosmos/cosmos-sdk/codec"
  13. codectypes "github.com/cosmos/cosmos-sdk/codec/types"
  14. sdk "github.com/cosmos/cosmos-sdk/types"
  15. "github.com/cosmos/cosmos-sdk/types/module"
  16. simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
  17. )
  18. // ConsensusVersion defines the current ibc-composability-mw module consensus version.
  19. const ConsensusVersion = 1
  20. var (
  21. _ module.AppModule = AppModule{}
  22. _ module.AppModuleBasic = AppModuleBasic{}
  23. _ module.AppModuleSimulation = AppModule{}
  24. )
  25. // AppModuleBasic is the router AppModuleBasic
  26. type AppModuleBasic struct{}
  27. // Name implements AppModuleBasic interface
  28. func (AppModuleBasic) Name() string {
  29. return types.ModuleName
  30. }
  31. // RegisterLegacyAminoCodec implements AppModuleBasic interface
  32. func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {}
  33. // RegisterInterfaces registers module concrete types into protobuf Any.
  34. func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {}
  35. // DefaultGenesis returns default genesis state as raw bytes for the
  36. // ibc-composability-mw module.
  37. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
  38. return []byte("{}")
  39. }
  40. // ValidateGenesis performs genesis state validation for the ibc-composability-mw module.
  41. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
  42. return nil
  43. }
  44. // RegisterRESTRoutes implements AppModuleBasic interface
  45. func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
  46. // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
  47. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {}
  48. // GetTxCmd implements AppModuleBasic interface
  49. func (AppModuleBasic) GetTxCmd() *cobra.Command {
  50. return nil
  51. }
  52. // GetQueryCmd implements AppModuleBasic interface
  53. func (AppModuleBasic) GetQueryCmd() *cobra.Command {
  54. return nil
  55. }
  56. // AppModule represents the AppModule for this module
  57. type AppModule struct {
  58. AppModuleBasic
  59. keeper *keeper.Keeper
  60. }
  61. // NewAppModule creates a new router module
  62. func NewAppModule(keeper *keeper.Keeper) AppModule {
  63. return AppModule{keeper: keeper}
  64. }
  65. // RegisterInvariants implements the AppModule interface
  66. func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
  67. // Route implements the AppModule interface
  68. func (am AppModule) Route() sdk.Route {
  69. return sdk.Route{}
  70. }
  71. // QuerierRoute implements the AppModule interface
  72. func (AppModule) QuerierRoute() string {
  73. return ""
  74. }
  75. // LegacyQuerierHandler implements the AppModule interface
  76. func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier {
  77. return nil
  78. }
  79. // RegisterServices registers module services.
  80. func (am AppModule) RegisterServices(cfg module.Configurator) {}
  81. // InitGenesis performs genesis initialization for the module. It returns
  82. // no validator updates.
  83. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
  84. var genesisState types.GenesisState
  85. cdc.MustUnmarshalJSON(data, &genesisState)
  86. am.keeper.InitGenesis(ctx, genesisState)
  87. return []abci.ValidatorUpdate{}
  88. }
  89. // ExportGenesis returns the exported genesis state as raw bytes for the ibc-router
  90. // module.
  91. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
  92. gs := am.keeper.ExportGenesis(ctx)
  93. return cdc.MustMarshalJSON(gs)
  94. }
  95. // ConsensusVersion implements AppModule/ConsensusVersion.
  96. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
  97. // BeginBlock implements the AppModule interface
  98. func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
  99. // EndBlock implements the AppModule interface
  100. func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
  101. return []abci.ValidatorUpdate{}
  102. }
  103. // AppModuleSimulation functions
  104. // GenerateGenesisState creates a randomized GenState of the router module.
  105. func (AppModule) GenerateGenesisState(_ *module.SimulationState) {}
  106. // ProposalContents doesn't return any content functions for governance proposals.
  107. func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
  108. return nil
  109. }
  110. // RandomizedParams creates randomized ibc-router param changes for the simulator.
  111. func (AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange {
  112. return nil
  113. }
  114. // RegisterStoreDecoder registers a decoder for router module's types
  115. func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
  116. // WeightedOperations returns the all the router module operations with their respective weights.
  117. func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
  118. return nil
  119. }