Skip to content

Commit

Permalink
refactor: use call trick
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Jul 4, 2024
1 parent 6b46c72 commit 3db1c71
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ contract Token {
let mut (change, missing) = storage.balances.odd_sub(from, amount, 2);

// If we are still missing some balance to cover the amount, call accumulate to spend more notes.
let call = Token::at(context.this_address())._accumulate(from, missing.to_field());
if !missing.eq(U128::zero()) {
change = Token::at(context.this_address())._accumulate(from, missing.to_field()).call(&mut context);
change = call.call(&mut context);
}

storage.balances.add(from, change).emit(encode_and_encrypt_note_with_keys_unconstrained(&mut context, from_ovpk, from_ivpk));
Expand All @@ -360,8 +361,9 @@ contract Token {
fn _accumulate(owner: AztecAddress, missing_: Field) -> U128 {
// Since we are already spending a lot of doing the call, and we don't do anything else in here, we might as well go over more notes.
let mut (change, missing) = storage.balances.odd_sub(owner, U128::from_integer(missing_), 8);
let call = Token::at(context.this_address())._accumulate(owner, missing.to_field());
if !missing.eq(U128::zero()) {
change = Token::at(context.this_address())._accumulate(owner, missing.to_field()).call(&mut context);
change = call.call(&mut context);
}
change
}
Expand Down

0 comments on commit 3db1c71

Please sign in to comment.