Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding change from get_or_init to get_or_use #36

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions basic_bank/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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 balance: u64 = Mapping::get_or_init(balances, hash, 0u64);
let balance: u64 = Mapping::get_or_use(balances, hash, 0u64);
Mapping::set(balances, hash, amount + balance);
}

Expand Down Expand Up @@ -75,7 +75,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 balance: u64 = Mapping::get_or_init(balances, hash, 0u64);
let balance: u64 = Mapping::get_or_use(balances, hash, 0u64);
Mapping::set(balances, hash, balance - amount);
}

Expand Down
10 changes: 5 additions & 5 deletions token/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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 receiver_amount: u64 = Mapping::get_or_init(account, receiver, 0u64);
let receiver_amount: u64 = Mapping::get_or_use(account, receiver, 0u64);
Mapping::set(account, receiver, receiver_amount + amount);
}

Expand All @@ -45,13 +45,13 @@ 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_init(account, sender, 0u64);
let sender_amount: u64 = Mapping::get_or_use(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_init(account, receiver, 0u64);
let receiver_amount: u64 = Mapping::get_or_use(account, receiver, 0u64);
Mapping::set(account, receiver, receiver_amount + amount);
}

Expand Down Expand Up @@ -101,7 +101,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 receiver_amount: u64 = Mapping::get_or_init(account, receiver, 0u64);
let receiver_amount: u64 = Mapping::get_or_use(account, receiver, 0u64);
Mapping::set(account, receiver, receiver_amount + amount);
}

Expand All @@ -123,7 +123,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 sender_amount: u64 = Mapping::get_or_init(account, sender, 0u64);
let sender_amount: u64 = Mapping::get_or_use(account, sender, 0u64);
Mapping::set(account, sender, sender_amount - amount);
}
}
6 changes: 3 additions & 3 deletions vote/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ program vote.aleo {
}
// Create a new ticket on a proposal in the "tickets" mapping.
finalize new_ticket(public pid: field) {
let vote: u64 = Mapping::get_or_init(tickets, pid, 0u64);
let vote: u64 = Mapping::get_or_use(tickets, pid, 0u64);
Mapping::set(tickets, pid, vote + 1u64);
}

Expand All @@ -75,7 +75,7 @@ program vote.aleo {
}
finalize agree(public pid: field) {
// Publicly increment the number of agree votes.
let agree_vote: u64 = Mapping::get_or_init(agree_votes, pid, 0u64);
let agree_vote: u64 = Mapping::get_or_use(agree_votes, pid, 0u64);
Mapping::set(agree_votes, pid, agree_vote + 1u64);
}

Expand All @@ -86,7 +86,7 @@ program vote.aleo {
}
finalize disagree(pid: field) {
// Publicly increment the number of disagree votes.
let disagree_vote: u64 = Mapping::get_or_init(disagree_votes, pid, 0u64);
let disagree_vote: u64 = Mapping::get_or_use(disagree_votes, pid, 0u64);
Mapping::set(disagree_votes, pid, disagree_vote + 1u64);
}
}