Skip to content

Commit 8b4a7a9

Browse files
committed
feat: nullified note retrieval in get_notes and view_notes (#4238)
Supercedes AztecProtocol/aztec-packages#4208, which was closed as that one was created from a fork and we therefore cannot run CI there. Fixes AztecProtocol/aztec-packages#3755.
1 parent d5bc0c2 commit 8b4a7a9

4 files changed

Lines changed: 43 additions & 7 deletions

File tree

aztec/src/note/note_getter.nr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use dep::protocol_types::constants::{
88
};
99
use crate::context::PrivateContext;
1010
use crate::note::{
11-
note_getter_options::{NoteGetterOptions, Select, Sort, SortOrder, Comparator},
11+
note_getter_options::{NoteGetterOptions, Select, Sort, SortOrder, Comparator, NoteStatus},
1212
note_interface::NoteInterface,
1313
note_viewer_options::NoteViewerOptions,
1414
utils::compute_note_hash_for_read_or_nullify,
@@ -135,6 +135,7 @@ unconstrained fn get_note_internal<Note, N>(storage_slot: Field, note_interface:
135135
[],
136136
1, // limit
137137
0, // offset
138+
NoteStatus.ACTIVE,
138139
placeholder_note,
139140
placeholder_fields
140141
)[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular).
@@ -159,6 +160,7 @@ unconstrained fn get_notes_internal<Note, N, FILTER_ARGS>(
159160
sort_order,
160161
options.limit,
161162
options.offset,
163+
options.status,
162164
placeholder_opt_notes,
163165
placeholder_fields
164166
);
@@ -187,6 +189,7 @@ unconstrained pub fn view_notes<Note, N>(
187189
sort_order,
188190
options.limit,
189191
options.offset,
192+
options.status,
190193
placeholder_opt_notes,
191194
placeholder_fields
192195
)

aztec/src/note/note_getter_options.nr

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ impl Sort {
5353
}
5454
}
5555

56+
struct NoteStatusEnum {
57+
ACTIVE: u2,
58+
ACTIVE_OR_NULLIFIED: u2,
59+
}
60+
61+
global NoteStatus = NoteStatusEnum {
62+
ACTIVE: 1,
63+
ACTIVE_OR_NULLIFIED: 2,
64+
// TODO 4217: add 'NULLIFIED'
65+
};
66+
5667
fn return_all_notes<Note, N>(
5768
notes: [Option<Note>; MAX_READ_REQUESTS_PER_CALL],
5869
_p: Field
@@ -68,6 +79,7 @@ struct NoteGetterOptions<Note, N, FILTER_ARGS> {
6879
offset: u32,
6980
filter: fn ([Option<Note>; MAX_READ_REQUESTS_PER_CALL], FILTER_ARGS) -> [Option<Note>; MAX_READ_REQUESTS_PER_CALL],
7081
filter_args: FILTER_ARGS,
82+
status: u2,
7183
}
7284
// docs:end:NoteGetterOptions
7385

@@ -85,6 +97,7 @@ impl<Note, N, FILTER_ARGS> NoteGetterOptions<Note, N, FILTER_ARGS> {
8597
offset: 0,
8698
filter: return_all_notes,
8799
filter_args: 0,
100+
status: NoteStatus.ACTIVE,
88101
}
89102
}
90103

@@ -101,6 +114,7 @@ impl<Note, N, FILTER_ARGS> NoteGetterOptions<Note, N, FILTER_ARGS> {
101114
offset: 0,
102115
filter,
103116
filter_args,
117+
status: NoteStatus.ACTIVE,
104118
}
105119
}
106120

@@ -120,16 +134,22 @@ impl<Note, N, FILTER_ARGS> NoteGetterOptions<Note, N, FILTER_ARGS> {
120134
*self
121135
}
122136

123-
// This method lets you set a limit for the maximum number of notes to be retrieved in a single query result.
137+
// This method lets you set a limit for the maximum number of notes to be retrieved in a single query result.
124138
pub fn set_limit(&mut self, limit: u32) -> Self {
125139
assert(limit <= MAX_READ_REQUESTS_PER_CALL as u32);
126140
self.limit = limit;
127141
*self
128142
}
129143

