-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.go
70 lines (62 loc) · 2.06 KB
/
queue.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
68
69
70
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/furynet/furymod/modules/farm/types"
)
func (k Keeper) Expired(ctx sdk.Context, pool types.FarmPool) bool {
height := ctx.BlockHeader().Height
switch {
case height > pool.EndHeight:
return true
case height == pool.EndHeight:
// When Destroy and other operations are at the same block height
key := types.KeyActiveFarmPool(pool.EndHeight, pool.Id)
store := ctx.KVStore(k.storeKey)
return !store.Has(key)
default:
return false
}
}
func (k Keeper) EnqueueActivePool(ctx sdk.Context, poolId string, expiredHeight int64) {
store := ctx.KVStore(k.storeKey)
store.Set(
types.KeyActiveFarmPool(expiredHeight, poolId),
types.MustMarshalPoolId(k.cdc, poolId),
)
}
func (k Keeper) DequeueActivePool(ctx sdk.Context, poolId string, expiredHeight int64) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.KeyActiveFarmPool(expiredHeight, poolId))
}
func (k Keeper) IteratorExpiredPool(ctx sdk.Context, height int64, fun func(pool types.FarmPool)) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.PrefixActiveFarmPool(height))
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
poolId := types.MustUnMarshalPoolId(k.cdc, iterator.Value())
if pool, exist := k.GetPool(ctx, poolId); exist {
fun(pool)
}
}
}
func (k Keeper) IteratorActivePool(ctx sdk.Context, fun func(pool types.FarmPool)) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.ActiveFarmPoolKey)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
poolId := types.MustUnMarshalPoolId(k.cdc, iterator.Value())
if pool, exist := k.GetPool(ctx, poolId); exist {
fun(pool)
}
}
}
func (k Keeper) IteratorAllPools(ctx sdk.Context, fun func(pool types.FarmPool)) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.FarmPoolKey)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var pool types.FarmPool
k.cdc.MustUnmarshal(iterator.Value(), &pool)
fun(pool)
}
}