-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
168 lines (133 loc) · 5.31 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
package evidence
import (
"encoding/json"
"fmt"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/client/context"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/codec"
sdk "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types/module"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/x/evidence/client"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/x/evidence/client/cli"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/x/evidence/client/rest"
"github.com/gorilla/mux"
abci "github.com/furyaxyz/fuxchain/libs/tendermint/abci/types"
"github.com/spf13/cobra"
)
var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
// TODO: Enable simulation once concrete types are defined.
// _ module.AppModuleSimulation = AppModuleSimulation{}
)
// ----------------------------------------------------------------------------
// AppModuleBasic
// ----------------------------------------------------------------------------
// AppModuleBasic implements the AppModuleBasic interface for the evidence module.
type AppModuleBasic struct {
evidenceHandlers []client.EvidenceHandler // client evidence submission handlers
}
func NewAppModuleBasic(evidenceHandlers ...client.EvidenceHandler) AppModuleBasic {
return AppModuleBasic{
evidenceHandlers: evidenceHandlers,
}
}
// Name returns the evidence module's name.
func (AppModuleBasic) Name() string {
return ModuleName
}
// RegisterCodec registers the evidence module's types to the provided codec.
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
RegisterCodec(cdc)
}
// DefaultGenesis returns the evidence module's default genesis state.
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
return ModuleCdc.MustMarshalJSON(DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the evidence module.
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
var gs GenesisState
if err := ModuleCdc.UnmarshalJSON(bz, &gs); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err)
}
return gs.Validate()
}
// RegisterRESTRoutes registers the evidence module's REST service handlers.
func (a AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
evidenceRESTHandlers := make([]rest.EvidenceRESTHandler, len(a.evidenceHandlers))
for i, evidenceHandler := range a.evidenceHandlers {
evidenceRESTHandlers[i] = evidenceHandler.RESTHandler(ctx)
}
rest.RegisterRoutes(ctx, rtr, evidenceRESTHandlers)
}
// GetTxCmd returns the evidence module's root tx command.
func (a AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
evidenceCLIHandlers := make([]*cobra.Command, len(a.evidenceHandlers))
for i, evidenceHandler := range a.evidenceHandlers {
evidenceCLIHandlers[i] = evidenceHandler.CLIHandler(cdc)
}
return cli.GetTxCmd(StoreKey, cdc, evidenceCLIHandlers)
}
// GetTxCmd returns the evidence module's root query command.
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(StoreKey, cdc)
}
// ----------------------------------------------------------------------------
// AppModule
// ----------------------------------------------------------------------------
// AppModule implements the AppModule interface for the evidence module.
type AppModule struct {
AppModuleBasic
keeper Keeper
}
func NewAppModule(keeper Keeper) AppModule {
return AppModule{
AppModuleBasic: NewAppModuleBasic(),
keeper: keeper,
}
}
// Name returns the evidence module's name.
func (am AppModule) Name() string {
return am.AppModuleBasic.Name()
}
// Route returns the evidence module's message routing key.
func (AppModule) Route() string {
return RouterKey
}
// QuerierRoute returns the evidence module's query routing key.
func (AppModule) QuerierRoute() string {
return QuerierRoute
}
// NewHandler returns the evidence module's message Handler.
func (am AppModule) NewHandler() sdk.Handler {
return NewHandler(am.keeper)
}
// NewQuerierHandler returns the evidence module's Querier.
func (am AppModule) NewQuerierHandler() sdk.Querier {
return NewQuerier(am.keeper)
}
// RegisterInvariants registers the evidence module's invariants.
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {}
// InitGenesis performs the evidence module's genesis initialization It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, bz json.RawMessage) []abci.ValidatorUpdate {
var gs GenesisState
err := ModuleCdc.UnmarshalJSON(bz, &gs)
if err != nil {
panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", ModuleName, err))
}
InitGenesis(ctx, am.keeper, gs)
return []abci.ValidatorUpdate{}
}
// ExportGenesis returns the evidence module's exported genesis state as raw JSON bytes.
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
return ModuleCdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper))
}
// BeginBlock executes all ABCI BeginBlock logic respective to the evidence module.
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
BeginBlocker(ctx, req, am.keeper)
}
// EndBlock executes all ABCI EndBlock logic respective to the evidence module. It
// returns no validator updates.
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}