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