-
Notifications
You must be signed in to change notification settings - Fork 11
/
keeper.go
100 lines (83 loc) · 2.5 KB
/
keeper.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
package keeper
import (
"fmt"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/persistenceOne/pstake-native/v2/x/liquidstake/types"
)
// Keeper of the liquidstake store
type Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
stakingKeeper types.StakingKeeper
mintKeeper types.MintKeeper
distrKeeper types.DistrKeeper
slashingKeeper types.SlashingKeeper
router *baseapp.MsgServiceRouter
authority string
}
// NewKeeper returns a liquidstake keeper.
func NewKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
stakingKeeper types.StakingKeeper,
mintKeeper types.MintKeeper,
distrKeeper types.DistrKeeper,
slashingKeeper types.SlashingKeeper,
router *baseapp.MsgServiceRouter,
authority string,
) Keeper {
// ensure liquidstake module account is set
if addr := accountKeeper.GetModuleAddress(types.ModuleName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
return Keeper{
cdc: cdc,
storeKey: storeKey,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
stakingKeeper: stakingKeeper,
mintKeeper: mintKeeper,
distrKeeper: distrKeeper,
slashingKeeper: slashingKeeper,
router: router,
authority: authority,
}
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName)
}
// SetParams sets the auth module's parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
if err := params.Validate(); err != nil {
return err
}
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(¶ms)
store.Set(types.ParamsKey, bz)
return nil
}
// GetParams gets the auth module's parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
}
k.cdc.MustUnmarshal(bz, ¶ms)
return params
}
// GetCodec return codec.Codec object used by the keeper
func (k Keeper) GetCodec() codec.BinaryCodec { return k.cdc }
// Router returns the keeper's msg router
func (k Keeper) Router() *baseapp.MsgServiceRouter {
return k.router
}