-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathmodule.go
More file actions
100 lines (78 loc) · 2.51 KB
/
module.go
File metadata and controls
100 lines (78 loc) · 2.51 KB
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
package genutil
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
)
const moduleName = "genutil"
// app module basics object
type AppModuleBasic struct{}
var _ sdk.AppModuleBasic = AppModuleBasic{}
// module name
func (AppModuleBasic) Name() string {
return ModuleName
}
// module name
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {}
// module name
func (AppModuleBasic) DefaultGenesis() json.RawMessage { return nil }
// module validate genesis
func (AppModuleBasic) ValidateGenesis(cdc *codec.Codec, bz json.RawMessage) error {
var data GenesisState
err := ModuleCdc.UnmarshalJSON(bz, &data)
if err != nil {
return err
}
return ValidateGenesis(cdc, data)
}
//___________________________
// app module
type AppModule struct {
AppModuleBasic
accoutKeeper AccountKeeper
stakingKeeper StakingKeeper
cdc *codec.Codec
deliverTx deliverTxfn
}
// NewAppModule creates a new AppModule object
func NewAppModule(accoutKeeper AccountKeeper, stakingKeeper StakingKeeper,
cdc *codec.Codec, deliverTx deliverTxfn) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
accoutKeeper: accoutKeeper,
stakingKeeper: stakingKeeper,
cdc: cdc,
deliverTx: deliverTx,
}
}
var _ sdk.AppModule = AppModule{}
// register invariants
func (AppModule) RegisterInvariants(_ sdk.InvariantRouter) {}
// module message route name
func (AppModule) Route() string { return "" }
// module handler
func (AppModule) NewHandler() sdk.Handler { return nil }
// module querier route name
func (AppModule) QuerierRoute() string { return "" }
// module querier
func (a AppModule) NewQuerierHandler() sdk.Querier { return nil }
// module init-genesis
func (a AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
ModuleCdc.MustUnmarshalJSON(data, &genesisState)
return InitGenesis(ctx, a.cdc, a.accountKeeper, a.stakingKeeper, a.deliverTx, genesisState)
}
// module export genesis
func (a AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
gs := ExportGenesis(ctx, a.accountKeeper)
return ModuleCdc.MustMarshalJSON(gs)
}
// module begin-block
func (a AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) sdk.Tags {
return sdk.EmptyTags()
}
// module end-block
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) ([]abci.ValidatorUpdate, sdk.Tags) {
return []abci.ValidatorUpdate{}, sdk.EmptyTags()
}