github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/params/module.go (about) 1 package params 2 3 import ( 4 "encoding/json" 5 "fmt" 6 sim "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/simulation" 7 "math/rand" 8 9 "github.com/fibonacci-chain/fbc/x/params/client/cli" 10 "github.com/fibonacci-chain/fbc/x/params/types" 11 12 "github.com/gorilla/mux" 13 "github.com/spf13/cobra" 14 15 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 16 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 17 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 18 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module" 19 abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types" 20 ) 21 22 var ( 23 _ module.AppModuleBasic = AppModuleBasic{} 24 _ module.AppModule = AppModule{} 25 ) 26 27 // GenesisState contains all params state that must be provided at genesis 28 type GenesisState struct { 29 Params types.Params `json:"params" yaml:"params"` 30 } 31 32 // DefaultGenesisState returns the default genesis state of this module 33 func DefaultGenesisState() GenesisState { 34 return GenesisState{ 35 Params: types.DefaultParams(), 36 } 37 } 38 39 // ValidateGenesis checks if parameters are within valid ranges 40 func ValidateGenesis(data GenesisState) error { 41 if !data.Params.MinDeposit.IsValid() { 42 return fmt.Errorf("params deposit amount must be a valid sdk.Coins amount, is %s", 43 data.Params.MinDeposit.String()) 44 } 45 return nil 46 } 47 48 // AppModuleBasic is the struct of app module basics object 49 type AppModuleBasic struct{} 50 51 // Name returns the module name 52 func (AppModuleBasic) Name() string { 53 return ModuleName 54 } 55 56 // RegisterCodec registers module codec 57 func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { 58 RegisterCodec(cdc) 59 } 60 61 // DefaultGenesis returns the default genesis state in json raw message 62 func (AppModuleBasic) DefaultGenesis() json.RawMessage { 63 return ModuleCdc.MustMarshalJSON(DefaultGenesisState()) 64 } 65 66 // ValidateGenesis gives a quick validity check for module genesis 67 func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { 68 var data GenesisState 69 err := ModuleCdc.UnmarshalJSON(bz, &data) 70 if err != nil { 71 return err 72 } 73 return ValidateGenesis(data) 74 } 75 76 // nolint 77 func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {} 78 func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil } 79 func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { 80 return cli.GetQueryCmd(RouterKey, cdc) 81 } 82 83 // AppModule is the struct of this app module 84 type AppModule struct { 85 AppModuleBasic 86 keeper Keeper 87 } 88 89 // NewAppModule creates a new AppModule object 90 func NewAppModule(keeper Keeper) AppModule { 91 return AppModule{ 92 AppModuleBasic: AppModuleBasic{}, 93 keeper: keeper, 94 } 95 } 96 97 // Route returns the module route name 98 func (AppModule) Route() string { 99 return RouterKey 100 } 101 102 // InitGenesis initializes the module genesis state 103 func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { 104 var genesisState GenesisState 105 ModuleCdc.MustUnmarshalJSON(data, &genesisState) 106 am.keeper.SetParams(ctx, genesisState.Params) 107 return []abci.ValidatorUpdate{} 108 } 109 110 // ExportGenesis exports the module genesis state 111 func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { 112 gs := GenesisState{ 113 Params: am.keeper.GetParams(ctx), 114 } 115 return ModuleCdc.MustMarshalJSON(gs) 116 } 117 118 // nolint 119 func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} 120 func (AppModule) NewHandler() sdk.Handler { return nil } 121 func (AppModule) QuerierRoute() string { return RouterKey } 122 func (am AppModule) NewQuerierHandler() sdk.Querier { return NewQuerier(am.keeper) } 123 func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} 124 func (AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { 125 return []abci.ValidatorUpdate{} 126 } 127 128 // AppModuleSimulation functions 129 // TODO: implement the AppModuleSimulation interface 130 131 // GenerateGenesisState creates a randomized GenState of the staking module. 132 func (AppModule) GenerateGenesisState(simState *module.SimulationState) { 133 } 134 135 // ProposalContents doesn't return any content functions for governance proposals. 136 func (AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalContent { 137 return nil 138 } 139 140 // RandomizedParams creates randomized staking param changes for the simulator. 141 func (AppModule) RandomizedParams(r *rand.Rand) []sim.ParamChange { 142 return nil 143 } 144 145 // RegisterStoreDecoder registers a decoder for staking module's types 146 func (AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { 147 148 } 149 150 // WeightedOperations returns the all the staking module operations with their respective weights. 151 func (am AppModule) WeightedOperations(simState module.SimulationState) []sim.WeightedOperation { 152 return nil 153 }