-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
83 lines (67 loc) · 2.75 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
package staking
import (
"encoding/json"
"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/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/fanfury-sports/blackfury/x/staking/keeper"
"github.com/fanfury-sports/blackfury/x/staking/types"
abci "github.com/tendermint/tendermint/abci/types"
)
var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
)
type AppModuleBasic struct {
staking.AppModuleBasic
}
// DefaultGenesis returns default genesis state as raw bytes for the staking
// module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesis())
}
// RegisterLegacyAminoCodec registers the staking module's types on the given LegacyAmino codec.
func (b AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
b.AppModuleBasic.RegisterLegacyAminoCodec(cdc)
types.RegisterCodec(cdc)
}
// RegisterInterfaces registers the module's interface types
func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
b.AppModuleBasic.RegisterInterfaces(registry)
types.RegisterInterfaces(registry)
}
type AppModule struct {
staking.AppModule
keeper keeper.Keeper
accountKeeper stakingtypes.AccountKeeper
bankKeeper stakingtypes.BankKeeper
}
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak stakingtypes.AccountKeeper, bk stakingtypes.BankKeeper) AppModule {
return AppModule{
AppModule: staking.NewAppModule(cdc, keeper.Keeper, ak, bk),
keeper: keeper,
accountKeeper: ak,
bankKeeper: bk,
}
}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
stakingtypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
querier := stakingkeeper.Querier{Keeper: am.keeper.Keeper}
stakingtypes.RegisterQueryServer(cfg.QueryServer(), querier)
m := stakingkeeper.NewMigrator(am.keeper.Keeper)
cfg.RegisterMigration(stakingtypes.ModuleName, 1, m.Migrate1to2)
}
// InitGenesis performs genesis initialization for the staking module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState stakingtypes.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
return InitGenesis(ctx, am.keeper, am.accountKeeper, am.bankKeeper, &genesisState)
}