-
Notifications
You must be signed in to change notification settings - Fork 0
/
locked.go
50 lines (44 loc) · 1.54 KB
/
locked.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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/petri-labs/kaiju/x/ve/types"
)
// SetTotalLockedAmount sets total locked amount
func (k Keeper) SetTotalLockedAmount(ctx sdk.Context, amount sdk.Int) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: amount})
store.Set(types.TotalLockedAmountKey(), bz)
}
// GetTotalLockedAmount gets total locked amount
func (k Keeper) GetTotalLockedAmount(ctx sdk.Context) sdk.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.TotalLockedAmountKey())
if bz == nil {
return sdk.ZeroInt()
}
var amount sdk.IntProto
k.cdc.MustUnmarshal(bz, &amount)
return amount.Int
}
// SetLockedAmountByUser sets locked amount of the specified ve
func (k Keeper) SetLockedAmountByUser(ctx sdk.Context, veID uint64, amount types.LockedBalance) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&amount)
store.Set(types.LockedAmountByUserKey(veID), bz)
}
// GetLockedAmountByUser Gets locked amount of the specified ve
func (k Keeper) GetLockedAmountByUser(ctx sdk.Context, veID uint64) types.LockedBalance {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.LockedAmountByUserKey(veID))
if bz == nil {
return types.NewLockedBalance()
}
var amount types.LockedBalance
k.cdc.MustUnmarshal(bz, &amount)
return amount
}
// DeleteLockedAmountByUser deletes locked amount of the specified ve
func (k Keeper) DeleteLockedAmountByUser(ctx sdk.Context, veID uint64) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.LockedAmountByUserKey(veID))
}