github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/genutil/module.go (about) 1 package genutil 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "github.com/gorilla/mux" 8 "github.com/spf13/cobra" 9 10 abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types" 11 12 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 13 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 14 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 15 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module" 16 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/genutil/types" 17 ) 18 19 var ( 20 _ module.AppModuleGenesis = AppModule{} 21 _ module.AppModuleBasic = AppModuleBasic{} 22 ) 23 24 // AppModuleBasic defines the basic application module used by the genutil module. 25 type AppModuleBasic struct{} 26 27 // Name returns the genutil module's name. 28 func (AppModuleBasic) Name() string { 29 return ModuleName 30 } 31 32 // RegisterCodec registers the genutil module's types for the given codec. 33 func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {} 34 35 // DefaultGenesis returns default genesis state as raw bytes for the genutil 36 // module. 37 func (AppModuleBasic) DefaultGenesis() json.RawMessage { 38 return ModuleCdc.MustMarshalJSON(types.DefaultGenesisState()) 39 } 40 41 // ValidateGenesis performs genesis state validation for the genutil module. 42 func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { 43 var data GenesisState 44 if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil { 45 return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) 46 } 47 48 return ValidateGenesis(data) 49 } 50 51 // RegisterRESTRoutes registers the REST routes for the genutil module. 52 func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {} 53 54 // GetTxCmd returns no root tx command for the genutil module. 55 func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil } 56 57 // GetQueryCmd returns no root query command for the genutil module. 58 func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } 59 60 //____________________________________________________________________________ 61 62 // AppModule implements an application module for the genutil module. 63 type AppModule struct { 64 AppModuleBasic 65 66 accountKeeper types.AccountKeeper 67 stakingKeeper types.StakingKeeper 68 deliverTx deliverTxfn 69 } 70 71 // NewAppModule creates a new AppModule object 72 func NewAppModule(accountKeeper types.AccountKeeper, 73 stakingKeeper types.StakingKeeper, deliverTx deliverTxfn) module.AppModule { 74 75 return module.NewGenesisOnlyAppModule(AppModule{ 76 AppModuleBasic: AppModuleBasic{}, 77 accountKeeper: accountKeeper, 78 stakingKeeper: stakingKeeper, 79 deliverTx: deliverTx, 80 }) 81 } 82 83 // InitGenesis performs genesis initialization for the genutil module. It returns 84 // no validator updates. 85 func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { 86 var genesisState GenesisState 87 ModuleCdc.MustUnmarshalJSON(data, &genesisState) 88 return InitGenesis(ctx, ModuleCdc, am.stakingKeeper, am.deliverTx, genesisState) 89 } 90 91 // ExportGenesis returns the exported genesis state as raw bytes for the genutil 92 // module. 93 func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { 94 return am.DefaultGenesis() 95 }