-
Notifications
You must be signed in to change notification settings - Fork 2
/
params.go
119 lines (101 loc) · 3.48 KB
/
params.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
package keeper
import (
"time"
sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
"github.com/fibonacci-chain/fbc/x/params"
"github.com/fibonacci-chain/fbc/x/staking/types"
)
// Default parameter namespace
const (
DefaultParamspace = types.ModuleName
)
// ParamKeyTable returns param table for staking module
func ParamKeyTable() params.KeyTable {
return params.NewKeyTable().RegisterParamSet(&types.Params{})
}
// UnbondingTime returns the param UnbondingTime
func (k Keeper) UnbondingTime(ctx sdk.Context) (res time.Duration) {
k.paramstore.Get(ctx, types.KeyUnbondingTime, &res)
return
}
// MaxValidators returns the param Maximum number of validators
func (k Keeper) MaxValidators(ctx sdk.Context) (res uint16) {
k.paramstore.Get(ctx, types.KeyMaxValidators, &res)
return
}
// BondDenom returns the default the denomination of staking token
func (k Keeper) BondDenom(_ sdk.Context) string {
return sdk.DefaultBondDenom
}
// GetParams gets all params as types.Params
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
return types.NewParams(
k.UnbondingTime(ctx),
k.MaxValidators(ctx),
k.ParamsEpoch(ctx),
k.ParamsMaxValsToAddShares(ctx),
k.ParamsMinDelegation(ctx),
k.ParamsMinSelfDelegation(ctx),
)
}
// SetParams sets the params
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramstore.SetParamSet(ctx, ¶ms)
}
// ParamsEpoch returns epoch from paramstore, only update the KeyEpoch after last epoch ends
func (k Keeper) ParamsEpoch(ctx sdk.Context) (res uint16) {
k.paramstore.Get(ctx, types.KeyEpoch, &res)
return
}
// GetEpoch returns the epoch for validators updates
func (k Keeper) GetEpoch(ctx sdk.Context) (epoch uint16) {
store := ctx.KVStore(k.storeKey)
b := store.Get(types.KeyEpoch)
if b == nil {
return types.DefaultEpoch
}
k.cdcMarshl.GetCdc().MustUnmarshalBinaryLengthPrefixed(b, &epoch)
return
}
// SetEpoch set epoch into keystore
func (k Keeper) SetEpoch(ctx sdk.Context, epoch uint16) {
store := ctx.KVStore(k.storeKey)
b := k.cdcMarshl.GetCdc().MustMarshalBinaryLengthPrefixed(epoch)
store.Set(types.KeyEpoch, b)
}
// IsEndOfEpoch checks whether an epoch is end
func (k Keeper) IsEndOfEpoch(ctx sdk.Context) bool {
blockInterval := ctx.BlockHeight() - k.GetTheEndOfLastEpoch(ctx)
return blockInterval%int64(k.GetEpoch(ctx)) == 0
}
// GetTheEndOfLastEpoch returns the deadline of the current epoch
func (k Keeper) GetTheEndOfLastEpoch(ctx sdk.Context) (height int64) {
store := ctx.KVStore(k.storeKey)
b := store.Get(types.KeyTheEndOfLastEpoch)
if b == nil {
return int64(0)
}
k.cdcMarshl.GetCdc().MustUnmarshalBinaryLengthPrefixed(b, &height)
return
}
// SetTheEndOfLastEpoch sets the deadline of the current epoch
func (k Keeper) SetTheEndOfLastEpoch(ctx sdk.Context) {
store := ctx.KVStore(k.storeKey)
b := k.cdcMarshl.GetCdc().MustMarshalBinaryLengthPrefixed(ctx.BlockHeight())
store.Set(types.KeyTheEndOfLastEpoch, b)
}
// ParamsMaxValsToAddShares returns the param MaxValsToAddShares
func (k Keeper) ParamsMaxValsToAddShares(ctx sdk.Context) (num uint16) {
k.paramstore.Get(ctx, types.KeyMaxValsToAddShares, &num)
return
}
// ParamsMinDelegation returns the param MinDelegateAmount
func (k Keeper) ParamsMinDelegation(ctx sdk.Context) (num sdk.Dec) {
k.paramstore.Get(ctx, types.KeyMinDelegation, &num)
return
}
// ParamsMinSelfDelegation returns the param MinSelfDelegateAmount
func (k Keeper) ParamsMinSelfDelegation(ctx sdk.Context) (num sdk.Dec) {
k.paramstore.Get(ctx, types.KeyMinSelfDelegation, &num)
return
}