-
Notifications
You must be signed in to change notification settings - Fork 53
/
module.go
155 lines (126 loc) · 4.18 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
package module
import (
"context"
"github.com/omni-network/omni/halo/attest/keeper"
"github.com/omni-network/omni/halo/attest/types"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/module"
skeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
)
var (
_ module.AppModuleBasic = (*AppModule)(nil)
_ appmodule.AppModule = (*AppModule)(nil)
_ appmodule.HasBeginBlocker = (*AppModule)(nil)
_ appmodule.HasEndBlocker = (*AppModule)(nil)
)
// ----------------------------------------------------------------------------
// AppModuleBasic
// ----------------------------------------------------------------------------
// AppModuleBasic implements the AppModuleBasic interface that defines the
// independent methods a Cosmos SDK module needs to implement.
type AppModuleBasic struct {
cdc codec.BinaryCodec
}
func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic {
return AppModuleBasic{cdc: cdc}
}
// Name returns the name of the module as a string.
func (AppModuleBasic) Name() string {
return types.ModuleName
}
// RegisterLegacyAminoCodec registers the amino codec for the module, which is used
// to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore.
func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {}
// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message.
func (AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(reg)
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) {}
// ----------------------------------------------------------------------------
// AppModule
// ----------------------------------------------------------------------------
// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement.
type AppModule struct {
AppModuleBasic
keeper *keeper.Keeper
}
func NewAppModule(
cdc codec.Codec,
keeper *keeper.Keeper,
) AppModule {
return AppModule{
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
}
}
func (m AppModule) BeginBlock(ctx context.Context) error {
return m.keeper.BeginBlock(ctx)
}
func (m AppModule) EndBlock(ctx context.Context) error {
return m.keeper.EndBlock(ctx)
}
// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries.
func (m AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServiceServer(cfg.MsgServer(), keeper.NewMsgServerImpl(m.keeper))
types.RegisterQueryServer(cfg.QueryServer(), m.keeper)
}
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (AppModule) IsAppModule() {}
// ----------------------------------------------------------------------------
// App Wiring Setup
// ----------------------------------------------------------------------------
//nolint:gochecknoinits // Cosmos-style
func init() {
appmodule.Register(
&Module{},
appmodule.Provide(
ProvideModule,
),
)
}
type ModuleInputs struct {
depinject.In
StoreService store.KVStoreService
Cdc codec.Codec
Config *Module
Logger log.Logger
TXConfig client.TxConfig
SKeeper *skeeper.Keeper
Namer types.ChainVerNameFunc
Voter types.Voter
}
type ModuleOutputs struct {
depinject.Out
Keeper *keeper.Keeper
Module appmodule.AppModule
}
func ProvideModule(in ModuleInputs) (ModuleOutputs, error) {
k, err := keeper.New(
in.Cdc,
in.StoreService,
in.SKeeper,
in.Namer,
in.Voter,
in.Config.GetVoteWindow(),
in.Config.GetVoteExtensionLimit(),
in.Config.GetTrimLag(),
)
if err != nil {
return ModuleOutputs{}, err
}
m := NewAppModule(
in.Cdc,
k,
)
return ModuleOutputs{Keeper: k, Module: m}, nil
}