-
Notifications
You must be signed in to change notification settings - Fork 368
/
keeper.go
67 lines (58 loc) · 1.82 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
package keeper
import (
"time"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/kava-labs/kava/x/kavadist/types"
)
// Keeper keeper for the cdp module
type Keeper struct {
key sdk.StoreKey
cdc codec.BinaryCodec
paramSubspace paramtypes.Subspace
bankKeeper types.BankKeeper
distKeeper types.DistKeeper
accountKeeper types.AccountKeeper
blacklistedAddrs map[string]bool
}
// NewKeeper creates a new keeper
func NewKeeper(
cdc codec.BinaryCodec, key sdk.StoreKey, paramstore paramtypes.Subspace, bk types.BankKeeper, ak types.AccountKeeper,
dk types.DistKeeper, blacklistedAddrs map[string]bool,
) Keeper {
if !paramstore.HasKeyTable() {
paramstore = paramstore.WithKeyTable(types.ParamKeyTable())
}
return Keeper{
key: key,
cdc: cdc,
paramSubspace: paramstore,
bankKeeper: bk,
distKeeper: dk,
accountKeeper: ak,
blacklistedAddrs: blacklistedAddrs,
}
}
// GetPreviousBlockTime get the blocktime for the previous block
func (k Keeper) GetPreviousBlockTime(ctx sdk.Context) (blockTime time.Time, found bool) {
store := prefix.NewStore(ctx.KVStore(k.key), types.PreviousBlockTimeKey)
b := store.Get(types.PreviousBlockTimeKey)
if b == nil {
return time.Time{}, false
}
if err := blockTime.UnmarshalBinary(b); err != nil {
return time.Time{}, false
}
return blockTime, true
}
// SetPreviousBlockTime set the time of the previous block
func (k Keeper) SetPreviousBlockTime(ctx sdk.Context, blockTime time.Time) {
store := prefix.NewStore(ctx.KVStore(k.key), types.PreviousBlockTimeKey)
b, err := blockTime.MarshalBinary()
if err != nil {
panic(err)
}
store.Set(types.PreviousBlockTimeKey, b)
}