Update examples

This commit is contained in:
Pranav Gaddamadugu 2023-04-15 19:51:47 -07:00
parent 6a660c4ceb
commit f88ddfead5
3 changed files with 10 additions and 10 deletions

View File

@ -50,7 +50,7 @@ program basic_bank.aleo {
// - `hash` : The hash of the token owner.
// - `amount`: The amount of tokens that were deposited.
finalize deposit(hash: field, amount: u64) {
let current_amount: u64 = Mapping::get_or(balances, hash, 0u64);
let current_amount: u64 = Mapping::get_or_init(balances, hash, 0u64);
Mapping::set(balances, hash, current_amount + amount);
}
@ -79,7 +79,7 @@ program basic_bank.aleo {
// - `hash` : The hash of the token owner.
// - `amount`: The amount of tokens that were withdrawn.
finalize withdraw(hash: field, amount: u64) {
let current_amount: u64 = Mapping::get_or(balances, hash, 0u64);
let current_amount: u64 = Mapping::get_or_init(balances, hash, 0u64);
Mapping::set(balances, hash, current_amount - amount);
}

View File

@ -24,7 +24,7 @@ program token.aleo {
// Increments `account[receiver]` by `amount`.
// If `account[receiver]` does not exist, it will be created.
// If `account[receiver] + amount` overflows, `mint_public` is reverted.
let current_amount: u64 = Mapping::get_or(account, receiver, 0u64);
let current_amount: u64 = Mapping::get_or_init(account, receiver, 0u64);
Mapping::set(account, receiver, current_amount + amount);
}
@ -47,12 +47,12 @@ program token.aleo {
// Decrements `account[sender]` by `amount`.
// If `account[sender]` does not exist, it will be created.
// If `account[sender] - amount` underflows, `transfer_public` is reverted.
let sender_amount: u64 = Mapping::get_or(account, sender, 0u64);
let sender_amount: u64 = Mapping::get_or_init(account, sender, 0u64);
Mapping::set(account, sender, sender_amount - amount);
// Increments `account[receiver]` by `amount`.
// If `account[receiver]` does not exist, it will be created.
// If `account[receiver] + amount` overflows, `transfer_public` is reverted.
let receiver_amount: u64 = Mapping::get_or(account, receiver, 0u64);
let receiver_amount: u64 = Mapping::get_or_init(account, receiver, 0u64);
Mapping::set(account, receiver, receiver_amount + amount);
}
@ -105,7 +105,7 @@ program token.aleo {
// Increments `account[receiver]` by `amount`.
// If `account[receiver]` does not exist, it will be created.
// If `account[receiver] + amount` overflows, `transfer_private_to_public` is reverted.
let current_amount: u64 = Mapping::get_or(account, receiver, 0u64);
let current_amount: u64 = Mapping::get_or_init(account, receiver, 0u64);
Mapping::set(account, receiver, current_amount + amount);
}
@ -128,7 +128,7 @@ program token.aleo {
// Decrements `account[sender]` by `amount`.
// If `account[sender]` does not exist, it will be created.
// If `account[sender] - amount` underflows, `transfer_public_to_private` is reverted.
let current_amount: u64 = Mapping::get_or(account, sender, 0u64);
let current_amount: u64 = Mapping::get_or_init(account, sender, 0u64);
Mapping::set(account, sender, current_amount - amount);
}

View File

@ -70,7 +70,7 @@ program vote.aleo {
}
// Create a new ticket on a proposal in the "tickets" mapping.
finalize new_ticket(public pid: field) {
let current: u64 = Mapping::get_or(tickets, pid, 0u64);
let current: u64 = Mapping::get_or_init(tickets, pid, 0u64);
Mapping::set(tickets, pid, current + 1u64);
}
@ -81,7 +81,7 @@ program vote.aleo {
}
finalize agree(public pid: field) {
// Publicly increment the number of agree votes.
let current: u64 = Mapping::get_or(agree_votes, pid, 0u64);
let current: u64 = Mapping::get_or_init(agree_votes, pid, 0u64);
Mapping::set(agree_votes, pid, current + 1u64);
}
@ -92,7 +92,7 @@ program vote.aleo {
}
finalize disagree(pid: field) {
// Publicly increment the number of disagree votes.
let current: u64 = Mapping::get_or(disagree_votes, pid, 0u64);
let current: u64 = Mapping::get_or_init(disagree_votes, pid, 0u64);
Mapping::set(disagree_votes, pid, current + 1u64);
}
}