From 587fc939007ea49b8eb9069e2dc857d4704556ae Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 20 Oct 2023 06:49:05 +0000 Subject: [PATCH] updated token box --- .../src/contracts/src/types/balance_set.nr | 7 +----- .../src/contracts/src/types/token_note.nr | 23 +++++++++---------- .../contracts/src/types/transparent_note.nr | 18 +++++++++++---- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/yarn-project/boxes/token/src/contracts/src/types/balance_set.nr b/yarn-project/boxes/token/src/contracts/src/types/balance_set.nr index 62dfcda4291..37dbcd4ddbe 100644 --- a/yarn-project/boxes/token/src/contracts/src/types/balance_set.nr +++ b/yarn-project/boxes/token/src/contracts/src/types/balance_set.nr @@ -76,13 +76,8 @@ impl BalanceSet { let mut addend_note = TokenNote::new(addend, self.owner); // docs:start:insert - self.set.insert(&mut addend_note); + self.set.insert(&mut addend_note, true); // docs:end:insert - - addend_note.emit_encrypted( - self.context.private.unwrap(), - self.set.storage_slot - ); } pub fn sub(self: Self, subtrahend: SafeU120) { diff --git a/yarn-project/boxes/token/src/contracts/src/types/token_note.nr b/yarn-project/boxes/token/src/contracts/src/types/token_note.nr index fdc147adf1a..510fd3a1c85 100644 --- a/yarn-project/boxes/token/src/contracts/src/types/token_note.nr +++ b/yarn-project/boxes/token/src/contracts/src/types/token_note.nr @@ -84,25 +84,18 @@ impl TokenNote { self.header = header; } - - pub fn emit_encrypted( - self: &mut Self, - context: &mut PrivateContext, - storage_slot: Field, - ) { + // Broadcasts the note as an encrypted log on L1. + pub fn broadcast(self, context: &mut PrivateContext, slot: Field) { // We only bother inserting the note if non-empty to save funds on gas. if !self.amount.is_zero() { // docs:start:encrypted - let application_contract_address = (*context).this_address(); let encryption_pub_key = get_public_key(self.owner.address); - let encrypted_data = (*self).serialize(); - emit_encrypted_log( context, - application_contract_address, - storage_slot, + (*context).this_address(), + slot, encryption_pub_key, - encrypted_data, + self.serialize(), ); // docs:end:encrypted } @@ -133,6 +126,11 @@ fn set_header(note: &mut TokenNote, header: NoteHeader) { note.set_header(header) } +// Broadcasts the note as an encrypted log on L1. +fn broadcast(context: &mut PrivateContext, slot: Field, note: TokenNote) { + note.broadcast(context, slot); +} + global TokenNoteMethods = NoteInterface { deserialize, serialize, @@ -140,4 +138,5 @@ global TokenNoteMethods = NoteInterface { compute_nullifier, get_header, set_header, + broadcast, }; \ No newline at end of file diff --git a/yarn-project/boxes/token/src/contracts/src/types/transparent_note.nr b/yarn-project/boxes/token/src/contracts/src/types/transparent_note.nr index 9cee3bf6d23..226ef2b0042 100644 --- a/yarn-project/boxes/token/src/contracts/src/types/transparent_note.nr +++ b/yarn-project/boxes/token/src/contracts/src/types/transparent_note.nr @@ -1,11 +1,14 @@ // docs:start:token_types_all use dep::std::hash::pedersen; -use dep::aztec::note::{ - note_header::NoteHeader, - note_interface::NoteInterface, - utils::compute_siloed_note_hash, +use dep::aztec::{ + note::{ + note_header::NoteHeader, + note_interface::NoteInterface, + utils::compute_siloed_note_hash, + }, + hash::compute_secret_hash, + context::PrivateContext, }; -use dep::aztec::hash::{compute_secret_hash}; global TRANSPARENT_NOTE_LEN: Field = 2; @@ -112,6 +115,10 @@ fn set_header(note: &mut TransparentNote, header: NoteHeader) { note.set_header(header) } +fn broadcast(context: &mut PrivateContext, slot: Field, note: TransparentNote) { + assert(false, "TransparentNote does not support broadcast"); +} + global TransparentNoteMethods = NoteInterface { deserialize, serialize, @@ -119,5 +126,6 @@ global TransparentNoteMethods = NoteInterface { compute_nullifier, get_header, set_header, + broadcast, }; // docs:end:token_types_all \ No newline at end of file