forked from osmosis-labs/osmosis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterator.go
71 lines (58 loc) · 2.7 KB
/
iterator.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
71
package keeper
import (
"time"
"github.com/MonOsmosis/osmosis/v10/x/incentives/types"
lockuptypes "github.com/MonOsmosis/osmosis/v10/x/lockup/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Returns an iterator over all gauges in the {prefix} space of state, that begin distributing rewards after a specific time.
func (k Keeper) iteratorAfterTime(ctx sdk.Context, prefix []byte, time time.Time) sdk.Iterator {
store := ctx.KVStore(k.storeKey)
timeKey := getTimeKey(time)
key := combineKeys(prefix, timeKey)
return store.Iterator(storetypes.InclusiveEndBytes(key), storetypes.PrefixEndBytes(prefix))
}
func (k Keeper) iteratorBeforeTime(ctx sdk.Context, prefix []byte, time time.Time) sdk.Iterator {
store := ctx.KVStore(k.storeKey)
timeKey := getTimeKey(time)
key := combineKeys(prefix, timeKey)
return store.Iterator(prefix, storetypes.InclusiveEndBytes(key))
}
func (k Keeper) iterator(ctx sdk.Context, prefix []byte) sdk.Iterator {
store := ctx.KVStore(k.storeKey)
return sdk.KVStorePrefixIterator(store, prefix)
}
// UpcomingGaugesIteratorAfterTime returns the iterator to get upcoming gauges that start distribution after specific time.
func (k Keeper) UpcomingGaugesIteratorAfterTime(ctx sdk.Context, time time.Time) sdk.Iterator {
return k.iteratorAfterTime(ctx, types.KeyPrefixUpcomingGauges, time)
}
// UpcomingGaugesIteratorBeforeTime returns the iterator to get upcoming gauges that already started distribution before specific time.
func (k Keeper) UpcomingGaugesIteratorBeforeTime(ctx sdk.Context, time time.Time) sdk.Iterator {
return k.iteratorBeforeTime(ctx, types.KeyPrefixUpcomingGauges, time)
}
// GaugesIterator returns iterator for all gauges.
func (k Keeper) GaugesIterator(ctx sdk.Context) sdk.Iterator {
return k.iterator(ctx, types.KeyPrefixGauges)
}
// UpcomingGaugesIterator returns iterator for upcoming gauges.
func (k Keeper) UpcomingGaugesIterator(ctx sdk.Context) sdk.Iterator {
return k.iterator(ctx, types.KeyPrefixUpcomingGauges)
}
// ActiveGaugesIterator returns iterator for active gauges.
func (k Keeper) ActiveGaugesIterator(ctx sdk.Context) sdk.Iterator {
return k.iterator(ctx, types.KeyPrefixActiveGauges)
}
// FinishedGaugesIterator returns iterator for finished gauges.
func (k Keeper) FinishedGaugesIterator(ctx sdk.Context) sdk.Iterator {
return k.iterator(ctx, types.KeyPrefixFinishedGauges)
}
func FilterLocksByMinDuration(locks []lockuptypes.PeriodLock, minDuration time.Duration) []lockuptypes.PeriodLock {
filteredLocks := make([]lockuptypes.PeriodLock, 0, len(locks)/2)
for _, lock := range locks {
if lock.Duration >= minDuration {
filteredLocks = append(filteredLocks, lock)
}
}
return filteredLocks
}