-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
255 lines (207 loc) · 8.54 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package ibc
import (
"context"
"encoding/json"
"fmt"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/types/upgrade"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/x/params"
ibcclient "github.com/evoblockchain/evochain/libs/ibc-go/modules/core/02-client"
"math/rand"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
clientCtx "github.com/evoblockchain/evochain/libs/cosmos-sdk/client/context"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/codec"
codectypes "github.com/evoblockchain/evochain/libs/cosmos-sdk/codec/types"
sdk "github.com/evoblockchain/evochain/libs/cosmos-sdk/types"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/types/module"
simulation2 "github.com/evoblockchain/evochain/libs/cosmos-sdk/x/simulation"
clienttypes "github.com/evoblockchain/evochain/libs/ibc-go/modules/core/02-client/types"
connectiontypes "github.com/evoblockchain/evochain/libs/ibc-go/modules/core/03-connection/types"
channeltypes "github.com/evoblockchain/evochain/libs/ibc-go/modules/core/04-channel/types"
host "github.com/evoblockchain/evochain/libs/ibc-go/modules/core/24-host"
"github.com/evoblockchain/evochain/libs/ibc-go/modules/core/base"
"github.com/evoblockchain/evochain/libs/ibc-go/modules/core/client/cli"
"github.com/evoblockchain/evochain/libs/ibc-go/modules/core/keeper"
"github.com/evoblockchain/evochain/libs/ibc-go/modules/core/simulation"
"github.com/evoblockchain/evochain/libs/ibc-go/modules/core/types"
abci "github.com/evoblockchain/evochain/libs/tendermint/abci/types"
tmtypes "github.com/evoblockchain/evochain/libs/tendermint/types"
"github.com/spf13/cobra"
)
var (
_ module.AppModuleAdapter = AppModule{}
_ module.AppModuleBasicAdapter = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
)
// AppModuleBasic defines the basic application module used by the ibc module.
type AppModuleBasic struct{}
var _ module.AppModuleBasic = AppModuleBasic{}
// Name returns the ibc module's name.
func (AppModuleBasic) Name() string {
return host.ModuleName
}
// DefaultGenesis returns default genesis state as raw bytes for the ibc
// module.
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
return nil
}
// ValidateGenesis performs genesis state validation for the mint module.
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
return nil
}
// RegisterRESTRoutes does nothing. IBC does not support legacy REST routes.
func (AppModuleBasic) RegisterRESTRoutes(ctx clientCtx.CLIContext, rtr *mux.Router) {}
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
types.RegisterCodec(cdc)
}
// TODO
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(ctx clientCtx.CLIContext, mux *runtime.ServeMux) {
clienttypes.RegisterQueryHandlerClient(context.Background(), mux, clienttypes.NewQueryClient(ctx))
connectiontypes.RegisterQueryHandlerClient(context.Background(), mux, connectiontypes.NewQueryClient(ctx))
channeltypes.RegisterQueryHandlerClient(context.Background(), mux, channeltypes.NewQueryClient(ctx))
}
// GetTxCmd returns the root tx command for the ibc module.
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
return nil
}
func (am AppModuleBasic) GetTxCmdV2(cdc *codec.CodecProxy, reg codectypes.InterfaceRegistry) *cobra.Command {
return cli.GetTxCmd(cdc, reg)
}
// GetQueryCmd returns no root query command for the ibc module.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return nil
}
func (AppModuleBasic) GetQueryCmdV2(cdc *codec.CodecProxy, reg codectypes.InterfaceRegistry) *cobra.Command {
return cli.GetQueryCmd(cdc, reg)
}
// RegisterInterfaces registers module concrete types into protobuf Any.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// AppModule implements an application module for the ibc module.
type AppModule struct {
AppModuleBasic
*base.BaseIBCUpgradeModule
keeper *keeper.Keeper
// create localhost by default
createLocalhost bool
}
// NewAppModule creates a new AppModule object
func NewAppModule(k *keeper.Keeper) AppModule {
ret := AppModule{
keeper: k,
}
ret.BaseIBCUpgradeModule = base.NewBaseIBCUpgradeModule(ret)
return ret
}
// TODO
func (a AppModule) NewQuerierHandler() sdk.Querier {
return nil
}
func (a AppModule) NewHandler() sdk.Handler {
return NewHandler(*a.keeper)
}
// Name returns the ibc module's name.
func (AppModule) Name() string {
return host.ModuleName
}
// RegisterInvariants registers the ibc module invariants.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
// TODO:
}
// Route returns the message routing key for the ibc module.
func (am AppModule) Route() string {
return host.RouterKey
//return sdk.NewRoute(host.RouterKey, NewHandler(*am.keeper))
}
// QuerierRoute returns the ibc module's querier route name.
func (AppModule) QuerierRoute() string {
return host.QuerierRoute
}
// LegacyQuerierHandler returns nil. IBC does not support the legacy querier.
//func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
// return nil
//}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
clienttypes.RegisterMsgServer(cfg.MsgServer(), am.keeper)
connectiontypes.RegisterMsgServer(cfg.MsgServer(), am.keeper)
channeltypes.RegisterMsgServer(cfg.MsgServer(), am.keeper)
types.RegisterQueryService(cfg.QueryServer(), am.keeper)
//m := clientkeeper.NewMigrator(am.keeper.ClientKeeper)
//cfg.RegisterMigration(host.ModuleName, 1, m.Migrate1to2)
}
// InitGenesis performs genesis initialization for the ibc module. It returns
// no validator updates.
//func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, bz json.RawMessage) []abci.ValidatorUpdate {
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
return nil
}
func (am AppModule) initGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
var gs types.GenesisState
err := ModuleCdc.UnmarshalJSON(data, &gs)
if err != nil {
panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", host.ModuleName, err))
}
InitGenesis(ctx, *am.keeper, am.createLocalhost, &gs)
return []abci.ValidatorUpdate{}
}
// ExportGenesis returns the exported genesis state as raw bytes for the ibc
// module.
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
return nil
}
func (am AppModule) exportGenesis(ctx sdk.Context) json.RawMessage {
return ModuleCdc.MustMarshalJSON(ExportGenesis(ctx, *am.keeper))
}
func lazyGenesis() json.RawMessage {
ret := DefaultGenesisState()
return ModuleCdc.MustMarshalJSON(&ret)
}
// BeginBlock returns the begin blocker for the ibc module.
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
if !tmtypes.HigherThanVenus1(req.Header.Height) {
return
}
ibcclient.BeginBlocker(ctx, am.keeper.ClientKeeper)
}
// EndBlock returns the end blocker for the ibc module. It returns no validator
// updates.
func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}
func (am AppModuleBasic) RegisterRouterForGRPC(cliCtx clientCtx.CLIContext, r *mux.Router) {
}
// ____________________________________________________________________________
// AppModuleSimulation functions
// GenerateGenesisState creates a randomized GenState of the ibc module.
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}
// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(_ module.SimulationState) []simulation2.WeightedProposalContent {
return nil
}
// RandomizedParams returns nil since IBC doesn't register parameter changes.
func (AppModule) RandomizedParams(_ *rand.Rand) []simulation2.ParamChange {
return nil
}
// RegisterStoreDecoder registers a decoder for ibc module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
sdr[host.StoreKey] = simulation.NewDecodeStore(*am.keeper)
}
// WeightedOperations returns the all the ibc module operations with their respective weights.
func (am AppModule) WeightedOperations(_ module.SimulationState) []simulation2.WeightedOperation {
return nil
}
func (am AppModule) RegisterTask() upgrade.HeightTask {
return upgrade.NewHeightTask(4, func(ctx sdk.Context) error {
data := lazyGenesis()
am.initGenesis(ctx, data)
return nil
})
}
func (am AppModule) RegisterParam() params.ParamSet {
return nil
}