mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
Merge pull request #2090 from AleoHQ/update-examples
unify leo examples with workshop, run all examples in circleci
This commit is contained in:
commit
0526e94e7f
@ -1,3 +1,17 @@
|
||||
#!/bin/bash
|
||||
# First check that Leo is installed.
|
||||
if ! command -v leo &> /dev/null
|
||||
then
|
||||
echo "leo is not installed."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Clone the 'leo' repository, or pull if it already exists.
|
||||
git clone https://github.com/AleoHQ/leo.git leo 2> /dev/null || (cd leo ; git pull)
|
||||
|
||||
# Install 'leo'.
|
||||
cd leo && cargo install --path . && cd ..
|
||||
|
||||
# Build and run the auction Leo program.
|
||||
(
|
||||
cd ./project/examples/auction || exit
|
||||
@ -9,9 +23,9 @@
|
||||
./run.sh
|
||||
)
|
||||
|
||||
# Build and run the broken_bank Leo program.
|
||||
# Build and run the basic_bank Leo program.
|
||||
(
|
||||
cd ./project/examples/broken_bank || exit
|
||||
cd ./project/examples/basic_bank || exit
|
||||
$LEO run issue
|
||||
$LEO run deposit
|
||||
$LEO run withdraw
|
||||
@ -20,6 +34,14 @@
|
||||
./run.sh
|
||||
)
|
||||
|
||||
# Build and run the battleship Leo program.
|
||||
(
|
||||
cd ./project/examples/battleship || exit
|
||||
|
||||
chmod +x ./run.sh
|
||||
./run.sh
|
||||
)
|
||||
|
||||
# Build and run the bubblesort Leo program.
|
||||
(
|
||||
cd ./project/examples/bubblesort || exit
|
||||
@ -38,6 +60,54 @@
|
||||
$LEO run main
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzdebruijin program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzdebruijin || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzgaudet program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzgaudet || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzloops program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzloops || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzmasks program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzmasks || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzreisers program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzreisers || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzseals program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzseals || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzsearchtree program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzsearchtree || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzsmallvals program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzsmallvals || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the helloworld Leo program.
|
||||
(
|
||||
cd ./project/examples/helloworld || exit
|
||||
@ -117,50 +187,10 @@
|
||||
$LEO run main
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzdebruijin program.
|
||||
# Build and run the vote Leo program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzdebruijin || exit
|
||||
$LEO run
|
||||
)
|
||||
cd ./project/examples/vote || exit
|
||||
|
||||
# Build and run the hackers-delight/ntzgaudet program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzgaudet || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzloops program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzloops || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzmasks program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzmasks || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzreisers program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzreisers || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzseals program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzseals || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzsearchtree program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzsearchtree || exit
|
||||
$LEO run
|
||||
)
|
||||
|
||||
# Build and run the hackers-delight/ntzsmallvals program.
|
||||
(
|
||||
cd ./project/examples/hackers-delight/ntzsmallvals || exit
|
||||
$LEO run
|
||||
)
|
||||
chmod +x ./run.sh
|
||||
./run.sh
|
||||
)
|
@ -1,6 +1,7 @@
|
||||
# Blind Auction
|
||||
<!-- # 🏛️ Blind Auction -->
|
||||
<img alt="workshop/auction" width="1412" src="../.resources/auction.png">
|
||||
|
||||
An auction application written in Leo.
|
||||
A first-price sealed-bid auction in Leo.
|
||||
|
||||
## Summary
|
||||
|
||||
@ -12,7 +13,7 @@ In this model, there are two parties: the auctioneer and the bidders.
|
||||
- **Auctioneer**: The party responsible for conducting the auction.
|
||||
|
||||
We make following assumptions about the auction:
|
||||
- The auctioneer is honest. That is, the auctioneer will resolve **all** bids in the order they are received. The auctioneer will not tamper with the bids. The auctioneer will not reveal the bids to any other party.
|
||||
- The auctioneer is honest. That is, the auctioneer will resolve **all** bids in the order they are received. The auctioneer will not tamper with the bids.
|
||||
- There is no limit to the number of bids.
|
||||
- The auctioneer knows the identity of all bidders, but bidders do not necessarily know the identity of other bidders.
|
||||
|
||||
@ -40,14 +41,13 @@ Users may either specify input values via the command line or provide an input f
|
||||
The `program.json` file contains a private key and address.
|
||||
This is the account that will be used to sign transactions and is checked for record ownership.
|
||||
When executing programs as different parties, be sure to set the `private_key` and `address` fields in `program.json` to the appropriate values.
|
||||
|
||||
See `./run.sh` for an example of how to run the program as different parties.
|
||||
|
||||
|
||||
The [Aleo SDK](https://github.com/AleoHQ/leo/tree/testnet3) provides a command line interface for generating new accounts.
|
||||
To generate a new account, run
|
||||
```
|
||||
aleo account new
|
||||
leo account new
|
||||
```
|
||||
|
||||
|
||||
@ -65,9 +65,3 @@ See `./run.sh` for an example.
|
||||
```bash
|
||||
leo run <function_name>
|
||||
```
|
||||
For example,
|
||||
```bash
|
||||
leo run place_bid
|
||||
leo run resolve
|
||||
leo run finish
|
||||
```
|
||||
|
@ -21,6 +21,20 @@ fi
|
||||
# "private_key": "APrivateKey1zkp5wvamYgK3WCAdpBQxZqQX8XnuN2u11Y6QprZTriVwZVc",
|
||||
# "address": "aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh"
|
||||
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 0: Initialize a new 2-party auction ########
|
||||
######## ########
|
||||
######## ------------------------------- ########
|
||||
######## | OPEN | A | B | ########
|
||||
######## ------------------------------- ########
|
||||
######## | Bid | | | ########
|
||||
######## ------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
# Swap in the private key and address of the first bidder to program.json.
|
||||
echo "{
|
||||
\"program\": \"auction.aleo\",
|
||||
@ -35,9 +49,18 @@ echo "{
|
||||
|
||||
# Have the first bidder place a bid of 10.
|
||||
echo "
|
||||
|
||||
|
||||
The first bidder is placing a bid of 10."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 1: The first bidder places a bid of 10 ########
|
||||
######## ########
|
||||
######## ------------------------------- ########
|
||||
######## | OPEN | A | B | ########
|
||||
######## ------------------------------- ########
|
||||
######## | Bid | 10 | | ########
|
||||
######## ------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run place_bid aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke 10u64
|
||||
|
||||
# Swap in the private key and address of the second bidder to program.json.
|
||||
@ -55,9 +78,18 @@ echo "{
|
||||
|
||||
# Have the second bidder place a bid of 90.
|
||||
echo "
|
||||
|
||||
|
||||
The second bidder is placing a bid of 90."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 2: The second bidder places a bid of 90 ########
|
||||
######## ########
|
||||
######## ------------------------------- ########
|
||||
######## | OPEN | A | B | ########
|
||||
######## ------------------------------- ########
|
||||
######## | Bid | 10 | 90 | ########
|
||||
######## ------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run place_bid aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4 90u64
|
||||
|
||||
# Swap in the private key and address of the auctioneer to program.json.
|
||||
@ -73,11 +105,19 @@ echo "{
|
||||
}" > program.json
|
||||
|
||||
# Have the auctioneer select the winning bid.
|
||||
|
||||
echo "
|
||||
|
||||
|
||||
The auctioneer is selecting the winning bid."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 3: The auctioneer selects the winning bidder ########
|
||||
######## ########
|
||||
######## ------------------------------- ########
|
||||
######## | OPEN | A | → B ← | ########
|
||||
######## ------------------------------- ########
|
||||
######## | Bid | 10 | → 90 ← | ########
|
||||
######## ------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run resolve "{
|
||||
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.private,
|
||||
gates: 0u64.private,
|
||||
@ -96,9 +136,18 @@ leo run resolve "{
|
||||
|
||||
# Have the auctioneer finish the auction.
|
||||
echo "
|
||||
|
||||
|
||||
The auctioneer is finishing the auction."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 3: The auctioneer completes the auction. ########
|
||||
######## ########
|
||||
######## ------------------------------- ########
|
||||
######## | CLOSE | A | → B ← | ########
|
||||
######## ------------------------------- ########
|
||||
######## | Bid | 10 | → 90 ← | ########
|
||||
######## ------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run finish "{
|
||||
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.private,
|
||||
gates: 0u64.private,
|
||||
|
@ -21,7 +21,9 @@ record Bid {
|
||||
// The address of the auction runner is aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.
|
||||
@program
|
||||
function place_bid(bidder: address, amount: u64) -> Bid {
|
||||
// Ensure the caller is the auction bidder.
|
||||
console.assert_eq(self.caller, bidder);
|
||||
// Return a new 'Bid' record for the auction bidder.
|
||||
return Bid {
|
||||
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh,
|
||||
gates: 0u64,
|
||||
@ -39,7 +41,9 @@ function place_bid(bidder: address, amount: u64) -> Bid {
|
||||
// In the event of a tie, the first bid is selected.
|
||||
@program
|
||||
function resolve(first: Bid, second: Bid) -> Bid {
|
||||
// Ensure the caller is the auctioneer.
|
||||
console.assert_eq(self.caller, aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh);
|
||||
// Resolve the winner of the auction.
|
||||
if (first.amount >= second.amount) {
|
||||
return first;
|
||||
} else {
|
||||
@ -53,7 +57,9 @@ function resolve(first: Bid, second: Bid) -> Bid {
|
||||
// Assumes that the function is invoked only after all bids have been resolved.
|
||||
@program
|
||||
function finish(bid: Bid) -> Bid {
|
||||
// Ensure the caller is the auctioneer.
|
||||
console.assert_eq(self.caller, aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh);
|
||||
// Return 'is_winner' as 'true' in the winning 'Bid'.
|
||||
return Bid {
|
||||
owner: bid.bidder,
|
||||
gates: bid.gates,
|
||||
|
@ -1,11 +1,11 @@
|
||||
# Broken Bank
|
||||
<!-- # 🏦 Basic Bank -->
|
||||
<img alt="workshop/basic_bank" width="1412" src="../.resources/basic_bank.png">
|
||||
|
||||
A "broken" bank written in Leo.
|
||||
A simple-interest yielding bank account in Leo.
|
||||
|
||||
## Summary
|
||||
|
||||
This application implements a bank that issues tokens to users and allows users to deposit tokens and accrue interest on their deposits.
|
||||
|
||||
This program implements a bank that issues tokens to users and allows users to deposit tokens to accrue simple interest on their deposits.
|
||||
|
||||
### User Flow
|
||||
1. The bank issues users tokens via the `issue` function.
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"program": "broken_bank.aleo",
|
||||
"program": "basic_bank.aleo",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"development": {
|
228
examples/basic_bank/run.sh
Executable file
228
examples/basic_bank/run.sh
Executable file
@ -0,0 +1,228 @@
|
||||
#!/bin/bash
|
||||
# First check that Leo is installed.
|
||||
if ! command -v leo &> /dev/null
|
||||
then
|
||||
echo "leo is not installed."
|
||||
exit
|
||||
fi
|
||||
|
||||
# The private key and address of the bank.
|
||||
# Swap these into program.json, when running transactions as the first bidder.
|
||||
# "private_key": "APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD",
|
||||
# "address": "aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a"
|
||||
|
||||
# The private key and address of the user.
|
||||
# Swap these into program.json, when running transactions as the second bidder.
|
||||
# "private_key": "APrivateKey1zkp75cpr5NNQpVWc5mfsD9Uf2wg6XvHknf82iwB636q3rtc"
|
||||
# "address": "aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg"
|
||||
|
||||
# Swap in the private key and address of the bank to program.json.
|
||||
echo "{
|
||||
\"program\": \"basic_bank.aleo\",
|
||||
\"version\": \"0.0.0\",
|
||||
\"description\": \"\",
|
||||
\"development\": {
|
||||
\"private_key\": \"APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD\",
|
||||
\"address\": \"aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a\"
|
||||
},
|
||||
\"license\": \"MIT\"
|
||||
}" > program.json
|
||||
|
||||
# Have the bank issue 100 tokens to the user.
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 1: Initialize 100 tokens for aleo1zeklp...v46ngg ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | ACTION | AMOUNT | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Issuing | 100 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Depositing | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Withdrawing | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | WALLET | aleo1zeklp...v46ngg | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Balance | 100 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | BANK | aleo1zeklp...v46ngg | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Balance | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Periods | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Interest Rate | 12.34% | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | TOTAL BALANCE | 100 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run issue aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg 100u64;
|
||||
|
||||
# Swap in the private key and address of the user to program.json.
|
||||
echo "{
|
||||
\"program\": \"basic_bank.aleo\",
|
||||
\"version\": \"0.0.0\",
|
||||
\"description\": \"\",
|
||||
\"development\": {
|
||||
\"private_key\": \"APrivateKey1zkp75cpr5NNQpVWc5mfsD9Uf2wg6XvHknf82iwB636q3rtc\",
|
||||
\"address\": \"aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg\"
|
||||
},
|
||||
\"license\": \"MIT\"
|
||||
}" > program.json
|
||||
|
||||
# Have the user deposit 50 tokens into the bank.
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 2: aleo1zeklp...v46ngg deposits 50 tokens ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | ACTION | AMOUNT | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Issuing | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Depositing | 50 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Withdrawing | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | WALLET | aleo1zeklp...v46ngg | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Balance | 50 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | BANK | aleo1zeklp...v46ngg | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Balance | 50 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Periods | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Interest Rate | 12.34% | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | TOTAL BALANCE | 100 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run deposit "{
|
||||
owner: aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg.private,
|
||||
gates: 0u64.private,
|
||||
amount: 100u64.private,
|
||||
_nonce: 4668394794828730542675887906815309351994017139223602571716627453741502624516group.public
|
||||
}" 50u64
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 3: Wait 15 periods ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | ACTION | AMOUNT | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Issuing | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Depositing | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Withdrawing | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | WALLET | aleo1zeklp...v46ngg | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Balance | 50 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | BANK | aleo1zeklp...v46ngg | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Balance | 266 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Periods | 15 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Interest Rate | 12.34% | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | TOTAL BALANCE | 316 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
|
||||
# Swap in the private key and address of the bank to program.json.
|
||||
echo "{
|
||||
\"program\": \"basic_bank.aleo\",
|
||||
\"version\": \"0.0.0\",
|
||||
\"description\": \"\",
|
||||
\"development\": {
|
||||
\"private_key\": \"APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD\",
|
||||
\"address\": \"aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a\"
|
||||
},
|
||||
\"license\": \"MIT\"
|
||||
}" > program.json
|
||||
|
||||
# Have the bank withdraw all of the user's tokens with compound interest over 15 periods at 12.34%.
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 4: Withdraw tokens of aleo1zeklp...v46ngg w/ interest ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | ACTION | AMOUNT | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Issuing | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Depositing | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Withdrawing | 266 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | WALLET | aleo1zeklp...v46ngg | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Balance | 316 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | BANK | aleo1zeklp...v46ngg | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Balance | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Periods | 15 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Interest Rate | 12.34% | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | TOTAL BALANCE | 316 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run withdraw aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a 50u64 1234u64 15u64;
|
@ -23,8 +23,8 @@
|
||||
- [Winning](#winning-the-game)
|
||||
|
||||
# Summary
|
||||
Battleship is a game where two players lay their ships into secret configurations on their respective 8x8 grids,
|
||||
and then take turns firing upon each other's board.
|
||||
Battleship is a game where two players lay their ships into secret configurations on their respective 8x8 grids,
|
||||
and then take turns firing upon each other's board.
|
||||
The game ends when one player has sunk all of the other player's ships.
|
||||
|
||||
This application was translated into Leo from the [zk-battleship](https://github.com/demox-labs/zk-battleship) example written by the Aleo community - show them some love!
|
||||
@ -41,7 +41,7 @@ leo build
|
||||
|
||||
### 1. Initializing the Players
|
||||
In order to play battleship, there must be two players with two boards.
|
||||
Players will be represented by their Aleo address.
|
||||
Players will be represented by their Aleo address.
|
||||
You can use the provided player accounts or [generate your own](https://aleohq.github.io/aleo/).
|
||||
```markdown
|
||||
Player 1:
|
||||
@ -72,9 +72,9 @@ Save the keys and addresses. Set the `program.json` private_key and address to o
|
||||
```
|
||||
|
||||
### 2. Player 1 Places Ships on the Board
|
||||
Now, we need to make a board as Player 1.
|
||||
See the [modeling the boards and ships](#modeling-the-board-and-ships) section for information on valid ship bitstrings and placements on the board.
|
||||
For this example, we will be using sample valid inputs.
|
||||
Now, we need to make a board as Player 1.
|
||||
See the [modeling the boards and ships](#modeling-the-board-and-ships) section for information on valid ship bitstrings and placements on the board.
|
||||
For this example, we will be using sample valid inputs.
|
||||
Initialize a new board as Player 1 with valid ship inputs and Player 2's address: `leo run initialize_board ship_5_bitstring ship_4_bitstring ship_3_bitstring ship_2_bitstring player_2_address`
|
||||
|
||||
**Run**
|
||||
@ -100,9 +100,9 @@ leo run initialize_board 34084860461056u64 551911718912u64 7u64 1157425104234217
|
||||
✅ Executed 'battleship.aleo/initialize_board'
|
||||
```
|
||||
|
||||
The output is a board_state record owned by Player 1.
|
||||
Notice that the `game_started` flag is false, as well as the composite ship configuration `ships`.
|
||||
1157459741006397447u64 to a binary bitstring becomes `0001000000010000000111111000000010000000100000001000000000000111`,
|
||||
The output is a board_state record owned by Player 1.
|
||||
Notice that the `game_started` flag is false, as well as the composite ship configuration `ships`.
|
||||
1157459741006397447u64 to a binary bitstring becomes `0001000000010000000111111000000010000000100000001000000000000111`,
|
||||
or laid out in columns and rows:
|
||||
```
|
||||
0 0 0 1 0 0 0 0
|
||||
@ -160,13 +160,13 @@ leo run offer_battleship '{
|
||||
✅ Executed 'battleship.aleo/offer_battleship'
|
||||
```
|
||||
|
||||
The first output record is the udpated board_state.record.
|
||||
Notice the `game_started` flag is now true.
|
||||
This board cannot be used to offer any other battleship games or accept any battleship game offers.
|
||||
Player 1 would need to initialize a new board and use that instead.
|
||||
The second output record is a dummy move.record --
|
||||
there are no fire coordinates included to play on Player 2's board,
|
||||
and no information about any previous Player 2 moves (Player 2 has not made any moves yet).
|
||||
The first output record is the udpated board_state.record.
|
||||
Notice the `game_started` flag is now true.
|
||||
This board cannot be used to offer any other battleship games or accept any battleship game offers.
|
||||
Player 1 would need to initialize a new board and use that instead.
|
||||
The second output record is a dummy move.record --
|
||||
there are no fire coordinates included to play on Player 2's board,
|
||||
and no information about any previous Player 2 moves (Player 2 has not made any moves yet).
|
||||
This move.record is owned by Player 2, who must use that in combination with their own board_state.record to accept the game. Let's do that now.
|
||||
|
||||
### 4: Player 2 Places Ships On The Board
|
||||
@ -274,12 +274,12 @@ leo run start_battleship '{
|
||||
✅ Executed 'battleship.aleo/start_battleship'
|
||||
```
|
||||
|
||||
Notice the outputs here are similar to `offer_battleship`.
|
||||
A dummy move.record is owned by Player 1, and Player 2 gets a board_state.record with the `game_started` flag updated.
|
||||
However, now that Player 1 has a move.record and a started board, they can begin to play.
|
||||
Notice the outputs here are similar to `offer_battleship`.
|
||||
A dummy move.record is owned by Player 1, and Player 2 gets a board_state.record with the `game_started` flag updated.
|
||||
However, now that Player 1 has a move.record and a started board, they can begin to play.
|
||||
|
||||
### 6: Player 1 Takes The 1st Turn
|
||||
**Switch** `program.json`'s keys back to Player 1's.
|
||||
**Switch** `program.json`'s keys back to Player 1's.
|
||||
Player 1 now makes the first real move: `leo run play 'board_state.record' 'move.record' fire_coordinate`
|
||||
|
||||
**Run**
|
||||
@ -332,10 +332,10 @@ leo run play '{
|
||||
✅ Executed 'battleship.aleo/play'
|
||||
```
|
||||
|
||||
Player 1 has an updated board_state.record -- they have a new `played_tiles` bitstring,
|
||||
which corresponds to the fire coordinate they just sent to Player 2.
|
||||
You can see that the `incoming_fire_coordinate` in the move.record owned by Player 2 matches exactly the input given by Player 1.
|
||||
Player 2 can now play this move tile and respond with a fire coordinate of their own,
|
||||
Player 1 has an updated board_state.record -- they have a new `played_tiles` bitstring,
|
||||
which corresponds to the fire coordinate they just sent to Player 2.
|
||||
You can see that the `incoming_fire_coordinate` in the move.record owned by Player 2 matches exactly the input given by Player 1.
|
||||
Player 2 can now play this move tile and respond with a fire coordinate of their own,
|
||||
and they will also let Player 1 know whether their fire coordinate hit or miss Player 2's ships.
|
||||
|
||||
### 7: Player 2 Takes The 2nd Turn
|
||||
@ -393,19 +393,19 @@ leo run play '{
|
||||
✅ Executed 'battleship.aleo/play'
|
||||
```
|
||||
|
||||
Player 2 now has an updated board_state.record which includes their newly updated `played_tiles`,
|
||||
only containing the fire coordinate they just sent to Player 1.
|
||||
Player 1 now owns a new move.record which includes the `hits_and_misses` field.
|
||||
This contains only the result of Player 1's previous fire coordinate they had sent to Player 2.
|
||||
It will always be a single coordinate on the 8x8 grid if it's a hit. A miss is 0u64 (8x8 grid of 0s),
|
||||
whereas a hit is the u64 equivalent of their previous fire coordinate in bitstring form.
|
||||
If you check Player 2's ships configuration, you'll note their entire bottom row is covered by two ships,
|
||||
so sample valid hits on the bottom row would be: 1u64, 2u64, 4u64, 8u64, 16u64, 32u64, 64u64, and 128u64.
|
||||
Player 2 now has an updated board_state.record which includes their newly updated `played_tiles`,
|
||||
only containing the fire coordinate they just sent to Player 1.
|
||||
Player 1 now owns a new move.record which includes the `hits_and_misses` field.
|
||||
This contains only the result of Player 1's previous fire coordinate they had sent to Player 2.
|
||||
It will always be a single coordinate on the 8x8 grid if it's a hit. A miss is 0u64 (8x8 grid of 0s),
|
||||
whereas a hit is the u64 equivalent of their previous fire coordinate in bitstring form.
|
||||
If you check Player 2's ships configuration, you'll note their entire bottom row is covered by two ships,
|
||||
so sample valid hits on the bottom row would be: 1u64, 2u64, 4u64, 8u64, 16u64, 32u64, 64u64, and 128u64.
|
||||
Since Player 1's first fire coordinate (1u64) was a hit, the `hits_and_misses` field is also 1u64.
|
||||
|
||||
Player 1's next move will consume this move.record, which will update Player 1's board with the hit-or-miss,
|
||||
as well as figure out the result of Player 2's fire coordinate.
|
||||
Now that Player 1 has some `played_tiles`, they can no longer choose an alread-played fire coordinate.
|
||||
Player 1's next move will consume this move.record, which will update Player 1's board with the hit-or-miss,
|
||||
as well as figure out the result of Player 2's fire coordinate.
|
||||
Now that Player 1 has some `played_tiles`, they can no longer choose an alread-played fire coordinate.
|
||||
For example, running `aleo run play 'board_state.record' 'move.record' 1u64` will fail, because 1u64 has already been played.
|
||||
|
||||
### 8: Player 1 Takes The 3rd Turn
|
||||
@ -462,7 +462,7 @@ leo run play '{
|
||||
✅ Executed 'battleship.aleo/play'
|
||||
```
|
||||
|
||||
As before, both a board_state.record and move.record are created.
|
||||
As before, both a board_state.record and move.record are created.
|
||||
The board_state.record now contains 3u64 as the `played_tiles`, which looks like this in bitstring form:
|
||||
```
|
||||
0 0 0 0 0 0 0 0
|
||||
@ -532,15 +532,15 @@ leo run play '{
|
||||
```
|
||||
|
||||
### 10. Who Wins?
|
||||
Play continues back and forth between Player 1 and Player 2.
|
||||
When one player has a total of 14 flipped bits in their `hits_and_misses` field on their board_state.record,
|
||||
Play continues back and forth between Player 1 and Player 2.
|
||||
When one player has a total of 14 flipped bits in their `hits_and_misses` field on their board_state.record,
|
||||
they have won the game.
|
||||
</details>
|
||||
|
||||
## ZK Battleship Privacy
|
||||
|
||||
How can we ensure that the ship configurations of each player remains secret,
|
||||
while being able to trustlessly and fairly play with their opponent?
|
||||
How can we ensure that the ship configurations of each player remains secret,
|
||||
while being able to trustlessly and fairly play with their opponent?
|
||||
By taking advantage of selective privacy powered by zero knowledge proofs on Aleo.
|
||||
|
||||
Broadly speaking, we can follow this general strategy:
|
||||
|
@ -1,11 +1,11 @@
|
||||
{
|
||||
"program": "battleship.aleo",
|
||||
"version": "0.0.0",
|
||||
"description": "Play ZK Battleship",
|
||||
"development": {
|
||||
"private_key": "APrivateKey1zkpGKaJY47BXb6knSqmT3JZnBUEGBDFAWz2nMVSsjwYpJmm",
|
||||
"view_key": "AViewKey1fSyEPXxfPFVgjL6qcM9izWRGrhSHKXyN3c64BNsAjnA6",
|
||||
"address": "aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
"program": "battleship.aleo",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"development": {
|
||||
"private_key": "APrivateKey1zkpGKaJY47BXb6knSqmT3JZnBUEGBDFAWz2nMVSsjwYpJmm",
|
||||
"view_key": "AViewKey1fSyEPXxfPFVgjL6qcM9izWRGrhSHKXyN3c64BNsAjnA6",
|
||||
"address": "aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
#!/bin/bash
|
||||
# First check that Leo is installed.
|
||||
if ! command -v leo &> /dev/null
|
||||
then
|
||||
echo "leo is not installed."
|
||||
exit
|
||||
fi
|
||||
|
||||
# The private key and address of the bank.
|
||||
# Swap these into program.json, when running transactions as the bank.
|
||||
# "private_key": "APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD",
|
||||
# "address": "aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a"
|
||||
|
||||
# The private key and address of the user.
|
||||
# Swap these into program.json, when running transactions as the user.
|
||||
# "private_key": "APrivateKey1zkp75cpr5NNQpVWc5mfsD9Uf2wg6XvHknf82iwB636q3rtc"
|
||||
# "address": "aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg"
|
||||
|
||||
# Swap in the private key and address of the bank to program.json.
|
||||
echo "{
|
||||
\"program\": \"broken_bank.aleo\",
|
||||
\"version\": \"0.0.0\",
|
||||
\"description\": \"\",
|
||||
\"development\": {
|
||||
\"private_key\": \"APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD\",
|
||||
\"address\": \"aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a\"
|
||||
},
|
||||
\"license\": \"MIT\"
|
||||
}" > program.json
|
||||
|
||||
# Have the bank issue 100 tokens to the user.
|
||||
echo "
|
||||
|
||||
|
||||
The bank is issuing 100 tokens to the user."
|
||||
leo run issue aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg 100u64;
|
||||
|
||||
# Swap in the private key and address of the user to program.json.
|
||||
echo "{
|
||||
\"program\": \"broken_bank.aleo\",
|
||||
\"version\": \"0.0.0\",
|
||||
\"description\": \"\",
|
||||
\"development\": {
|
||||
\"private_key\": \"APrivateKey1zkp75cpr5NNQpVWc5mfsD9Uf2wg6XvHknf82iwB636q3rtc\",
|
||||
\"address\": \"aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg\"
|
||||
},
|
||||
\"license\": \"MIT\"
|
||||
}" > program.json
|
||||
|
||||
# Have the user deposit 50 tokens into the bank.
|
||||
echo "
|
||||
|
||||
|
||||
The user is depositing 50 tokens into the bank."
|
||||
leo run deposit "{
|
||||
owner: aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg.private,
|
||||
gates: 0u64.private,
|
||||
amount: 100u64.private,
|
||||
_nonce: 4668394794828730542675887906815309351994017139223602571716627453741502624516group.public
|
||||
}" 50u64
|
||||
|
||||
# Swap in the private key and address of the bank to program.json.
|
||||
echo "{
|
||||
\"program\": \"broken_bank.aleo\",
|
||||
\"version\": \"0.0.0\",
|
||||
\"description\": \"\",
|
||||
\"development\": {
|
||||
\"private_key\": \"APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD\",
|
||||
\"address\": \"aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a\"
|
||||
},
|
||||
\"license\": \"MIT\"
|
||||
}" > program.json
|
||||
|
||||
# Have the bank withdraw all of the user's tokens with compound interest over 15 periods at 12.34%.
|
||||
echo "
|
||||
|
||||
|
||||
The bank is withdrawing the user's tokens after 15 periods at 12.34%."
|
||||
leo run withdraw aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a 50u64 1234u64 15u64;
|
@ -1,6 +1,17 @@
|
||||
# Tic Tac Toe
|
||||
<!-- # ⭕ Tic-Tac-Toe -->
|
||||
<img alt="workshop/tictactoe" width="1412" src="../.resources/tictactoe.png">
|
||||
|
||||
A simple Tic Tac Toe game written in Leo.
|
||||
A standard game of Tic-Tac-Toe in Leo.
|
||||
|
||||
⭕ ❕ ⭕ ❕ ❌
|
||||
|
||||
➖ ➕ ➖ ➕ ➖
|
||||
|
||||
⭕ ❕ ❌ ❕ ⭕
|
||||
|
||||
➖ ➕ ➖ ➕ ➖
|
||||
|
||||
❌ ❕ ❌ ❕ ⭕
|
||||
|
||||
## Representing State
|
||||
Leo allows users to define composite data types with the `circuit` keyword.
|
||||
@ -31,9 +42,3 @@ See `./run.sh` for an example.
|
||||
```bash
|
||||
leo run <function_name>
|
||||
```
|
||||
For example,
|
||||
```bash
|
||||
leo run new
|
||||
leo run make_move
|
||||
|
||||
```
|
||||
|
@ -2,6 +2,10 @@
|
||||
[new]
|
||||
|
||||
// Inputs for the `make_move` function.
|
||||
// - `player` : A u8 representing the player making the move. 1 for player 1, 2 for player 2.
|
||||
// - `row` : A u8 representing the row to make the move in.
|
||||
// - `column` : A u8 representing the column to make the move in.
|
||||
// - `board` : A representation of the board state.
|
||||
[make_move]
|
||||
player: u8 = 1u8;
|
||||
row: u8 = 1u8;
|
||||
|
@ -8,88 +8,151 @@ fi
|
||||
|
||||
# Create a new game.
|
||||
echo "
|
||||
|
||||
|
||||
Creating a new game."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 0: Creating a new game of Tic-Tac-Toe ########
|
||||
######## ########
|
||||
######## | | | | ########
|
||||
######## | | | | ########
|
||||
######## | | | | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run new
|
||||
|
||||
# Have the first player make a move.
|
||||
# | x | | |
|
||||
# | | | |
|
||||
# | | | |
|
||||
# Have the Player 1 make a move.
|
||||
echo "
|
||||
|
||||
The first player is making a move."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 1: Player 1 makes the 1st move. ########
|
||||
######## ########
|
||||
######## | x | | | ########
|
||||
######## | | | | ########
|
||||
######## | | | | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run make_move 1u8 1u8 1u8 "{ r1: { c1: 0u8, c2: 0u8, c3: 0u8 }, r2: { c1: 0u8, c2: 0u8, c3: 0u8 }, r3: { c1: 0u8, c2: 0u8, c3: 0u8 } }"
|
||||
|
||||
# Have the second player make a move.
|
||||
# | x | | |
|
||||
# | | o | |
|
||||
# | | | |
|
||||
# Have the Player 2 make a move.
|
||||
echo "
|
||||
|
||||
The second player is making a move."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 2: Player 2 makes the 2nd move. ########
|
||||
######## ########
|
||||
######## | x | | | ########
|
||||
######## | | o | | ########
|
||||
######## | | | | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run make_move 2u8 2u8 2u8 "{ r1: { c1: 1u8, c2: 0u8, c3: 0u8 }, r2: { c1: 0u8, c2: 0u8, c3: 0u8 }, r3: { c1: 0u8, c2: 0u8, c3: 0u8 } }"
|
||||
|
||||
# Have the first player make a move.
|
||||
# | x | | |
|
||||
# | | o | |
|
||||
# | x | | |
|
||||
# Have the Player 1 make a move.
|
||||
echo "
|
||||
|
||||
The first player is making a move."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 3: Player 1 makes the 3rd move. ########
|
||||
######## ########
|
||||
######## | x | | | ########
|
||||
######## | | o | | ########
|
||||
######## | x | | | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run make_move 1u8 3u8 1u8 "{ r1: { c1: 1u8, c2: 0u8, c3: 0u8 }, r2: { c1: 0u8, c2: 2u8, c3: 0u8 }, r3: { c1: 0u8, c2: 0u8, c3: 0u8 } }"
|
||||
|
||||
# Have the second player make a move.
|
||||
# | x | | |
|
||||
# | o | o | |
|
||||
# | x | | |
|
||||
# Have the Player 2 make a move.
|
||||
echo "
|
||||
|
||||
The second player is making a move."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 4: Player 2 makes the 4th move. ########
|
||||
######## ########
|
||||
######## | x | | | ########
|
||||
######## | o | o | | ########
|
||||
######## | x | | | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run make_move 2u8 2u8 1u8 "{ r1: { c1: 1u8, c2: 0u8, c3: 0u8 }, r2: { c1: 0u8, c2: 2u8, c3: 0u8 }, r3: { c1: 1u8, c2: 0u8, c3: 0u8 } }"
|
||||
|
||||
# Have the first player make a move.
|
||||
# | x | | |
|
||||
# | o | o | x |
|
||||
# | x | | |
|
||||
# Have the Player 1 make a move.
|
||||
echo "
|
||||
|
||||
The first player is making a move."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 5: Player 1 makes the 5th move. ########
|
||||
######## ########
|
||||
######## | x | | | ########
|
||||
######## | o | o | x | ########
|
||||
######## | x | | | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run make_move 1u8 2u8 3u8 "{ r1: { c1: 1u8, c2: 0u8, c3: 0u8 }, r2: { c1: 2u8, c2: 2u8, c3: 0u8 }, r3: { c1: 1u8, c2: 0u8, c3: 0u8 } }"
|
||||
|
||||
# Have the second player make a move.
|
||||
# | x | o | |
|
||||
# | o | o | x |
|
||||
# | x | | |
|
||||
# Have the Player 2 make a move.
|
||||
echo "
|
||||
|
||||
The second player is making a move."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 6: Player 2 makes the 6th move. ########
|
||||
######## ########
|
||||
######## | x | o | | ########
|
||||
######## | o | o | x | ########
|
||||
######## | x | | | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run make_move 2u8 1u8 2u8 "{ r1: { c1: 1u8, c2: 0u8, c3: 0u8 }, r2: { c1: 2u8, c2: 2u8, c3: 1u8 }, r3: { c1: 1u8, c2: 0u8, c3: 0u8 } }"
|
||||
|
||||
# Have the first player make a move.
|
||||
# | x | o | |
|
||||
# | o | o | x |
|
||||
# | x | x | |
|
||||
# Have the Player 1 make a move.
|
||||
echo "
|
||||
|
||||
The first player is making a move."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 7: Player 1 makes the 7th move. ########
|
||||
######## ########
|
||||
######## | x | o | | ########
|
||||
######## | o | o | x | ########
|
||||
######## | x | x | | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run make_move 1u8 3u8 2u8 "{ r1: { c1: 1u8, c2: 2u8, c3: 0u8 }, r2: { c1: 2u8, c2: 2u8, c3: 1u8 }, r3: { c1: 1u8, c2: 0u8, c3: 0u8 } }"
|
||||
|
||||
# Have the second player make a move.
|
||||
# | x | o | |
|
||||
# | o | o | x |
|
||||
# | x | x | o |
|
||||
# Have the Player 2 make a move.
|
||||
echo "
|
||||
|
||||
The second player is making a move."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 8: Player 2 makes the 8th move. ########
|
||||
######## ########
|
||||
######## | x | o | | ########
|
||||
######## | o | o | x | ########
|
||||
######## | x | x | o | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run make_move 2u8 3u8 3u8 "{ r1: { c1: 1u8, c2: 2u8, c3: 0u8 }, r2: { c1: 2u8, c2: 2u8, c3: 1u8 }, r3: { c1: 1u8, c2: 1u8, c3: 0u8 } }"
|
||||
|
||||
# Have the first player make a move.
|
||||
# | x | o | x |
|
||||
# | o | o | x |
|
||||
# | x | x | o |
|
||||
echo "
|
||||
|
||||
The first player is making a move."
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 9: Player 1 makes the 9th move. ########
|
||||
######## ########
|
||||
######## | x | o | x | ########
|
||||
######## | o | o | x | ########
|
||||
######## | x | x | o | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run make_move 1u8 1u8 3u8 "{ r1: { c1: 1u8, c2: 2u8, c3: 0u8 }, r2: { c1: 2u8, c2: 2u8, c3: 1u8 }, r3: { c1: 1u8, c2: 1u8, c3: 2u8 } }"
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## Game Complete! Players 1 & 2 Tied ########
|
||||
######## ########
|
||||
######## | x | o | x | ########
|
||||
######## | o | o | x | ########
|
||||
######## | x | x | o | ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
|
@ -1,8 +1,11 @@
|
||||
# token.aleo
|
||||
<!-- # 🪙 Token -->
|
||||
<img alt="workshop/token" width="1412" src="../.resources/token.png">
|
||||
|
||||
## Build Guide
|
||||
A transparent & shielded custom token in Leo.
|
||||
|
||||
To compile this Aleo program, run:
|
||||
## How to Build
|
||||
|
||||
To compile this Leo program, run:
|
||||
```bash
|
||||
aleo build
|
||||
leo build
|
||||
```
|
||||
|
@ -1,4 +1,5 @@
|
||||
# Leo Vote
|
||||
<!-- # 🗳️ Vote -->
|
||||
<img alt="workshop/vote" width="1412" src="../.resources/vote.png">
|
||||
|
||||
## Summary
|
||||
|
||||
@ -61,7 +62,7 @@ and can only be used(voted) by the ticket `owner`.
|
||||
Run `new_ticket`:
|
||||
|
||||
```
|
||||
aleo run new_ticket
|
||||
leo run new_ticket
|
||||
```
|
||||
|
||||
Output sample:
|
||||
|
@ -1,21 +1,74 @@
|
||||
#!/bin/bash
|
||||
# First check that Leo is installed.
|
||||
if ! command -v leo &> /dev/null
|
||||
then
|
||||
echo "leo is not installed."
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 0: Compile the vote program ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
# Build the Leo vote program.
|
||||
(
|
||||
leo build || exit
|
||||
)
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 1: Propose a new ballot ########
|
||||
######## ########
|
||||
######## --------------------------- ########
|
||||
######## | | Yes | No | ########
|
||||
######## --------------------------- ########
|
||||
######## | Votes | | | ########
|
||||
######## --------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
# Run the `propose` program function
|
||||
(
|
||||
leo run propose || exit
|
||||
)
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 2: Issue a new ballot ticket ########
|
||||
######## ########
|
||||
######## --------------------------- ########
|
||||
######## | | Yes | No | ########
|
||||
######## --------------------------- ########
|
||||
######## | Votes | 0 | 0 | ########
|
||||
######## --------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
# Run the `new_ticket` program function
|
||||
(
|
||||
leo run new_ticket || exit
|
||||
)
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 3: Vote 'Yes' on the ballot ticket ########
|
||||
######## ########
|
||||
######## --------------------------- ########
|
||||
######## | | Yes | No | ########
|
||||
######## --------------------------- ########
|
||||
######## | Votes | 1 | 0 | ########
|
||||
######## --------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
# Run the `agree` or `disagree` program function
|
||||
(
|
||||
leo run agree || exit
|
||||
# leo run disagree || exit
|
||||
)
|
||||
|
||||
|
@ -77,20 +77,24 @@ finalize new_ticket(public pid: field) {
|
||||
increment(tickets, pid, 1u64);
|
||||
}
|
||||
|
||||
// Vote to agree with a proposal.
|
||||
// Vote privately to agree with a proposal.
|
||||
@program
|
||||
function agree(ticket: Ticket) {// Privately cast the vote.
|
||||
function agree(ticket: Ticket) {
|
||||
// Finalize this vote.
|
||||
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);
|
||||
}
|
||||
|
||||
// Vote to disagree with a proposal.
|
||||
// Vote privately to disagree with a proposal.
|
||||
@program
|
||||
function disagree(ticket: Ticket) {// Privately cast the vote.
|
||||
function disagree(ticket: Ticket) {
|
||||
// Finalize this vote.
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user