/
store.go
49 lines (42 loc) · 1.52 KB
/
store.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
package downtimedetector
import (
"errors"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/osmosis/v24/x/downtime-detector/types"
)
func (k *Keeper) GetLastBlockTime(ctx sdk.Context) (time.Time, error) {
store := ctx.KVStore(k.storeKey)
timeBz := store.Get(types.GetLastBlockTimestampKey())
if len(timeBz) == 0 {
return time.Time{}, errors.New("no last block time stored in state. Should not happen, did initialization happen correctly?")
}
timeV, err := osmoutils.ParseTimeString(string(timeBz))
if err != nil {
return time.Time{}, err
}
return timeV, nil
}
func (k *Keeper) StoreLastBlockTime(ctx sdk.Context, t time.Time) {
store := ctx.KVStore(k.storeKey)
timeBz := osmoutils.FormatTimeString(t)
store.Set(types.GetLastBlockTimestampKey(), []byte(timeBz))
}
func (k *Keeper) GetLastDowntimeOfLength(ctx sdk.Context, dur types.Downtime) (time.Time, error) {
store := ctx.KVStore(k.storeKey)
timeBz := store.Get(types.GetLastDowntimeOfLengthKey(dur))
if len(timeBz) == 0 {
return time.Time{}, errors.New("no last time stored in state. Should not happen, did initialization happen correctly?")
}
timeV, err := osmoutils.ParseTimeString(string(timeBz))
if err != nil {
return time.Time{}, err
}
return timeV, nil
}
func (k *Keeper) StoreLastDowntimeOfLength(ctx sdk.Context, dur types.Downtime, t time.Time) {
store := ctx.KVStore(k.storeKey)
timeBz := osmoutils.FormatTimeString(t)
store.Set(types.GetLastDowntimeOfLengthKey(dur), []byte(timeBz))
}