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

burn private/burn public added to token contract #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 33 additions & 1 deletion token/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,45 @@ program token.aleo {
let receiver_amount: u64 = Mapping::get_or_use(account, receiver, 0u64);
Mapping::set(account, receiver, receiver_amount + amount);
}

// The function `mint_private` initializes a new record with the specified amount of tokens for the receiver.
transition mint_private(receiver: address, amount: u64) -> token {
return token {
owner: receiver,
amount: amount,
};
}
/* Burn */
// The function `burn_public` publicly removes the specified token amount from the token sender's account.
transition burn_public(public amount: u64) {
return then finalize(self.caller, amount);
}

finalize burn_public(public sender: address, public amount: u64) {
// Decrements `account[sender]` by `amount`.
// If `account[sender]` does not exist, it will be created.
// If `account[sender] - amount` underflows, `burn_public` is reverted.
let sender_amount: u64 = Mapping::get_or_use(account, sender, 0u64);
if sender_amount < amount {
panic!("Underflow error");
}
Mapping::set(account, sender, sender_amount - amount);
}
// The function `burn_private` reduces the specified token amount from the specified token record.
transition burn_private(sender: token, amount: u64) -> token {
// Checks the given token record has sufficient balance.
// This `sub` operation is safe, and the proof will fail if an underflow occurs.
let difference: u64 = sender.amount - amount;

// Produce a token record with the remaining amount for the sender.
let remaining: token = token {
owner: sender.owner,
amount: difference,
};

// Output the sender's remaining record.
return remaining;
}

/* Transfer */
transition transfer_public(public receiver: address, public amount: u64) {
Expand Down Expand Up @@ -126,4 +157,5 @@ program token.aleo {
let sender_amount: u64 = Mapping::get_or_use(account, sender, 0u64);
Mapping::set(account, sender, sender_amount - amount);
}

}