Skip to content

Commit

Permalink
add assert messages
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejdfinity committed Aug 21, 2023
1 parent fe21c96 commit f470e6f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cycles-ledger/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,24 @@ fn record_approval(

fn use_allowance(s: &mut State, account: &Account, spender: &Account, amount: u128, now: u64) {
let key = (to_account_key(account), to_account_key(spender));

assert!(amount > 0);
let (current_allowance, current_expiration) =
s.approvals.get(&key).expect("Allowance does not exist");

assert!(amount > 0, "Cannot use amount 0 from allowance");
let (current_allowance, current_expiration) = s.approvals.get(&key).expect(&format!(
"Allowance does not exist, account {}, spender {}",
account, spender
));
assert!(
current_expiration == 0 || current_expiration > now,
"Expired allowance"
"Expired allowance, expiration {} is earlier than now {}",
current_expiration,
now
);
assert!(
current_allowance >= amount,
"Insufficient allowance, current_allowance {}, total spent amount {}",
current_allowance,
amount
);
assert!(current_allowance >= amount, "Insufficient allowance");

let new_amount = current_allowance - amount;
if new_amount == 0 {
Expand Down

0 comments on commit f470e6f

Please sign in to comment.