mirror of
https://github.com/AleoHQ/leo.git
synced 2024-09-21 12:07:56 +03:00
Update examples
This commit is contained in:
parent
d4eb6441d7
commit
2881fce2ec
@ -50,7 +50,8 @@ 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) {
|
||||
increment(balances, hash, amount);
|
||||
let current_amount: u64 = Mapping::get_or(balances, hash, 0u64);
|
||||
Mapping::put(balances, hash, current_amount + amount);
|
||||
}
|
||||
|
||||
// Returns a new Token containing the amount of money withdrawn.
|
||||
@ -78,7 +79,8 @@ 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) {
|
||||
decrement(balances, hash, amount);
|
||||
let current_amount: u64 = Mapping::get_or(balances, hash, 0u64);
|
||||
Mapping::put(balances, hash, current_amount - amount);
|
||||
}
|
||||
|
||||
// Returns the total amount of tokens after compounding interest.
|
||||
|
@ -24,7 +24,8 @@ 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.
|
||||
increment(account, receiver, amount);
|
||||
let current_amount: u64 = Mapping::get_or(account, receiver, 0u64);
|
||||
Mapping::put(account, receiver, current_amount + amount);
|
||||
}
|
||||
|
||||
// The function `mint_private` initializes a new record with the specified amount of tokens for the receiver.
|
||||
@ -46,11 +47,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.
|
||||
decrement(account, sender, amount);
|
||||
let current_amount = Mapping::get_or(account, sender, 0u64);
|
||||
Mapping::put(account, sender, current_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.
|
||||
increment(account, receiver, amount);
|
||||
let current_amount = Mapping::get_or(account, receiver, 0u64);
|
||||
Mapping::put(account, receiver, current_amount + amount);
|
||||
}
|
||||
|
||||
// The function `transfer_private` sends the specified token amount to the token receiver from the specified token record.
|
||||
@ -102,7 +105,8 @@ 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.
|
||||
increment(account, receiver, amount);
|
||||
let current_amount: u64 = Mapping::get_or(account, receiver, 0u64);
|
||||
Mapping::put(account, receiver, current_amount + amount);
|
||||
}
|
||||
|
||||
// The function `transfer_public_to_private` turns a specified token amount from `account` into a token record for the specified receiver.
|
||||
@ -124,7 +128,8 @@ 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.
|
||||
decrement(account, sender, amount);
|
||||
let current_amount: u64 = Mapping::get_or(account, sender, 0u64);
|
||||
Mapping::put(account, sender, current_amount - amount);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ program vote.aleo {
|
||||
}
|
||||
// Create a new proposal in the "tickets" mapping.
|
||||
finalize propose(public id: field) {
|
||||
increment(tickets, id, 0u64);
|
||||
Mapping::put(tickets, id, 0u64);
|
||||
}
|
||||
|
||||
// Create a new ticket to vote with.
|
||||
@ -70,7 +70,8 @@ program vote.aleo {
|
||||
}
|
||||
// Create a new ticket on a proposal in the "tickets" mapping.
|
||||
finalize new_ticket(public pid: field) {
|
||||
increment(tickets, pid, 1u64);
|
||||
let current: u64 = Mapping::get_or(tickets, pid, 0u64);
|
||||
Mapping::put(tickets, pid, current + 1u64);
|
||||
}
|
||||
|
||||
// Vote privately to agree with a proposal.
|
||||
@ -80,7 +81,8 @@ program vote.aleo {
|
||||
}
|
||||
finalize agree(public pid: field) {
|
||||
// Publicly increment the number of agree votes.
|
||||
increment(agree_votes, pid, 1u64);
|
||||
let current: u64 = Mapping::get_or(agree_votes, pid, 0u64);
|
||||
Mapping::put(agree_votes, pid, current + 1u64);
|
||||
}
|
||||
|
||||
// Vote privately to disagree with a proposal.
|
||||
@ -90,6 +92,7 @@ program vote.aleo {
|
||||
}
|
||||
finalize disagree(pid: field) {
|
||||
// Publicly increment the number of disagree votes.
|
||||
increment(disagree_votes, pid, 1u64);
|
||||
let current: u64 = Mapping::get_or(disagree_votes, pid, 0u64);
|
||||
Mapping::put(disagree_votes, pid, current + 1u64);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user