-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
module.go
174 lines (140 loc) · 5.25 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
package consensus
import (
"context"
"encoding/json"
modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
abci "github.com/cometbft/cometbft/abci/types"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/consensus/keeper"
"github.com/cosmos/cosmos-sdk/x/consensus/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
// ConsensusVersion defines the current x/consensus module consensus version.
const ConsensusVersion = 1
var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
)
// AppModuleBasic defines the basic application module used by the consensus_param module.
type AppModuleBasic struct {
cdc codec.Codec
}
// Name returns the consensus_param module's name.
func (AppModuleBasic) Name() string { return types.ModuleName }
// RegisterLegacyAminoCodec registers the consensus_param module's types on the LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
// DefaultGenesis returns default genesis state as raw bytes for the consensus_param
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
// nil is returned since default genesis of consensus params is handled by tendermint
return nil
}
// ValidateGenesis performs genesis state validation
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
return nil
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
// GetTxCmd returns the root tx command
func (AppModuleBasic) GetTxCmd() *cobra.Command {
return nil
}
// GetQueryCmd returns no root query command
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return nil
}
// RegisterInterfaces registers interfaces and implementations of the bank module.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
types.RegisterInterfaces(registry)
}
// AppModule implements an application module
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
}
var _ appmodule.AppModule = AppModule{}
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper))
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
}
}
// Name returns the consensus_param module's name.
func (AppModule) Name() string { return types.ModuleName }
// InitGenesis is handled by for init genesis of consensus_param
func (am AppModule) InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate {
// nil is returned since initgenesis of consensus params is handled by tendermint
return nil
}
// ExportGenesis is handled by tendermint export of genesis
func (am AppModule) ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage {
// nil is returned since ExportGenesis of consensus params is handled by tendermint and baseapp
return nil
}
// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
// RegisterInvariants does nothing, there are no invariants to enforce
func (am AppModule) RegisterInvariants(sdk.InvariantRegistry) {}
func init() {
appmodule.Register(
&modulev1.Module{},
appmodule.Provide(ProvideModule),
)
}
type ConsensusInputs struct {
depinject.In
Config *modulev1.Module
Cdc codec.Codec
Key *store.KVStoreKey
}
type ConsensusOutputs struct {
depinject.Out
Keeper keeper.Keeper
Module appmodule.AppModule
BaseAppOption runtime.BaseAppOption
}
func ProvideModule(in ConsensusInputs) ConsensusOutputs {
// default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
if in.Config.Authority != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}
k := keeper.NewKeeper(in.Cdc, in.Key, authority.String())
m := NewAppModule(in.Cdc, k)
baseappOpt := func(app *baseapp.BaseApp) {
app.SetParamStore(&k)
}
return ConsensusOutputs{
Keeper: k,
Module: m,
BaseAppOption: baseappOpt,
}
}