/
module.go
146 lines (122 loc) · 4.74 KB
/
module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package evm
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/evmos/ethermint/x/evm"
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
"github.com/evmos/ethermint/x/evm/types"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
fxtypes "github.com/functionx/fx-core/v7/types"
"github.com/functionx/fx-core/v7/x/evm/client/cli"
"github.com/functionx/fx-core/v7/x/evm/keeper"
fxevmtypes "github.com/functionx/fx-core/v7/x/evm/types"
)
var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.EndBlockAppModule = AppModule{}
)
// AppModuleBasic defines the basic application module used by the evm module.
type AppModuleBasic struct {
evm.AppModuleBasic
}
// DefaultGenesis returns default genesis state as raw bytes for the evm
// module.
func (am AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
genesisState := types.DefaultGenesisState()
genesisState.Params.EvmDenom = fxtypes.DefaultDenom
return cdc.MustMarshalJSON(genesisState)
}
// RegisterLegacyAminoCodec registers the evm module's types for the given codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
fxevmtypes.RegisterLegacyAminoCodec(cdc)
}
// RegisterInterfaces registers interfaces and implementations of the evm module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
fxevmtypes.RegisterInterfaces(registry)
}
// GetTxCmd returns the root tx command for the evm module.
func (AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd()
}
// GetQueryCmd returns no root query command for the evm module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}
// AppModule implements an application module for the evm module.
type AppModule struct {
AppModuleBasic
keeper *keeper.Keeper
accountKeeper types.AccountKeeper
legacyAmino *codec.LegacyAmino
paramsStoreKey storetypes.StoreKey
legacySubspace types.Subspace
}
// NewAppModule creates a new AppModule object
func NewAppModule(k *keeper.Keeper, accountKeeper types.AccountKeeper, legacyAmino *codec.LegacyAmino, paramsStoreKey storetypes.StoreKey, legacySubspace types.Subspace) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: k,
accountKeeper: accountKeeper,
legacyAmino: legacyAmino,
paramsStoreKey: paramsStoreKey,
legacySubspace: legacySubspace,
}
}
// RegisterInvariants implements app module
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), am.keeper)
fxevmtypes.RegisterMsgServer(cfg.MsgServer(), am.keeper)
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := evmkeeper.NewMigrator(*am.keeper.Keeper, am.legacySubspace)
err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4)
if err != nil {
panic(err)
}
if err := cfg.RegisterMigration(types.ModuleName, 4, m.Migrate4to5); err != nil {
panic(err)
}
}
// Deprecated: Route returns the message routing key
func (am AppModule) Route() sdk.Route {
return sdk.Route{}
}
// QuerierRoute implements app module
func (am AppModule) QuerierRoute() string { return "" }
// LegacyQuerierHandler returns no sdk.Querier
func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier {
return nil
}
// EndBlock returns the end blocker for the evm module. It returns no validator
// updates.
func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate {
return am.keeper.EndBlock(ctx, req)
}
// InitGenesis performs genesis initialization for the evm module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
am.keeper.InitGenesis(ctx, am.accountKeeper, genesisState)
return []abci.ValidatorUpdate{}
}
// ExportGenesis returns the exported genesis state as raw bytes for the evm
// module.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
state := evm.ExportGenesis(ctx, am.keeper.Keeper, am.accountKeeper)
return cdc.MustMarshalJSON(state)
}
// ConsensusVersion implements AppModule/ConsensusVersion.
func (am AppModule) ConsensusVersion() uint64 {
return 5
}