diff --git a/aztec/src/note/note_getter.nr b/aztec/src/note/note_getter.nr index 0a5420ff..441f77f0 100644 --- a/aztec/src/note/note_getter.nr +++ b/aztec/src/note/note_getter.nr @@ -8,7 +8,7 @@ use dep::protocol_types::constants::{ }; use crate::context::PrivateContext; use crate::note::{ - note_getter_options::{NoteGetterOptions, Select, Sort, SortOrder, Comparator}, + note_getter_options::{NoteGetterOptions, Select, Sort, SortOrder, Comparator, NoteStatus}, note_interface::NoteInterface, note_viewer_options::NoteViewerOptions, utils::compute_note_hash_for_read_or_nullify, @@ -135,6 +135,7 @@ unconstrained fn get_note_internal(storage_slot: Field, note_interface: [], 1, // limit 0, // offset + NoteStatus.ACTIVE, placeholder_note, placeholder_fields )[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular). @@ -159,6 +160,7 @@ unconstrained fn get_notes_internal( sort_order, options.limit, options.offset, + options.status, placeholder_opt_notes, placeholder_fields ); @@ -187,6 +189,7 @@ unconstrained pub fn view_notes( sort_order, options.limit, options.offset, + options.status, placeholder_opt_notes, placeholder_fields ) diff --git a/aztec/src/note/note_getter_options.nr b/aztec/src/note/note_getter_options.nr index 78fbeffd..3010135e 100644 --- a/aztec/src/note/note_getter_options.nr +++ b/aztec/src/note/note_getter_options.nr @@ -53,6 +53,17 @@ impl Sort { } } +struct NoteStatusEnum { + ACTIVE: u2, + ACTIVE_OR_NULLIFIED: u2, +} + +global NoteStatus = NoteStatusEnum { + ACTIVE: 1, + ACTIVE_OR_NULLIFIED: 2, + // TODO 4217: add 'NULLIFIED' +}; + fn return_all_notes( notes: [Option; MAX_READ_REQUESTS_PER_CALL], _p: Field @@ -68,6 +79,7 @@ struct NoteGetterOptions { offset: u32, filter: fn ([Option; MAX_READ_REQUESTS_PER_CALL], FILTER_ARGS) -> [Option; MAX_READ_REQUESTS_PER_CALL], filter_args: FILTER_ARGS, + status: u2, } // docs:end:NoteGetterOptions @@ -85,6 +97,7 @@ impl NoteGetterOptions { offset: 0, filter: return_all_notes, filter_args: 0, + status: NoteStatus.ACTIVE, } } @@ -101,6 +114,7 @@ impl NoteGetterOptions { offset: 0, filter, filter_args, + status: NoteStatus.ACTIVE, } } @@ -120,16 +134,22 @@ impl NoteGetterOptions { *self } - // This method lets you set a limit for the maximum number of notes to be retrieved in a single query result. + // This method lets you set a limit for the maximum number of notes to be retrieved in a single query result. pub fn set_limit(&mut self, limit: u32) -> Self { assert(limit <= MAX_READ_REQUESTS_PER_CALL as u32); self.limit = limit; *self } - // This method sets the offset value, which determines where to start retrieving notes in the query results. + // This method sets the offset value, which determines where to start retrieving notes in the query results. pub fn set_offset(&mut self, offset: u32) -> Self { self.offset = offset; *self } + + // This method sets the status value, which determines whether to retrieve active or nullified notes. + pub fn set_status(&mut self, status: u2) -> Self { + self.status = status; + *self + } } diff --git a/aztec/src/note/note_viewer_options.nr b/aztec/src/note/note_viewer_options.nr index 34c7271b..4b1c8949 100644 --- a/aztec/src/note/note_viewer_options.nr +++ b/aztec/src/note/note_viewer_options.nr @@ -1,6 +1,6 @@ use dep::std::option::Option; use dep::protocol_types::constants::MAX_NOTES_PER_PAGE; -use crate::note::note_getter_options::{Select, Sort, Comparator}; +use crate::note::note_getter_options::{Select, Sort, Comparator, NoteStatus}; use crate::types::vec::BoundedVec; // docs:start:NoteViewerOptions @@ -9,6 +9,7 @@ struct NoteViewerOptions { sorts: BoundedVec, N>, limit: u32, offset: u32, + status: u2, } // docs:end:NoteViewerOptions @@ -19,12 +20,13 @@ impl NoteViewerOptions { sorts: BoundedVec::new(Option::none()), limit: MAX_NOTES_PER_PAGE as u32, offset: 0, + status: NoteStatus.ACTIVE, } } - + // This method adds a `Select` criterion to the options. - // It takes a field_index indicating which field to select, - // a value representing the specific value to match in that field, and + // It takes a field_index indicating which field to select, + // a value representing the specific value to match in that field, and // a comparator (For possible values of comparators, please see the Comparator enum from note_getter_options) pub fn select(&mut self, field_index: u8, value: Field, comparator: Option) -> Self { self.selects.push(Option::some(Select::new(field_index, value, comparator.unwrap_or(Comparator.EQ)))); @@ -46,4 +48,10 @@ impl NoteViewerOptions { self.offset = offset; *self } + + // This method sets the status value, which determines whether to retrieve active or nullified notes. + pub fn set_status(&mut self, status: u2) -> Self { + self.status = status; + *self + } } diff --git a/aztec/src/oracle/notes.nr b/aztec/src/oracle/notes.nr index 4176e647..c4f2940f 100644 --- a/aztec/src/oracle/notes.nr +++ b/aztec/src/oracle/notes.nr @@ -32,6 +32,7 @@ fn get_notes_oracle( _sort_order: [u2; N], _limit: u32, _offset: u32, + _status: u2, _return_size: u32, _placeholder_fields: [Field; S] ) -> [Field; S] {} @@ -46,6 +47,7 @@ unconstrained fn get_notes_oracle_wrapper( sort_order: [u2; N], limit: u32, offset: u32, + status: u2, mut placeholder_fields: [Field; S] ) -> [Field; S] { let return_size = placeholder_fields.len() as u32; @@ -59,6 +61,7 @@ unconstrained fn get_notes_oracle_wrapper( sort_order, limit, offset, + status, return_size, placeholder_fields ) @@ -75,6 +78,7 @@ unconstrained pub fn get_notes( sort_order: [u2; M], limit: u32, offset: u32, + status: u2, mut placeholder_opt_notes: [Option; S], // TODO: Remove it and use `limit` to initialize the note array. placeholder_fields: [Field; NS] // TODO: Remove it and use `limit` to initialize the note array. ) -> [Option; S] { @@ -88,6 +92,7 @@ unconstrained pub fn get_notes( sort_order, limit, offset, + status, placeholder_fields ); let num_notes = fields[0] as u32;