-
Notifications
You must be signed in to change notification settings - Fork 11
/
unbonding_epoch_c_value.go
58 lines (48 loc) · 2.26 KB
/
unbonding_epoch_c_value.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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/persistenceOne/pstake-native/x/lscosmos/types"
)
// SetUnbondingEpochCValue sets cvalue for unbonding epoch
func (k Keeper) SetUnbondingEpochCValue(ctx sdk.Context, unbondingEpochCValue types.UnbondingEpochCValue) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&unbondingEpochCValue)
store.Set(types.GetUnbondingEpochCValueKey(unbondingEpochCValue.EpochNumber), bz)
}
// GetUnbondingEpochCValue sets cvalue for unbonding epoch
func (k Keeper) GetUnbondingEpochCValue(ctx sdk.Context, epochNumber int64) types.UnbondingEpochCValue {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.GetUnbondingEpochCValueKey(epochNumber))
var unbondingEpochCValue types.UnbondingEpochCValue
k.cdc.MustUnmarshal(bz, &unbondingEpochCValue)
return unbondingEpochCValue
}
// IterateAllUnbondingEpochCValues sets cvalue for all epochs
func (k Keeper) IterateAllUnbondingEpochCValues(ctx sdk.Context) []types.UnbondingEpochCValue {
store := ctx.KVStore(k.storeKey)
var unbondingEpochCValues []types.UnbondingEpochCValue
iterator := sdk.KVStorePrefixIterator(store, types.UnbondingEpochCValueKey)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var unbondingEpochCValue types.UnbondingEpochCValue
k.cdc.MustUnmarshal(iterator.Value(), &unbondingEpochCValue)
unbondingEpochCValues = append(unbondingEpochCValues, unbondingEpochCValue)
}
return unbondingEpochCValues
}
// MatureUnbondingEpochCValue sets unbonding epochCValue as matured
func (k Keeper) MatureUnbondingEpochCValue(ctx sdk.Context, epochNumber int64) {
unbondingEpochCValue := k.GetUnbondingEpochCValue(ctx, epochNumber)
unbondingEpochCValue.IsMatured = true
k.SetUnbondingEpochCValue(ctx, unbondingEpochCValue)
}
// FailUnbondingEpochCValue sets unbonding epochCValue as timeout for undelegation
func (k Keeper) FailUnbondingEpochCValue(ctx sdk.Context, epochNumber int64, undelegationAmount sdk.Coin) {
unbondingEpochCValue := k.GetUnbondingEpochCValue(ctx, epochNumber)
if unbondingEpochCValue.EpochNumber != epochNumber {
unbondingEpochCValue.EpochNumber = epochNumber
unbondingEpochCValue.STKBurn = undelegationAmount
}
unbondingEpochCValue.IsFailed = true
k.SetUnbondingEpochCValue(ctx, unbondingEpochCValue)
}