-
Notifications
You must be signed in to change notification settings - Fork 206
/
module.go
106 lines (83 loc) · 2.88 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
package downtime
import (
"context"
"encoding/json"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/lavanet/lava/v2/x/downtime/client/cli"
"github.com/lavanet/lava/v2/x/downtime/keeper"
"github.com/lavanet/lava/v2/x/downtime/types"
v1 "github.com/lavanet/lava/v2/x/downtime/v1"
"github.com/spf13/cobra"
)
var (
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModule = AppModule{}
)
const (
ConsensusVersion = 1
)
// AppModuleBasic implements the module.AppModuleBasic interface for the downtime module.
type AppModuleBasic struct{}
func (a AppModuleBasic) Name() string {
return types.ModuleName
}
func (a AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}
func (a AppModuleBasic) RegisterInterfaces(ir cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(ir)
}
func (a AppModuleBasic) DefaultGenesis(codec codec.JSONCodec) json.RawMessage {
return codec.MustMarshalJSON(v1.DefaultGenesisState())
}
func (a AppModuleBasic) ValidateGenesis(codec codec.JSONCodec, config client.TxEncodingConfig, message json.RawMessage) error {
gs := new(v1.GenesisState)
codec.MustUnmarshalJSON(message, gs)
return gs.Validate()
}
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
_ = v1.RegisterQueryHandlerClient(context.Background(), mux, v1.NewQueryClient(clientCtx))
}
func (a AppModuleBasic) GetTxCmd() *cobra.Command { return cli.NewTxCmd() }
func (a AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.NewQueryCmd() }
// ---- AppModule
func NewAppModule(k keeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
k: k,
}
}
type AppModule struct {
AppModuleBasic
k keeper.Keeper
}
func (a AppModule) InitGenesis(context sdk.Context, jsonCodec codec.JSONCodec, message json.RawMessage) []abci.ValidatorUpdate {
gs := new(v1.GenesisState)
jsonCodec.MustUnmarshalJSON(message, gs)
err := a.k.ImportGenesis(context, gs)
if err != nil {
panic(err)
}
return nil
}
func (a AppModule) ExportGenesis(context sdk.Context, jsonCodec codec.JSONCodec) json.RawMessage {
gs, err := a.k.ExportGenesis(context)
if err != nil {
panic(err)
}
return jsonCodec.MustMarshalJSON(gs)
}
func (a AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
func (a AppModule) RegisterServices(configurator module.Configurator) {
v1.RegisterQueryServer(configurator.QueryServer(), keeper.NewQueryServer(a.k))
}
func (a AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
func (a AppModule) BeginBlock(context sdk.Context, _ abci.RequestBeginBlock) {
a.k.BeginBlock(context)
}