/
module.go
133 lines (108 loc) · 3.63 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
package guardian
// DONTCOVER
import (
"encoding/json"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/abci/types"
"github.com/Dipper-Labs/Dipper-Protocol/app/v0/guardian/client/cli"
guardiantypes "github.com/Dipper-Labs/Dipper-Protocol/app/v0/guardian/types"
"github.com/Dipper-Labs/Dipper-Protocol/client/context"
"github.com/Dipper-Labs/Dipper-Protocol/codec"
sdk "github.com/Dipper-Labs/Dipper-Protocol/types"
"github.com/Dipper-Labs/Dipper-Protocol/types/module"
)
var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
)
// AppModuleBasic defines the basic application module used by the guardian module.
type AppModuleBasic struct{}
// Name returns the guardian module's name.
func (a AppModuleBasic) Name() string {
return ModuleName
}
// RegisterCodec registers the guardian module's types for the given codec.
func (a AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
guardiantypes.RegisterCodec(cdc)
}
// DefaultGenesis returns default genesis state as raw bytes for the guardian
// module.
func (a AppModuleBasic) DefaultGenesis() json.RawMessage {
d, _ := json.Marshal(DefaultGenesisState())
return d
}
// ValidateGenesis performs genesis state validation
func (a AppModuleBasic) ValidateGenesis(d json.RawMessage) error {
var gs GenesisState
return json.Unmarshal(d, &gs)
}
// RegisterRESTRoutes registers the REST routes
func (a AppModuleBasic) RegisterRESTRoutes(context.CLIContext, *mux.Router) {
}
// GetTxCmd returns the root tx command
func (a AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
return cli.GuardianCmd(cdc)
}
// GetQueryCmd returns the root query command for the guardian module.
func (a AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(cdc)
}
// AppModule implements an application module for the guardian module.
type AppModule struct {
AppModuleBasic
keeper Keeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(keeper Keeper) AppModule {
return AppModule{keeper: keeper}
}
// InitGenesis performs genesis initialization for the guardian module. It returns
// no validator updates.
func (a AppModule) InitGenesis(ctx sdk.Context, d json.RawMessage) []types.ValidatorUpdate {
var gs GenesisState
err := json.Unmarshal(d, &gs)
if err != nil {
panic(err)
}
InitGenesis(ctx, a.keeper, gs)
return nil
}
// ExportGenesis returns the exported genesis state as raw bytes for the guardian
// module.
func (a AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
d, err := json.Marshal(ExportGenesis(ctx, a.keeper))
if err != nil {
panic(err)
}
return d
}
// RegisterInvariants registers module invariants
func (a AppModule) RegisterInvariants(sdk.InvariantRegistry) {
panic("implement me")
}
// Route returns the message routing key for the guardian module.
func (a AppModule) Route() string {
return RouterKey
}
// NewHandler returns an sdk.Handler for the guardian module.
func (a AppModule) NewHandler() sdk.Handler {
return NewHandler(a.keeper)
}
// QuerierRoute returns the guardian module's querier route name.
func (a AppModule) QuerierRoute() string {
return QuerierRoute
}
// NewQuerierHandler returns no sdk.Querier.
func (a AppModule) NewQuerierHandler() sdk.Querier {
return NewQuerier(a.keeper)
}
// BeginBlock returns the begin blocker for the guardian module.
func (a AppModule) BeginBlock(sdk.Context, types.RequestBeginBlock) {
panic("implement me")
}
// EndBlock returns the end blocker for the guardian module. It returns no validator
// updates.
func (a AppModule) EndBlock(ctx sdk.Context, b types.RequestEndBlock) []types.ValidatorUpdate {
return nil
}