You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/developers/contracts/syntax/storage/private_state.md
+17-4Lines changed: 17 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -250,7 +250,7 @@ You can view the implementation [here](https://github.com/AztecProtocol/aztec-pa
250
250
251
251
#### `selects: BoundedVec<Option<Select>, N>`
252
252
253
-
`selects` is a collection of filtering criteria, specified by `Select { field_index: u8, value: Field}` structs. It instructs the data oracle to find notes whose (`field_index`)th field matches the provided `value`.
253
+
`selects` is a collection of filtering criteria, specified by `Select { field_index: u8, value: Field, comparator: u3 }` structs. It instructs the data oracle to find notes whose (`field_index`)th field matches the provided `value`, according to the `comparator`.
254
254
255
255
#### `sorts: BoundedVec<Option<Sort>, N>`
256
256
@@ -304,6 +304,8 @@ This method sets the offset value, which determines where to start retrieving no
304
304
305
305
#### Examples
306
306
307
+
##### Example 1
308
+
307
309
The following code snippet creates an instance of `NoteGetterOptions`, which has been configured to find the cards that belong to `account_address`. The returned cards are sorted by their points in descending order, and the first `offset` cards with the highest points are skipped.
@@ -314,24 +316,35 @@ The first value of `.select` and `.sort` is the index of a field in a note type.
314
316
315
317
The indices are: 0 for `points`, 1 for `secret`, and 2 for `owner`.
316
318
317
-
In the example, `.select(2, account_address)` matches the 2nd field of `CardNote`, which is `owner`, and returns the cards whose `owner` field equals `account_address`.
319
+
In the example, `.select(2, account_address, Option::none())` matches the 2nd field of `CardNote`, which is `owner`, and returns the cards whose `owner` field equals `account_address`, equality is the comparator used because because including no comparator (the third argument) defaults to using the equality comparator. The current possible values of Comparator are specified in the Note Getter Options implementation linked above.
318
320
319
321
`.sort(0, SortOrder.DESC)` sorts the 0th field of `CardNote`, which is `points`, in descending order.
320
322
321
323
There can be as many conditions as the number of fields a note type has. The following example finds cards whose fields match the three given values:
While `selects` lets us find notes with specific values, `filter` lets us find notes in a more dynamic way. The function below picks the cards whose points are at least `min_points`:
327
+
While `selects` lets us find notes with specific values, `filter` lets us find notes in a more dynamic way. The function below picks the cards whose points are at least `min_points`, although this now can be done by using the select function with a GTE comparator:
One thing to remember is, `filter` will be applied on the notes after they are picked from the database. Therefore, it's possible that the actual notes we end up getting are fewer than the limit.
335
+
One thing to remember is, `filter` will be applied on the notes after they are picked from the database, so it is more efficient to use select with comparators where possible. Another side effect of this is that it's possible that the actual notes we end up getting are fewer than the limit.
334
336
335
337
The limit is `MAX_READ_REQUESTS_PER_CALL` by default. But we can set it to any value **smaller** than that:
In this example, we use the above typescript code to invoke a call to our Noir contract below. This Noir contract function takes an input to match with, and a comparator to use when fetching and selecting notes from storage.
0 commit comments