forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
keeper.go
88 lines (72 loc) · 2.09 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
package mint
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/params"
)
// keeper of the staking store
type Keeper struct {
storeKey sdk.StoreKey
cdc *codec.Codec
paramSpace params.Subspace
sk StakingKeeper
fck FeeCollectionKeeper
}
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey,
paramSpace params.Subspace, sk StakingKeeper, fck FeeCollectionKeeper) Keeper {
keeper := Keeper{
storeKey: key,
cdc: cdc,
paramSpace: paramSpace.WithKeyTable(ParamKeyTable()),
sk: sk,
fck: fck,
}
return keeper
}
//____________________________________________________________________
// Keys
var (
minterKey = []byte{0x00} // the one key to use for the keeper store
// params store for inflation params
ParamStoreKeyParams = []byte("params")
)
// ParamTable for staking module
func ParamKeyTable() params.KeyTable {
return params.NewKeyTable(
ParamStoreKeyParams, Params{},
)
}
const (
// default paramspace for params keeper
DefaultParamspace = "mint"
// StoreKey is the default store key for mint
StoreKey = "mint"
)
//______________________________________________________________________
// get the minter
func (k Keeper) GetMinter(ctx sdk.Context) (minter Minter) {
store := ctx.KVStore(k.storeKey)
b := store.Get(minterKey)
if b == nil {
panic("Stored fee pool should not have been nil")
}
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &minter)
return
}
// set the minter
func (k Keeper) SetMinter(ctx sdk.Context, minter Minter) {
store := ctx.KVStore(k.storeKey)
b := k.cdc.MustMarshalBinaryLengthPrefixed(minter)
store.Set(minterKey, b)
}
//______________________________________________________________________
// get inflation params from the global param store
func (k Keeper) GetParams(ctx sdk.Context) Params {
var params Params
k.paramSpace.Get(ctx, ParamStoreKeyParams, ¶ms)
return params
}
// set inflation params from the global param store
func (k Keeper) SetParams(ctx sdk.Context, params Params) {
k.paramSpace.Set(ctx, ParamStoreKeyParams, ¶ms)
}