mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
core: add Backwards option for storage iterators
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
4f827de5cd
commit
d5bea0ad4c
4 changed files with 19 additions and 3 deletions
|
@ -44,6 +44,7 @@ func TestFindFlags(t *testing.T) {
|
|||
require.EqualValues(t, storage.DeserializeValues, istorage.FindDeserialize)
|
||||
require.EqualValues(t, storage.PickField0, istorage.FindPick0)
|
||||
require.EqualValues(t, storage.PickField1, istorage.FindPick1)
|
||||
require.EqualValues(t, storage.Backwards, istorage.FindBackwards)
|
||||
}
|
||||
|
||||
type syscallTestCase struct {
|
||||
|
|
|
@ -19,9 +19,10 @@ const (
|
|||
FindDeserialize = 1 << 3
|
||||
FindPick0 = 1 << 4
|
||||
FindPick1 = 1 << 5
|
||||
FindBackwards = 1 << 7
|
||||
|
||||
FindAll = FindDefault | FindKeysOnly | FindRemovePrefix | FindValuesOnly |
|
||||
FindDeserialize | FindPick0 | FindPick1
|
||||
FindDeserialize | FindPick0 | FindPick1 | FindBackwards
|
||||
)
|
||||
|
||||
// Iterator is an iterator state representation.
|
||||
|
@ -111,8 +112,9 @@ func Find(ic *interop.Context) error {
|
|||
if opts&FindDeserialize == 0 && (opts&FindPick0 != 0 || opts&FindPick1 != 0) {
|
||||
return fmt.Errorf("%w: PickN is specified without Deserialize", errFindInvalidOptions)
|
||||
}
|
||||
bkwrds := opts&FindBackwards != 0
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
seekres := ic.DAO.SeekAsync(ctx, stc.ID, storage.SeekRange{Prefix: prefix})
|
||||
seekres := ic.DAO.SeekAsync(ctx, stc.ID, storage.SeekRange{Prefix: prefix, Backwards: bkwrds})
|
||||
item := NewIterator(seekres, prefix, opts)
|
||||
ic.VM.Estack().PushItem(stackitem.NewInterop(item))
|
||||
ic.RegisterCancelFunc(func() {
|
||||
|
|
|
@ -197,7 +197,18 @@ func TestFind(t *testing.T) {
|
|||
}),
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("normal invocation, backwards", func(t *testing.T) {
|
||||
testFind(t, []byte{0x01}, istorage.FindBackwards, []stackitem.Item{
|
||||
stackitem.NewStruct([]stackitem.Item{
|
||||
stackitem.NewByteArray(skeys[0]),
|
||||
stackitem.NewByteArray(items[0]),
|
||||
}),
|
||||
stackitem.NewStruct([]stackitem.Item{
|
||||
stackitem.NewByteArray(skeys[2]),
|
||||
stackitem.NewByteArray(items[2]),
|
||||
}),
|
||||
})
|
||||
})
|
||||
t.Run("keys only", func(t *testing.T) {
|
||||
testFind(t, []byte{0x01}, istorage.FindKeysOnly, []stackitem.Item{
|
||||
stackitem.NewByteArray(skeys[2]),
|
||||
|
|
|
@ -36,6 +36,8 @@ const (
|
|||
PickField0 FindFlags = 1 << 4
|
||||
// PickField1 is used to get second field in a serialized struct or array.
|
||||
PickField1 FindFlags = 1 << 5
|
||||
// Backwards is used to iterate over elements in reversed (descending) order.
|
||||
Backwards FindFlags = 1 << 7
|
||||
)
|
||||
|
||||
// ConvertContextToReadOnly returns new context from the given one, but with
|
||||
|
|
Loading…
Reference in a new issue