github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/erc20/module.go (about) 1 package erc20 2 3 import ( 4 "encoding/json" 5 6 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/upgrade" 7 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/params" 8 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/base" 9 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 abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types" 18 "github.com/fibonacci-chain/fbc/x/erc20/client/cli" 19 "github.com/fibonacci-chain/fbc/x/erc20/keeper" 20 "github.com/fibonacci-chain/fbc/x/erc20/types" 21 ) 22 23 var _ module.AppModuleBasic = AppModuleBasic{} 24 var _ module.AppModule = AppModule{} 25 var _ upgrade.UpgradeModule = AppModule{} 26 27 // AppModuleBasic struct 28 type AppModuleBasic struct{} 29 30 // Name for app module basic 31 func (AppModuleBasic) Name() string { 32 return types.ModuleName 33 } 34 35 // RegisterCodec registers types for module 36 func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { 37 types.RegisterCodec(cdc) 38 } 39 40 // DefaultGenesis is json default structure 41 func (AppModuleBasic) DefaultGenesis() json.RawMessage { 42 return nil 43 } 44 45 // ValidateGenesis is the validation check of the Genesis 46 func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { 47 return nil 48 } 49 50 // RegisterRESTRoutes Registers rest routes 51 func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { 52 } 53 54 // GetQueryCmd Gets the root query command of this module 55 func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { 56 return cli.GetQueryCmd(types.ModuleName, cdc) 57 } 58 59 // GetTxCmd Gets the root tx command of this module 60 func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { 61 return nil 62 } 63 64 //____________________________________________________________________________ 65 66 // AppModule implements an application module for the erc20 module. 67 type AppModule struct { 68 *base.BaseIBCUpgradeModule 69 AppModuleBasic 70 keeper Keeper 71 } 72 73 // NewAppModule creates a new AppModule Object 74 func NewAppModule(k Keeper) AppModule { 75 ret := AppModule{ 76 AppModuleBasic: AppModuleBasic{}, 77 keeper: k, 78 } 79 ret.BaseIBCUpgradeModule = base.NewBaseIBCUpgradeModule(ret) 80 return ret 81 } 82 83 // Name is module name 84 func (AppModule) Name() string { 85 return types.ModuleName 86 } 87 88 // RegisterInvariants interface for registering invariants 89 func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { 90 keeper.RegisterInvariants(ir, am.keeper) 91 } 92 93 // Route specifies path for transactions 94 func (am AppModule) Route() string { 95 return types.RouterKey 96 } 97 98 // NewHandler sets up a new handler for module 99 func (am AppModule) NewHandler() sdk.Handler { 100 return NewHandler(am.keeper) 101 } 102 103 // QuerierRoute sets up path for queries 104 func (am AppModule) QuerierRoute() string { 105 return types.ModuleName 106 } 107 108 // NewQuerierHandler sets up new querier handler for module 109 func (am AppModule) NewQuerierHandler() sdk.Querier { 110 return keeper.NewQuerier(am.keeper) 111 } 112 113 // BeginBlock function for module at start of each block 114 func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {} 115 116 // EndBlock function for module at end of block 117 func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate { 118 return []abci.ValidatorUpdate{} 119 } 120 121 // InitGenesis instantiates the genesis state 122 func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { 123 return nil 124 } 125 126 func (am AppModule) initGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { 127 var genesisState types.GenesisState 128 types.ModuleCdc.MustUnmarshalJSON(data, &genesisState) 129 return InitGenesis(ctx, am.keeper, genesisState) 130 } 131 132 // ExportGenesis exports the genesis state to be used by daemon 133 func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { 134 return nil 135 } 136 137 func (am AppModule) RegisterTask() upgrade.HeightTask { 138 return upgrade.NewHeightTask(0, func(ctx sdk.Context) error { 139 if am.Sealed() { 140 return nil 141 } 142 am.initGenesis(ctx, types.ModuleCdc.MustMarshalJSON(types.DefaultGenesisState())) 143 return nil 144 }) 145 } 146 147 func (am AppModule) RegisterParam() params.ParamSet { 148 return nil 149 }