forked from neutron-org/neutron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tick_iterator.go
43 lines (34 loc) · 859 Bytes
/
tick_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
package keeper
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/MonikaCat/neutron/v2/x/dex/types"
)
type TickIterator struct {
iter sdk.Iterator
cdc codec.BinaryCodec
}
func (k Keeper) NewTickIterator(
ctx sdk.Context,
tradePairID *types.TradePairID,
) TickIterator {
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.TickLiquidityPrefix(tradePairID))
return TickIterator{
iter: prefixStore.Iterator(nil, nil),
cdc: k.cdc,
}
}
func (ti TickIterator) Valid() bool {
return ti.iter.Valid()
}
func (ti TickIterator) Close() error {
return ti.iter.Close()
}
func (ti TickIterator) Value() (tick types.TickLiquidity) {
ti.cdc.MustUnmarshal(ti.iter.Value(), &tick)
return tick
}
func (ti TickIterator) Next() {
ti.iter.Next()
}