2019-07-08 16:02:20 +00:00
|
|
|
package evm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-04-01 18:49:21 +00:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2019-08-14 23:52:45 +00:00
|
|
|
|
2019-07-08 16:02:20 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2019-07-25 20:38:55 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
2020-04-01 18:49:21 +00:00
|
|
|
|
2019-07-25 20:38:55 +00:00
|
|
|
"github.com/cosmos/ethermint/x/evm/client/cli"
|
2020-03-09 13:17:23 +00:00
|
|
|
"github.com/cosmos/ethermint/x/evm/keeper"
|
2019-07-08 16:02:20 +00:00
|
|
|
"github.com/cosmos/ethermint/x/evm/types"
|
|
|
|
)
|
|
|
|
|
2019-07-25 20:38:55 +00:00
|
|
|
var _ module.AppModuleBasic = AppModuleBasic{}
|
|
|
|
var _ module.AppModule = AppModule{}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// AppModuleBasic struct
|
2019-07-08 16:02:20 +00:00
|
|
|
type AppModuleBasic struct{}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// Name for app module basic
|
2019-07-08 16:02:20 +00:00
|
|
|
func (AppModuleBasic) Name() string {
|
|
|
|
return types.ModuleName
|
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// RegisterCodec registers types for module
|
2019-07-08 16:02:20 +00:00
|
|
|
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
|
|
|
types.RegisterCodec(cdc)
|
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// DefaultGenesis is json default structure
|
2020-08-23 21:41:54 +00:00
|
|
|
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
|
|
|
|
return types.ModuleCdc.MustMarshalJSON(types.DefaultGenesisState())
|
2019-07-08 16:02:20 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// ValidateGenesis is the validation check of the Genesis
|
2020-08-23 21:41:54 +00:00
|
|
|
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
|
2020-05-18 19:21:12 +00:00
|
|
|
var genesisState types.GenesisState
|
2020-08-23 21:41:54 +00:00
|
|
|
err := types.ModuleCdc.UnmarshalJSON(bz, &genesisState)
|
2019-07-08 16:02:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-18 19:21:12 +00:00
|
|
|
|
|
|
|
return genesisState.Validate()
|
2019-07-08 16:02:20 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// RegisterRESTRoutes Registers rest routes
|
2019-07-08 16:02:20 +00:00
|
|
|
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
|
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// GetQueryCmd Gets the root query command of this module
|
2019-07-08 16:02:20 +00:00
|
|
|
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
|
2019-07-25 20:38:55 +00:00
|
|
|
return cli.GetQueryCmd(types.ModuleName, cdc)
|
2019-07-08 16:02:20 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// GetTxCmd Gets the root tx command of this module
|
2019-07-08 16:02:20 +00:00
|
|
|
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
2020-10-22 20:39:51 +00:00
|
|
|
return nil
|
2019-07-08 16:02:20 +00:00
|
|
|
}
|
2019-07-25 20:38:55 +00:00
|
|
|
|
2020-04-16 15:47:39 +00:00
|
|
|
//____________________________________________________________________________
|
|
|
|
|
|
|
|
// AppModule implements an application module for the evm module.
|
2019-07-25 20:38:55 +00:00
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
|
|
|
keeper Keeper
|
2020-05-18 19:21:12 +00:00
|
|
|
ak types.AccountKeeper
|
2019-07-25 20:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule Object
|
2020-05-18 19:21:12 +00:00
|
|
|
func NewAppModule(k Keeper, ak types.AccountKeeper) AppModule {
|
2019-07-25 20:38:55 +00:00
|
|
|
return AppModule{
|
|
|
|
AppModuleBasic: AppModuleBasic{},
|
2020-03-09 13:17:23 +00:00
|
|
|
keeper: k,
|
2020-05-18 19:21:12 +00:00
|
|
|
ak: ak,
|
2019-07-25 20:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// Name is module name
|
2019-07-25 20:38:55 +00:00
|
|
|
func (AppModule) Name() string {
|
|
|
|
return types.ModuleName
|
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// RegisterInvariants interface for registering invariants
|
2020-12-15 18:43:06 +00:00
|
|
|
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
|
|
|
keeper.RegisterInvariants(ir, am.keeper)
|
|
|
|
}
|
2019-07-25 20:38:55 +00:00
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// Route specifies path for transactions
|
2019-07-25 20:38:55 +00:00
|
|
|
func (am AppModule) Route() string {
|
|
|
|
return types.RouterKey
|
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// NewHandler sets up a new handler for module
|
2019-07-25 20:38:55 +00:00
|
|
|
func (am AppModule) NewHandler() sdk.Handler {
|
2019-08-14 23:52:45 +00:00
|
|
|
return NewHandler(am.keeper)
|
2019-07-25 20:38:55 +00:00
|
|
|
}
|
2019-09-26 15:54:23 +00:00
|
|
|
|
|
|
|
// QuerierRoute sets up path for queries
|
2019-07-25 20:38:55 +00:00
|
|
|
func (am AppModule) QuerierRoute() string {
|
|
|
|
return types.ModuleName
|
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// NewQuerierHandler sets up new querier handler for module
|
2019-07-25 20:38:55 +00:00
|
|
|
func (am AppModule) NewQuerierHandler() sdk.Querier {
|
2020-03-09 13:17:23 +00:00
|
|
|
return keeper.NewQuerier(am.keeper)
|
2019-07-25 20:38:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// BeginBlock function for module at start of each block
|
2020-04-01 18:49:21 +00:00
|
|
|
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
|
2020-10-20 17:53:13 +00:00
|
|
|
am.keeper.BeginBlock(ctx, req)
|
2019-09-27 14:08:45 +00:00
|
|
|
}
|
2019-07-25 20:38:55 +00:00
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// EndBlock function for module at end of block
|
2020-04-01 18:49:21 +00:00
|
|
|
func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate {
|
2020-10-20 17:53:13 +00:00
|
|
|
return am.keeper.EndBlock(ctx, req)
|
2019-07-25 20:38:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// InitGenesis instantiates the genesis state
|
2020-08-23 21:41:54 +00:00
|
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
2020-03-09 13:17:23 +00:00
|
|
|
var genesisState types.GenesisState
|
2020-08-23 21:41:54 +00:00
|
|
|
types.ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
2020-11-27 18:42:04 +00:00
|
|
|
return InitGenesis(ctx, am.keeper, am.ak, genesisState)
|
2019-07-25 20:38:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 15:54:23 +00:00
|
|
|
// ExportGenesis exports the genesis state to be used by daemon
|
2020-08-23 21:41:54 +00:00
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
2020-05-18 19:21:12 +00:00
|
|
|
gs := ExportGenesis(ctx, am.keeper, am.ak)
|
2020-08-23 21:41:54 +00:00
|
|
|
return types.ModuleCdc.MustMarshalJSON(gs)
|
2019-07-25 20:38:55 +00:00
|
|
|
}
|