130-
// This method sets the offset value, which determines where to start retrieving notes in the query results.
144+
// This method sets the offset value, which determines where to start retrieving notes in the query results.
131145
pub fn set_offset(&mut self, offset: u32) -> Self {
132146
self.offset = offset;
133147
*self
134148
}
149+
150+
// This method sets the status value, which determines whether to retrieve active or nullified notes.
151+
pub fn set_status(&mut self, status: u2) -> Self {
152+
self.status = status;
153+
*self
154+
}
135155
}

aztec/src/note/note_viewer_options.nr

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use dep::std::option::Option;
22
use dep::protocol_types::constants::MAX_NOTES_PER_PAGE;
3-
use crate::note::note_getter_options::{Select, Sort, Comparator};
3+
use crate::note::note_getter_options::{Select, Sort, Comparator, NoteStatus};
44
use crate::types::vec::BoundedVec;
55

66
// docs:start:NoteViewerOptions
@@ -9,6 +9,7 @@ struct NoteViewerOptions<Note, N> {
99
sorts: BoundedVec<Option<Sort>, N>,
1010
limit: u32,
1111
offset: u32,
12+
status: u2,
1213
}
1314
// docs:end:NoteViewerOptions
1415

@@ -19,12 +20,13 @@ impl<Note, N> NoteViewerOptions<Note, N> {
1920
sorts: BoundedVec::new(Option::none()),
2021
limit: MAX_NOTES_PER_PAGE as u32,
2122
offset: 0,
23+
status: NoteStatus.ACTIVE,
2224
}
2325
}
24-
26+
2527
// This method adds a `Select` criterion to the options.
26-
// It takes a field_index indicating which field to select,
27-
// a value representing the specific value to match in that field, and
28+
// It takes a field_index indicating which field to select,
29+
// a value representing the specific value to match in that field, and
2830
// a comparator (For possible values of comparators, please see the Comparator enum from note_getter_options)
2931
pub fn select(&mut self, field_index: u8, value: Field, comparator: Option<u3>) -> Self {
3032
self.selects.push(Option::some(Select::new(field_index, value, comparator.unwrap_or(Comparator.EQ))));
@@ -46,4 +48,10 @@ impl<Note, N> NoteViewerOptions<Note, N> {
4648
self.offset = offset;
4749
*self
4850
}
51+
52+
// This method sets the status value, which determines whether to retrieve active or nullified notes.
53+
pub fn set_status(&mut self, status: u2) -> Self {
54+
self.status = status;
55+
*self
56+
}
4957
}

aztec/src/oracle/notes.nr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fn get_notes_oracle<N, S>(
3232
_sort_order: [u2; N],
3333
_limit: u32,
3434
_offset: u32,
35+
_status: u2,
3536
_return_size: u32,
3637
_placeholder_fields: [Field; S]
3738
) -> [Field; S] {}
@@ -46,6 +47,7 @@ unconstrained fn get_notes_oracle_wrapper<N, S>(
4647
sort_order: [u2; N],
4748
limit: u32,
4849
offset: u32,
50+
status: u2,
4951
mut placeholder_fields: [Field; S]
5052
) -> [Field; S] {
5153
let return_size = placeholder_fields.len() as u32;
@@ -59,6 +61,7 @@ unconstrained fn get_notes_oracle_wrapper<N, S>(
5961
sort_order,
6062
limit,
6163
offset,
64+
status,
6265
return_size,
6366
placeholder_fields
6467
)
@@ -75,6 +78,7 @@ unconstrained pub fn get_notes<Note, N, M, S, NS>(
7578
sort_order: [u2; M],
7679
limit: u32,
7780
offset: u32,
81+
status: u2,
7882
mut placeholder_opt_notes: [Option<Note>; S], // TODO: Remove it and use `limit` to initialize the note array.
7983
placeholder_fields: [Field; NS] // TODO: Remove it and use `limit` to initialize the note array.
8084
) -> [Option<Note>; S] {
@@ -88,6 +92,7 @@ unconstrained pub fn get_notes<Note, N, M, S, NS>(
8892
sort_order,
8993
limit,
9094
offset,
95+
status,
9196
placeholder_fields
9297
);
9398
let num_notes = fields[0] as u32;

0 commit comments

Comments
 (0)