Update examples to use async before finalize

This commit is contained in:
Pranav Gaddamadugu 2022-09-21 13:23:24 -07:00
parent 7a859e7b63
commit bf50384dd5
3 changed files with 10 additions and 10 deletions

View File

@ -28,7 +28,7 @@ function deposit(token: Token, amount: u64) -> Token {
let hash: field = BHP256::hash(token.owner); let hash: field = BHP256::hash(token.owner);
finalize(hash, amount); async finalize(hash, amount);
return remaining; return remaining;
} }
@ -50,7 +50,7 @@ function withdraw(recipient: address, amount: u64, rate: u64, periods: u64) -> T
amount: total, amount: total,
}; };
finalize(hash, amount); async finalize(hash, amount);
return token; return token;
} }

View File

@ -17,7 +17,7 @@ record token {
@program @program
function mint_public(public receiver: address, public amount: u64) { function mint_public(public receiver: address, public amount: u64) {
// Mint the tokens publicly by invoking the computation on-chain. // Mint the tokens publicly by invoking the computation on-chain.
finalize(receiver, amount); async finalize(receiver, amount);
} }
finalize mint_public(public receiver: address, public amount: u64) { finalize mint_public(public receiver: address, public amount: u64) {
@ -41,7 +41,7 @@ function mint_private(receiver: address, amount: u64) -> token {
@program @program
function transfer_public(public receiver: address, public amount: u64) { function transfer_public(public receiver: address, public amount: u64) {
// Transfer the tokens publicly, by invoking the computation on-chain. // Transfer the tokens publicly, by invoking the computation on-chain.
finalize(self.caller, receiver, amount); async finalize(self.caller, receiver, amount);
} }
finalize transfer_public(public sender: address, public receiver: address, public amount: u64) { finalize transfer_public(public sender: address, public receiver: address, public amount: u64) {
@ -98,7 +98,7 @@ function transfer_private_to_public(sender: token, public receiver: address, pub
}; };
// Increment the token amount publicly for the token receiver. // Increment the token amount publicly for the token receiver.
finalize(receiver, amount); async finalize(receiver, amount);
// Output the sender's change record. // Output the sender's change record.
return remaining; return remaining;
@ -123,7 +123,7 @@ function transfer_public_to_private(public receiver: address, public amount: u64
}; };
// Decrement the token amount of the caller publicly. // Decrement the token amount of the caller publicly.
finalize(self.caller, amount); async finalize(self.caller, amount);
// Output the receiver's record. // Output the receiver's record.
return transferred; return transferred;

View File

@ -42,7 +42,7 @@ function propose(public info: ProposalInfo) -> Proposal {
let id: field = BHP256::hash(info.title); let id: field = BHP256::hash(info.title);
// Finalize the proposal id. // Finalize the proposal id.
finalize(id); async finalize(id);
// Return a new record for the proposal. // Return a new record for the proposal.
return Proposal { return Proposal {
@ -64,7 +64,7 @@ function new_ticket(
public voter: address, public voter: address,
) -> Ticket { ) -> Ticket {
// Finalize the proposal id for the ticket. // Finalize the proposal id for the ticket.
finalize(pid); async finalize(pid);
return Ticket { return Ticket {
owner: voter, owner: voter,
@ -80,7 +80,7 @@ finalize new_ticket(public pid: field) {
// Vote to agree with a proposal. // Vote to agree with a proposal.
@program @program
function agree(ticket: Ticket) {// Privately cast the vote. function agree(ticket: Ticket) {// Privately cast the vote.
finalize(ticket.pid); async finalize(ticket.pid);
} }
finalize agree(public pid: field) {// Publicly increment the number of agree votes. finalize agree(public pid: field) {// Publicly increment the number of agree votes.
increment(agree_votes, pid, 1u64); increment(agree_votes, pid, 1u64);
@ -89,7 +89,7 @@ finalize agree(public pid: field) {// Publicly increment the number of agree vot
// Vote to disagree with a proposal. // Vote to disagree with a proposal.
@program @program
function disagree(ticket: Ticket) {// Privately cast the vote. function disagree(ticket: Ticket) {// Privately cast the vote.
finalize(ticket.pid); async finalize(ticket.pid);
} }
finalize disagree(pid: field) {// Publicly increment the number of disagree votes. finalize disagree(pid: field) {// Publicly increment the number of disagree votes.
increment(disagree_votes, pid, 1u64); increment(disagree_votes, pid, 1u64);