Skip to content

Commit

Permalink
updated token box
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 20, 2023
1 parent a154066 commit 587fc93
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 11 additions & 12 deletions yarn-project/boxes/token/src/contracts/src/types/token_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -133,11 +126,17 @@ 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,
compute_note_hash,
compute_nullifier,
get_header,
set_header,
broadcast,
};
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -112,12 +115,17 @@ 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,
compute_note_hash,
compute_nullifier,
get_header,
set_header,
broadcast,
};
// docs:end:token_types_all

0 comments on commit 587fc93

Please sign in to comment.