Merge pull request #2952 from nspcc-dev/find-backwards

core: add `Backwards` option to System.Storage.Find

Port neo-project/neo#2819.
This commit is contained in:
Roman Khimov 2023-04-12 17:09:30 +03:00 committed by GitHub
commit fdec8ea3f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 58 additions and 42 deletions

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/engine
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/events
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/iterator
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/nft
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

View file

@ -4,7 +4,7 @@ go 1.18
require ( require (
github.com/nspcc-dev/neo-go v0.99.5-0.20221108145959-8746d9877eb5 github.com/nspcc-dev/neo-go v0.99.5-0.20221108145959-8746d9877eb5
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a
github.com/stretchr/testify v1.8.0 github.com/stretchr/testify v1.8.0
) )

View file

@ -187,8 +187,8 @@ github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22/go.mod h
github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y= github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y=
github.com/nspcc-dev/neo-go v0.99.5-0.20221108145959-8746d9877eb5 h1:NCIUxkLRB3ovLzM1lvQA6wBNn8fuY7dQx4cMJKLuaAs= github.com/nspcc-dev/neo-go v0.99.5-0.20221108145959-8746d9877eb5 h1:NCIUxkLRB3ovLzM1lvQA6wBNn8fuY7dQx4cMJKLuaAs=
github.com/nspcc-dev/neo-go v0.99.5-0.20221108145959-8746d9877eb5/go.mod h1:aWrWJZBYO+9kYC4+qJXvEjySW1WIyPnrHpmdrzd5mJY= github.com/nspcc-dev/neo-go v0.99.5-0.20221108145959-8746d9877eb5/go.mod h1:aWrWJZBYO+9kYC4+qJXvEjySW1WIyPnrHpmdrzd5mJY=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 h1:SVqc523pZsSaS9vnPS1mm3VV6b6xY0gvdA0uYJ/GWZQ= github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 h1:SVqc523pZsSaS9vnPS1mm3VV6b6xY0gvdA0uYJ/GWZQ=
github.com/nspcc-dev/neofs-crypto v0.4.0 h1:5LlrUAM5O0k1+sH/sktBtrgfWtq1pgpDs09fZo+KYi4= github.com/nspcc-dev/neofs-crypto v0.4.0 h1:5LlrUAM5O0k1+sH/sktBtrgfWtq1pgpDs09fZo+KYi4=
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 h1:rpMCoRa7expLc9gMiOP724gz6YSykZzmMALR/CmiwnU= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 h1:rpMCoRa7expLc9gMiOP724gz6YSykZzmMALR/CmiwnU=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/nft-nd
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/oracle
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/runtime
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/storage
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/timer
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/token
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

2
go.mod
View file

@ -13,7 +13,7 @@ require (
github.com/mr-tron/base58 v1.2.0 github.com/mr-tron/base58 v1.2.0
github.com/nspcc-dev/dbft v0.0.0-20230404091436-0108387748cd github.com/nspcc-dev/dbft v0.0.0-20230404091436-0108387748cd
github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659
github.com/nspcc-dev/rfc6979 v0.2.0 github.com/nspcc-dev/rfc6979 v0.2.0
github.com/pierrec/lz4 v2.6.1+incompatible github.com/pierrec/lz4 v2.6.1+incompatible

4
go.sum
View file

@ -268,8 +268,8 @@ github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y=
github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU= github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU=
github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg= github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg=
github.com/nspcc-dev/neo-go v0.98.0/go.mod h1:E3cc1x6RXSXrJb2nDWXTXjnXk3rIqVN8YdFyWv+FrqM= github.com/nspcc-dev/neo-go v0.98.0/go.mod h1:E3cc1x6RXSXrJb2nDWXTXjnXk3rIqVN8YdFyWv+FrqM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs= github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 h1:SVqc523pZsSaS9vnPS1mm3VV6b6xY0gvdA0uYJ/GWZQ= github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 h1:SVqc523pZsSaS9vnPS1mm3VV6b6xY0gvdA0uYJ/GWZQ=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs= github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/internal/examples/oracle
go 1.18 go 1.18
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=

View file

@ -44,6 +44,7 @@ func TestFindFlags(t *testing.T) {
require.EqualValues(t, storage.DeserializeValues, istorage.FindDeserialize) require.EqualValues(t, storage.DeserializeValues, istorage.FindDeserialize)
require.EqualValues(t, storage.PickField0, istorage.FindPick0) require.EqualValues(t, storage.PickField0, istorage.FindPick0)
require.EqualValues(t, storage.PickField1, istorage.FindPick1) require.EqualValues(t, storage.PickField1, istorage.FindPick1)
require.EqualValues(t, storage.Backwards, istorage.FindBackwards)
} }
type syscallTestCase struct { type syscallTestCase struct {

View file

@ -19,9 +19,10 @@ const (
FindDeserialize = 1 << 3 FindDeserialize = 1 << 3
FindPick0 = 1 << 4 FindPick0 = 1 << 4
FindPick1 = 1 << 5 FindPick1 = 1 << 5
FindBackwards = 1 << 7
FindAll = FindDefault | FindKeysOnly | FindRemovePrefix | FindValuesOnly | FindAll = FindDefault | FindKeysOnly | FindRemovePrefix | FindValuesOnly |
FindDeserialize | FindPick0 | FindPick1 FindDeserialize | FindPick0 | FindPick1 | FindBackwards
) )
// Iterator is an iterator state representation. // 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) { if opts&FindDeserialize == 0 && (opts&FindPick0 != 0 || opts&FindPick1 != 0) {
return fmt.Errorf("%w: PickN is specified without Deserialize", errFindInvalidOptions) return fmt.Errorf("%w: PickN is specified without Deserialize", errFindInvalidOptions)
} }
bkwrds := opts&FindBackwards != 0
ctx, cancel := context.WithCancel(context.Background()) 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) item := NewIterator(seekres, prefix, opts)
ic.VM.Estack().PushItem(stackitem.NewInterop(item)) ic.VM.Estack().PushItem(stackitem.NewInterop(item))
ic.RegisterCancelFunc(func() { ic.RegisterCancelFunc(func() {

View file

@ -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) { t.Run("keys only", func(t *testing.T) {
testFind(t, []byte{0x01}, istorage.FindKeysOnly, []stackitem.Item{ testFind(t, []byte{0x01}, istorage.FindKeysOnly, []stackitem.Item{
stackitem.NewByteArray(skeys[2]), stackitem.NewByteArray(skeys[2]),

View file

@ -36,6 +36,8 @@ const (
PickField0 FindFlags = 1 << 4 PickField0 FindFlags = 1 << 4
// PickField1 is used to get second field in a serialized struct or array. // PickField1 is used to get second field in a serialized struct or array.
PickField1 FindFlags = 1 << 5 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 // ConvertContextToReadOnly returns new context from the given one, but with