github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/auth/module.go (about) 1 package auth 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/base" 7 "math/rand" 8 9 abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types" 10 "github.com/gorilla/mux" 11 "github.com/spf13/cobra" 12 13 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 14 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 15 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 16 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module" 17 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/client/cli" 18 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/client/rest" 19 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/simulation" 20 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/types" 21 sim "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/simulation" 22 ) 23 24 var ( 25 _ module.AppModule = AppModule{} 26 _ module.AppModuleBasic = AppModuleBasic{} 27 _ module.AppModuleSimulation = AppModule{} 28 ) 29 30 // AppModuleBasic defines the basic application module used by the auth module. 31 type AppModuleBasic struct{} 32 33 // Name returns the auth module's name. 34 func (AppModuleBasic) Name() string { 35 return types.ModuleName 36 } 37 38 // RegisterCodec registers the auth module's types for the given codec. 39 func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { 40 types.RegisterCodec(cdc) 41 } 42 43 // DefaultGenesis returns default genesis state as raw bytes for the auth 44 // module. 45 func (AppModuleBasic) DefaultGenesis() json.RawMessage { 46 return types.ModuleCdc.MustMarshalJSON(types.DefaultGenesisState()) 47 } 48 49 // ValidateGenesis performs genesis state validation for the auth module. 50 func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { 51 var data types.GenesisState 52 if err := types.ModuleCdc.UnmarshalJSON(bz, &data); err != nil { 53 return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) 54 } 55 56 return types.ValidateGenesis(data) 57 } 58 59 // RegisterRESTRoutes registers the REST routes for the auth module. 60 func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { 61 rest.RegisterRoutes(ctx, rtr, types.StoreKey) 62 } 63 64 // GetTxCmd returns the root tx command for the auth module. 65 func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { 66 return cli.GetTxCmd(cdc) 67 } 68 69 // GetQueryCmd returns the root query command for the auth module. 70 func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { 71 return cli.GetQueryCmd(cdc) 72 } 73 74 //____________________________________________________________________________ 75 76 // AppModule implements an application module for the auth module. 77 type AppModule struct { 78 AppModuleBasic 79 80 accountKeeper AccountKeeper 81 *base.BaseIBCUpgradeModule 82 } 83 84 // NewAppModule creates a new AppModule object 85 func NewAppModule(accountKeeper AccountKeeper) AppModule { 86 ret := AppModule{ 87 AppModuleBasic: AppModuleBasic{}, 88 accountKeeper: accountKeeper, 89 } 90 ret.BaseIBCUpgradeModule = base.NewBaseIBCUpgradeModule(ret) 91 return ret 92 } 93 94 // Name returns the auth module's name. 95 func (AppModule) Name() string { 96 return types.ModuleName 97 } 98 99 // RegisterInvariants performs a no-op. 100 func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} 101 102 // Route returns the message routing key for the auth module. 103 func (AppModule) Route() string { return "" } 104 105 // NewHandler returns an sdk.Handler for the auth module. 106 func (AppModule) NewHandler() sdk.Handler { return nil } 107 108 // QuerierRoute returns the auth module's querier route name. 109 func (AppModule) QuerierRoute() string { 110 return types.QuerierRoute 111 } 112 113 // NewQuerierHandler returns the auth module sdk.Querier. 114 func (am AppModule) NewQuerierHandler() sdk.Querier { 115 return NewQuerier(am.accountKeeper) 116 } 117 118 // InitGenesis performs genesis initialization for the auth module. It returns 119 // no validator updates. 120 func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { 121 var genesisState GenesisState 122 types.ModuleCdc.MustUnmarshalJSON(data, &genesisState) 123 InitGenesis(ctx, am.accountKeeper, genesisState) 124 return []abci.ValidatorUpdate{} 125 } 126 127 // ExportGenesis returns the exported genesis state as raw bytes for the auth 128 // module. 129 func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { 130 gs := ExportGenesis(ctx, am.accountKeeper) 131 return types.ModuleCdc.MustMarshalJSON(gs) 132 } 133 134 // BeginBlock returns the begin blocker for the auth module. 135 func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} 136 137 // EndBlock returns the end blocker for the auth module. It returns no validator 138 // updates. 139 func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { 140 return []abci.ValidatorUpdate{} 141 } 142 143 //____________________________________________________________________________ 144 145 // AppModuleSimulation functions 146 147 // GenerateGenesisState creates a randomized GenState of the auth module 148 func (AppModule) GenerateGenesisState(simState *module.SimulationState) { 149 simulation.RandomizedGenState(simState) 150 } 151 152 // ProposalContents doesn't return any content functions for governance proposals. 153 func (AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalContent { 154 return nil 155 } 156 157 // RandomizedParams creates randomized auth param changes for the simulator. 158 func (AppModule) RandomizedParams(r *rand.Rand) []sim.ParamChange { 159 return simulation.ParamChanges(r) 160 } 161 162 // RegisterStoreDecoder registers a decoder for auth module's types 163 func (AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { 164 sdr[StoreKey] = simulation.DecodeStore 165 } 166 167 // WeightedOperations doesn't return any auth module operation. 168 func (AppModule) WeightedOperations(_ module.SimulationState) []sim.WeightedOperation { 169 return nil 170 }