Skip to content

Commit

Permalink
Merge pull request #2952 from nspcc-dev/find-backwards
Browse files Browse the repository at this point in the history
core: add `Backwards` option to System.Storage.Find

Port neo-project/neo#2819.
  • Loading branch information
roman-khimov authored Apr 12, 2023
2 parents 4f827de + 1962dd9 commit fdec8ea
Show file tree
Hide file tree
Showing 30 changed files with 58 additions and 42 deletions.
2 changes: 1 addition & 1 deletion examples/engine/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/engine

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
4 changes: 2 additions & 2 deletions examples/engine/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
2 changes: 1 addition & 1 deletion examples/events/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/events

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
4 changes: 2 additions & 2 deletions examples/events/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
2 changes: 1 addition & 1 deletion examples/iterator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/iterator

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
4 changes: 2 additions & 2 deletions examples/iterator/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
2 changes: 1 addition & 1 deletion examples/nft-d/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/nft

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
4 changes: 2 additions & 2 deletions examples/nft-d/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
2 changes: 1 addition & 1 deletion examples/nft-nd-nns/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
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
)

Expand Down
4 changes: 2 additions & 2 deletions examples/nft-nd-nns/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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/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/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY=
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 h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
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-crypto v0.4.0 h1:5LlrUAM5O0k1+sH/sktBtrgfWtq1pgpDs09fZo+KYi4=
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 h1:rpMCoRa7expLc9gMiOP724gz6YSykZzmMALR/CmiwnU=
Expand Down
2 changes: 1 addition & 1 deletion examples/nft-nd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/nft-nd

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
4 changes: 2 additions & 2 deletions examples/nft-nd/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
2 changes: 1 addition & 1 deletion examples/oracle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/oracle

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
4 changes: 2 additions & 2 deletions examples/oracle/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
2 changes: 1 addition & 1 deletion examples/runtime/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/runtime

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
4 changes: 2 additions & 2 deletions examples/runtime/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
2 changes: 1 addition & 1 deletion examples/storage/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/storage

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
4 changes: 2 additions & 2 deletions examples/storage/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
2 changes: 1 addition & 1 deletion examples/timer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/timer

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
4 changes: 2 additions & 2 deletions examples/timer/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
2 changes: 1 addition & 1 deletion examples/token/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/token

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
4 changes: 2 additions & 2 deletions examples/token/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/mr-tron/base58 v1.2.0
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/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/rfc6979 v0.2.0
github.com/pierrec/lz4 v2.6.1+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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/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/pkg/interop v0.0.0-20230405124917-68cb07999b91 h1:hU7UwIQp+r13s62B0ofBLYcP7R5zU6wl8haLEdkGWBY=
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 h1:MgU7bK0SJ29jH+OHGGFhEGTTOul+BKXI9SVcQnXt6BA=
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.1 h1:SVqc523pZsSaS9vnPS1mm3VV6b6xY0gvdA0uYJ/GWZQ=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
Expand Down
2 changes: 1 addition & 1 deletion internal/contracts/oracle_contract/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/internal/examples/oracle

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
4 changes: 2 additions & 2 deletions internal/contracts/oracle_contract/go.sum
Original file line number Diff line number Diff line change
@@ -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-20230405124917-68cb07999b91/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
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-20230412134538-d5bea0ad4c2a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg=
1 change: 1 addition & 0 deletions pkg/compiler/syscall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions pkg/core/interop/storage/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
13 changes: 12 additions & 1 deletion pkg/core/interop/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
2 changes: 2 additions & 0 deletions pkg/interop/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fdec8ea

Please sign in to comment.