-
Notifications
You must be signed in to change notification settings - Fork 201
/
epoch_tracker.go
63 lines (51 loc) · 1.69 KB
/
epoch_tracker.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
package keeper
import (
"github.com/Stride-Labs/stride/x/stakeibc/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// SetEpochTracker set a specific epochTracker in the store from its index
func (k Keeper) SetEpochTracker(ctx sdk.Context, epochTracker types.EpochTracker) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.EpochTrackerKeyPrefix))
b := k.cdc.MustMarshal(&epochTracker)
store.Set(types.EpochTrackerKey(
epochTracker.EpochIdentifier,
), b)
}
// GetEpochTracker returns a epochTracker from its index
func (k Keeper) GetEpochTracker(
ctx sdk.Context,
epochIdentifier string,
) (val types.EpochTracker, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.EpochTrackerKeyPrefix))
b := store.Get(types.EpochTrackerKey(
epochIdentifier,
))
if b == nil {
return val, false
}
k.cdc.MustUnmarshal(b, &val)
return val, true
}
// RemoveEpochTracker removes a epochTracker from the store
func (k Keeper) RemoveEpochTracker(
ctx sdk.Context,
epochIdentifier string,
) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.EpochTrackerKeyPrefix))
store.Delete(types.EpochTrackerKey(
epochIdentifier,
))
}
// GetAllEpochTracker returns all epochTracker
func (k Keeper) GetAllEpochTracker(ctx sdk.Context) (list []types.EpochTracker) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.EpochTrackerKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var val types.EpochTracker
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}
return
}