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

Updates workshop examples to Leo v1.6.1 #19

Merged
merged 1 commit into from
Dec 1, 2022
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 auction/program.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.0.0",
"description": "",
"development": {
"private_key": "APrivateKey1zkpG9Af9z5Ha4ejVyMCqVFXRKknSm8L1ELEwcc4htk9YhVK",
"address": "aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke"
"private_key": "APrivateKey1zkp5wvamYgK3WCAdpBQxZqQX8XnuN2u11Y6QprZTriVwZVc",
"address": "aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh"
},
"license": "MIT"
}
8 changes: 2 additions & 6 deletions basic_bank/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ program basic_bank.aleo {
// Compute the hash of the token owner.
let hash: field = BHP256::hash(token.owner);

async finalize(hash, amount);

return remaining;
return remaining then finalize (hash, amount);
}

// Updates on-chain state by the amount of tokens deposited.
Expand Down Expand Up @@ -74,9 +72,7 @@ program basic_bank.aleo {
amount: total,
};

async finalize(hash, amount);

return token;
return token then finalize(hash, amount);
}

// Updates on-chain state by the amount of tokens withdrawn.
Expand Down
20 changes: 10 additions & 10 deletions battleship/program.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"program": "battleship.aleo",
"version": "0.0.0",
"description": "",
"development": {
"private_key": "APrivateKey1zkp86FNGdKxjgAdgQZ967bqBanjuHkAaoRe19RK24ZCGsHH",
"view_key": "AViewKey1hh6dvSEgeMdfseP4hfdbNYjX4grETwCuTbKnCftkpMwE",
"address": "aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry"
},
"license": "MIT"
}
"program": "battleship.aleo",
"version": "0.0.0",
"description": "",
"development": {
"private_key": "APrivateKey1zkpGKaJY47BXb6knSqmT3JZnBUEGBDFAWz2nMVSsjwYpJmm",
"view_key": "AViewKey1fSyEPXxfPFVgjL6qcM9izWRGrhSHKXyN3c64BNsAjnA6",
"address": "aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy"
},
"license": "MIT"
}
16 changes: 6 additions & 10 deletions token/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ program token.aleo {
// The function `mint_public` issues the specified token amount for the token receiver publicly on the network.
transition mint_public(public receiver: address, public amount: u64) {
// Mint the tokens publicly by invoking the computation on-chain.
async finalize(receiver, amount);
return then finalize(receiver, amount);
}

finalize mint_public(public receiver: address, public amount: u64) {
Expand All @@ -40,7 +40,7 @@ program token.aleo {
/* Transfer */
transition transfer_public(public receiver: address, public amount: u64) {
// Transfer the tokens publicly, by invoking the computation on-chain.
async finalize(self.caller, receiver, amount);
return then finalize(self.caller, receiver, amount);
}

finalize transfer_public(public sender: address, public receiver: address, public amount: u64) {
Expand Down Expand Up @@ -94,11 +94,9 @@ program token.aleo {
amount: difference,
};

// Increment the token amount publicly for the token receiver.
async finalize(receiver, amount);

// Output the sender's change record.
return remaining;
// Increment the token amount publicly for the token receiver.
return remaining then finalize(receiver, amount);
}

finalize transfer_private_to_public(public receiver: address, public amount: u64) {
Expand All @@ -118,11 +116,9 @@ program token.aleo {
amount: amount,
};

// Decrement the token amount of the caller publicly.
async finalize(self.caller, amount);

// Output the receiver's record.
return transferred;
// Decrement the token amount of the caller publicly.
return transferred then finalize(self.caller, amount);
}

finalize transfer_public_to_private(public sender: address, public amount: u64) {
Expand Down
14 changes: 5 additions & 9 deletions vote/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ program vote.aleo {
// Generate a new proposal id.
let id: field = BHP256::hash(info.title);

// Finalize the proposal id.
async finalize(id);

// Return a new record for the proposal.
// Finalize the proposal id.
return Proposal {
owner: self.caller,
gates: 0u64,
id,
info,
};
} then finalize(id);
}
// Create a new proposal in the "tickets" mapping.
finalize propose(public id: field) {
Expand All @@ -62,13 +60,11 @@ program vote.aleo {
public voter: address,
) -> Ticket {
// Finalize the proposal id for the ticket.
async finalize(pid);

return Ticket {
owner: voter,
gates: 0u64,
pid,
};
} then finalize(pid);
}
// Create a new ticket on a proposal in the "tickets" mapping.
finalize new_ticket(public pid: field) {
Expand All @@ -78,7 +74,7 @@ program vote.aleo {
// Vote privately to agree with a proposal.
transition agree(ticket: Ticket) {
// Finalize this vote.
async finalize(ticket.pid);
return then finalize(ticket.pid);
}
finalize agree(public pid: field) {
// Publicly increment the number of agree votes.
Expand All @@ -88,7 +84,7 @@ program vote.aleo {
// Vote privately to disagree with a proposal.
transition disagree(ticket: Ticket) {
// Finalize this vote.
async finalize(ticket.pid);
return then finalize(ticket.pid);
}
finalize disagree(pid: field) {
// Publicly increment the number of disagree votes.
Expand Down