github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/evm/module.go (about) 1 package evm 2 3 import ( 4 "encoding/json" 5 6 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/baseapp" 7 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 8 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 9 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 10 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module" 11 abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types" 12 "github.com/fibonacci-chain/fbc/x/evm/client/cli" 13 "github.com/fibonacci-chain/fbc/x/evm/keeper" 14 "github.com/fibonacci-chain/fbc/x/evm/types" 15 "github.com/gorilla/mux" 16 "github.com/spf13/cobra" 17 ) 18 19 var _ module.AppModuleBasic = AppModuleBasic{} 20 var _ module.AppModule = AppModule{} 21 22 // AppModuleBasic struct 23 type AppModuleBasic struct{} 24 25 // Name for app module basic 26 func (AppModuleBasic) Name() string { 27 return types.ModuleName 28 } 29 30 // RegisterCodec registers types for module 31 func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { 32 types.RegisterCodec(cdc) 33 } 34 35 // DefaultGenesis is json default structure 36 func (AppModuleBasic) DefaultGenesis() json.RawMessage { 37 return types.ModuleCdc.MustMarshalJSON(types.DefaultGenesisState()) 38 } 39 40 // ValidateGenesis is the validation check of the Genesis 41 func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { 42 var genesisState types.GenesisState 43 err := types.ModuleCdc.UnmarshalJSON(bz, &genesisState) 44 if err != nil { 45 return err 46 } 47 48 return genesisState.Validate() 49 } 50 51 // RegisterRESTRoutes Registers rest routes 52 func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { 53 } 54 55 // GetQueryCmd Gets the root query command of this module 56 func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { 57 return cli.GetQueryCmd(types.ModuleName, cdc) 58 } 59 60 // GetTxCmd Gets the root tx command of this module 61 func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { 62 return nil 63 } 64 65 //____________________________________________________________________________ 66 67 // AppModule implements an application module for the evm module. 68 type AppModule struct { 69 AppModuleBasic 70 keeper *Keeper 71 ak types.AccountKeeper 72 } 73 74 // NewAppModule creates a new AppModule Object 75 func NewAppModule(k *Keeper, ak types.AccountKeeper) AppModule { 76 return AppModule{ 77 AppModuleBasic: AppModuleBasic{}, 78 keeper: k, 79 ak: ak, 80 } 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 am.keeper.BeginBlock(ctx, req) 116 } 117 118 // EndBlock function for module at end of block 119 func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate { 120 baseapp.InstanceOfHistoryGasUsedRecordDB().FlushHgu() 121 return am.keeper.EndBlock(ctx, req) 122 } 123 124 // InitGenesis instantiates the genesis state 125 func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate { 126 var genesisState types.GenesisState 127 types.ModuleCdc.MustUnmarshalJSON(data, &genesisState) 128 return InitGenesis(ctx, *am.keeper, am.ak, genesisState) 129 } 130 131 // ExportGenesis exports the genesis state to be used by daemon 132 func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage { 133 gs := ExportGenesis(ctx, *am.keeper, am.ak) 134 return types.ModuleCdc.MustMarshalJSON(gs) 135 }