From 2b155862d2e80041ba63660fff30337b91f03c03 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 9 Aug 2024 07:43:10 +0000 Subject: [PATCH] using preprocessor in token contract --- .../aztec-nr/aztec/src/note/note_getter/mod.nr | 12 ++++++++++-- .../token_contract/src/types/balances_map.nr | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr b/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr index c8b8759fa0ef..d77476747b60 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr @@ -110,9 +110,17 @@ pub fn get_notes( ) -> BoundedVec where Note: NoteInterface + Eq { let opt_notes = get_notes_internal(storage_slot, options); - // apply_filter_hin(...) + let preprocessed_notes = apply_preprocessor(opt_notes, options.preprocessor, options.preprocessor_args); - constrain_get_notes_internal(context, storage_slot, opt_notes, options) + constrain_get_notes_internal(context, storage_slot, preprocessed_notes, options) +} + +unconstrained fn apply_preprocessor( + notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + preprocessor: fn([Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], PREPROCESSOR_ARGS) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + preprocessor_args: PREPROCESSOR_ARGS +) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] { + preprocessor(notes, preprocessor_args) } fn constrain_get_notes_internal( diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr index 6a582c259f75..6c8efcc4ea71 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr @@ -107,7 +107,7 @@ impl BalancesMap { target_amount: U128, max_notes: u32 ) -> U128 where T: NoteInterface + OwnedNote + Eq { - let options = NoteGetterOptions::with_filter(filter_notes_min_sum, target_amount).set_limit(max_notes); + let options = NoteGetterOptions::with_preprocessor(preprocess_notes_min_sum, target_amount).set_limit(max_notes); let notes = self.map.at(owner).pop_notes(options); let mut subtracted = U128::from_integer(0); @@ -127,7 +127,7 @@ impl BalancesMap { // The filter does not check if total sum is larger or equal to 'min_sum' - all it does is remove extra notes if it does // reach that value. // Note that proper usage of this filter requires for notes to be sorted in descending order. -pub fn filter_notes_min_sum( +pub fn preprocess_notes_min_sum( notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], min_sum: U128 ) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] where T: NoteInterface + OwnedNote {