-
Notifications
You must be signed in to change notification settings - Fork 179
/
module.go
216 lines (173 loc) · 7.27 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
package capability
import (
"encoding/json"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
clientCtx "github.com/okex/exchain/libs/cosmos-sdk/client/context"
"github.com/okex/exchain/libs/cosmos-sdk/codec"
types2 "github.com/okex/exchain/libs/cosmos-sdk/codec/types"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
"github.com/okex/exchain/libs/cosmos-sdk/types/module"
"github.com/okex/exchain/libs/cosmos-sdk/types/upgrade"
"github.com/okex/exchain/libs/cosmos-sdk/x/capability/keeper"
"github.com/okex/exchain/libs/cosmos-sdk/x/capability/simulation"
"github.com/okex/exchain/libs/cosmos-sdk/x/capability/types"
simulation2 "github.com/okex/exchain/libs/cosmos-sdk/x/simulation"
"github.com/okex/exchain/libs/ibc-go/modules/core/base"
abci "github.com/okex/exchain/libs/tendermint/abci/types"
tmtypes "github.com/okex/exchain/libs/tendermint/types"
"github.com/spf13/cobra"
"math/rand"
)
var (
_ module.AppModuleAdapter = AppModule{}
_ module.AppModuleBasicAdapter = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
_ upgrade.UpgradeModule = AppModule{}
)
// ----------------------------------------------------------------------------
// AppModuleBasic
// ----------------------------------------------------------------------------
// AppModuleBasic implements the AppModuleBasic interface for the capability module.
type AppModuleBasic struct {
cdc *codec.CodecProxy
}
func NewAppModuleBasic(cdc *codec.CodecProxy) AppModuleBasic {
ret := AppModuleBasic{cdc: cdc}
return ret
}
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {}
// Name returns the capability module's name.
func (AppModuleBasic) Name() string {
return types.ModuleName
}
// RegisterLegacyAminoCodec does nothing. Capability does not support amino.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.Codec) {}
// RegisterInterfaces registers the module's interface types
func (a AppModuleBasic) RegisterInterfaces(_ types2.InterfaceRegistry) {}
// 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 capability module.
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
return nil
}
// RegisterRESTRoutes registers the capability module's REST service handlers.
func (a AppModuleBasic) RegisterRESTRoutes(ctx clientCtx.CLIContext, rtr *mux.Router) {}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the capability module.
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(ctx clientCtx.CLIContext, mux *runtime.ServeMux) {
}
// GetTxCmd returns the capability module's root tx command.
func (a AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { return nil }
func (am AppModuleBasic) GetTxCmdV2(cdc *codec.CodecProxy, reg types2.InterfaceRegistry) *cobra.Command {
return nil
}
// GetQueryCmd returns the capability module's root query command.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { return nil }
func (AppModuleBasic) GetQueryCmdV2(cdc *codec.CodecProxy, reg types2.InterfaceRegistry) *cobra.Command {
return nil
}
func (am AppModuleBasic) RegisterRouterForGRPC(cliCtx clientCtx.CLIContext, r *mux.Router) {
}
// ----------------------------------------------------------------------------
// AppModule
// ----------------------------------------------------------------------------
// AppModule implements the AppModule interface for the capability module.
type AppModule struct {
AppModuleBasic
*base.BaseIBCUpgradeModule
keeper keeper.Keeper
}
func (am AppModule) NewHandler() sdk.Handler {
return nil
}
func (am AppModule) NewQuerierHandler() sdk.Querier {
return nil
}
func NewAppModule(cdc *codec.CodecProxy, keeper keeper.Keeper) AppModule {
ret := AppModule{
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
}
ret.BaseIBCUpgradeModule = base.NewBaseIBCUpgradeModule(ret)
return ret
}
// Name returns the capability module's name.
func (am AppModule) Name() string {
return am.AppModuleBasic.Name()
}
// Route returns the capability module's message routing key.
func (AppModule) Route() string { return types.ModuleName }
// QuerierRoute returns the capability module's query routing key.
func (AppModule) QuerierRoute() string { return "" }
// LegacyQuerierHandler returns the capability module's Querier.
func (am AppModule) LegacyQuerierHandler(codec2 *codec.Codec) sdk.Querier { return nil }
// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(module.Configurator) {}
// RegisterInvariants registers the capability module's invariants.
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
// InitGenesis performs the capability module's genesis initialization It returns
// no validator updates.
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 genState types.GenesisState
// Initialize global index to index in genesis state
ModuleCdc.MustUnmarshalJSON(data, &genState)
InitGenesis(ctx, am.keeper, genState)
return []abci.ValidatorUpdate{}
}
// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes.
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
return nil
}
func (am AppModule) exportGenesis(ctx sdk.Context) json.RawMessage {
genState := ExportGenesis(ctx, am.keeper)
return ModuleCdc.MustMarshalJSON(genState)
}
// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
if tmtypes.HigherThanVenus1(ctx.BlockHeight()) {
am.keeper.InitMemStore(ctx)
}
}
// EndBlock executes all ABCI EndBlock logic respective to the capability module. It
// returns no validator updates.
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}
// GenerateGenesisState creates a randomized GenState of the capability module.
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}
// ProposalContents performs a no-op
func (am AppModule) ProposalContents(simState module.SimulationState) []simulation2.WeightedProposalContent {
return nil
}
// RandomizedParams creates randomized capability param changes for the simulator.
func (AppModule) RandomizedParams(r *rand.Rand) []simulation2.ParamChange {
return nil
}
// RegisterStoreDecoder registers a decoder for capability module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
sdr[types.StoreKey] = simulation.NewDecodeStore()
}
// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simulation2.WeightedOperation {
return nil
}
func (am AppModule) RegisterTask() upgrade.HeightTask {
return upgrade.NewHeightTask(
0, func(ctx sdk.Context) error {
if am.Sealed() {
return nil
}
data := ModuleCdc.MustMarshalJSON(types.DefaultGenesis())
am.initGenesis(ctx, data)
return nil
})
}