mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
Update leo examples (#2501)
* improve leo example run scripts * add leo build warning message, reduce number of calls to snarkvm package open * cargo clippy * Update examples/token/run.sh Co-authored-by: Eric McCarthy <7607035+bendyarm@users.noreply.github.com> Signed-off-by: Collin Chin <16715212+collinc97@users.noreply.github.com> * Update examples/token/run.sh Co-authored-by: Eric McCarthy <7607035+bendyarm@users.noreply.github.com> Signed-off-by: Collin Chin <16715212+collinc97@users.noreply.github.com> * Update examples/token/run.sh Co-authored-by: Eric McCarthy <7607035+bendyarm@users.noreply.github.com> Signed-off-by: Collin Chin <16715212+collinc97@users.noreply.github.com> * Update examples/token/run.sh Co-authored-by: Eric McCarthy <7607035+bendyarm@users.noreply.github.com> Signed-off-by: Collin Chin <16715212+collinc97@users.noreply.github.com> * Update examples/token/run.sh Co-authored-by: Eric McCarthy <7607035+bendyarm@users.noreply.github.com> Signed-off-by: Collin Chin <16715212+collinc97@users.noreply.github.com> * fix comments * make auctioneer the starting private key in auction example --------- Signed-off-by: Collin Chin <16715212+collinc97@users.noreply.github.com> Co-authored-by: Eric McCarthy <7607035+bendyarm@users.noreply.github.com>
This commit is contained in:
parent
ac38dfa028
commit
d31b707c4b
@ -1,4 +1,4 @@
|
||||
|
||||
NETWORK=testnet3
|
||||
PRIVATE_KEY=APrivateKey1zkpG9Af9z5Ha4ejVyMCqVFXRKknSm8L1ELEwcc4htk9YhVK
|
||||
PRIVATE_KEY=APrivateKey1zkp5wvamYgK3WCAdpBQxZqQX8XnuN2u11Y6QprZTriVwZVc
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
<!-- # 🏛️ Blind Auction -->
|
||||
<img alt="workshop/auction" width="1412" src="../.resources/auction.png">
|
||||
|
||||
[//]: # (<img alt="workshop/auction" width="1412" src="../.resources/auction.png">)
|
||||
|
||||
A first-price sealed-bid auction in Leo.
|
||||
|
||||
|
@ -1,3 +1,11 @@
|
||||
#!/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 first bidder.
|
||||
# Swap these into program.json, when running transactions as the first bidder.
|
||||
# "private_key": "APrivateKey1zkpG9Af9z5Ha4ejVyMCqVFXRKknSm8L1ELEwcc4htk9YhVK"
|
||||
|
@ -1,5 +1,6 @@
|
||||
<!-- # 🏦 Basic Bank -->
|
||||
<img alt="workshop/basic_bank" width="1412" src="../.resources/basic_bank.png">
|
||||
|
||||
[//]: # (<img alt="workshop/basic_bank" width="1412" src="../.resources/basic_bank.png">)
|
||||
|
||||
A simple-interest yielding bank account in Leo.
|
||||
|
||||
|
@ -1,3 +1,11 @@
|
||||
#!/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",
|
||||
@ -199,3 +207,4 @@ echo "
|
||||
###############################################################################
|
||||
"
|
||||
leo run withdraw aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a 50u64 1234u64 15u64 || exit
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
# Leo Battleship 🏴☠️
|
||||
<!-- # Leo Battleship 🏴☠️ -->
|
||||
|
||||
[//]: # (<img alt="workshop/battleship" width="1412" src="../.resources/battleship.png">)
|
||||
|
||||
- [Summary](#summary)
|
||||
- [Build](#how-to-build)
|
||||
|
@ -1,3 +1,10 @@
|
||||
#!/bin/bash
|
||||
# First check that Leo is installed.
|
||||
if ! command -v leo &> /dev/null
|
||||
then
|
||||
echo "leo is not installed."
|
||||
exit
|
||||
fi
|
||||
# Follow along in the README.md for a detailed explanation of each step.
|
||||
|
||||
# 1: Initializing Player 1
|
||||
|
@ -1,5 +1,6 @@
|
||||
<!-- # ⭕ Tic-Tac-Toe -->
|
||||
<img alt="workshop/tictactoe" width="1412" src="../.resources/tictactoe.png">
|
||||
|
||||
[//]: # (<img alt="workshop/tictactoe" width="1412" src="../.resources/tictactoe.png">)
|
||||
|
||||
A standard game of Tic-Tac-Toe in Leo.
|
||||
|
||||
|
@ -1,3 +1,10 @@
|
||||
#!/bin/bash
|
||||
# First check that Leo is installed.
|
||||
if ! command -v leo &> /dev/null
|
||||
then
|
||||
echo "leo is not installed."
|
||||
exit
|
||||
fi
|
||||
# Create a new game.
|
||||
echo "
|
||||
###############################################################################
|
||||
|
@ -1,5 +1,6 @@
|
||||
<!-- # 🪙 Token -->
|
||||
<img alt="workshop/token" width="1412" src="../.resources/token.png">
|
||||
|
||||
[//]: # (<img alt="workshop/token" width="1412" src="../.resources/token.png">)
|
||||
|
||||
A transparent & shielded custom token in Leo.
|
||||
|
||||
|
239
examples/token/run.sh
Executable file
239
examples/token/run.sh
Executable file
@ -0,0 +1,239 @@
|
||||
#!/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 Alice.
|
||||
# Swap these into program.json, when running transactions as the first bidder.
|
||||
# "private_key": "APrivateKey1zkp1w8PTxrRgGfAtfKUSq43iQyVbdQHfhGbiNPEg2LVSEXR",
|
||||
# "address": "aleo13ssze66adjjkt795z9u5wpq8h6kn0y2657726h4h3e3wfnez4vqsm3008q"
|
||||
|
||||
# The private key and address of Bob.
|
||||
# Swap these into program.json, when running transactions as the second bidder.
|
||||
# "private_key": "APrivateKey1zkpFo72g7N9iFt3JzzeG8CqsS5doAiXyFvNCgk2oHvjRCzF"
|
||||
# "address": "aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z"
|
||||
|
||||
# Swap in the private key of Alice.
|
||||
echo "
|
||||
NETWORK=testnet3
|
||||
PRIVATE_KEY=APrivateKey1zkp1w8PTxrRgGfAtfKUSq43iQyVbdQHfhGbiNPEg2LVSEXR
|
||||
" > .env
|
||||
|
||||
# Publicly mint 100 tokens for Alice.
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 1: Publicly mint 100 tokens for Alice ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PUBLIC BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 100 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PRIVATE BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run mint_public aleo13ssze66adjjkt795z9u5wpq8h6kn0y2657726h4h3e3wfnez4vqsm3008q 100u64
|
||||
|
||||
# Swap in the private key of Bob.
|
||||
echo "
|
||||
NETWORK=testnet3
|
||||
PRIVATE_KEY=APrivateKey1zkpFo72g7N9iFt3JzzeG8CqsS5doAiXyFvNCgk2oHvjRCzF
|
||||
" > .env
|
||||
|
||||
# Privately mint 100 tokens for Bob.
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 2: Privately mint 100 tokens for Bob ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PUBLIC BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 100 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PRIVATE BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 100 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run mint_private aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z 100u64
|
||||
|
||||
# Swap in the private key of Alice.
|
||||
echo "
|
||||
NETWORK=testnet3
|
||||
PRIVATE_KEY=APrivateKey1zkp1w8PTxrRgGfAtfKUSq43iQyVbdQHfhGbiNPEg2LVSEXR
|
||||
" > .env
|
||||
|
||||
# Publicly transfer 10 tokens from Alice to Bob.
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 3: Publicly transfer 10 tokens from Alice to Bob ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PUBLIC BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 90 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 10 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PRIVATE BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 0 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 100 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run transfer_public aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z 10u64
|
||||
|
||||
# Swap in the private key of Bob.
|
||||
echo "
|
||||
NETWORK=testnet3
|
||||
PRIVATE_KEY=APrivateKey1zkpFo72g7N9iFt3JzzeG8CqsS5doAiXyFvNCgk2oHvjRCzF
|
||||
" > .env
|
||||
|
||||
# Privately transfer 20 tokens from Bob to Alice.
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 4: Privately transfer 20 tokens from Bob to Alice ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PUBLIC BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 90 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 10 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PRIVATE BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 20 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 80 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run transfer_private "{
|
||||
owner: aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z.private,
|
||||
amount: 100u64.private,
|
||||
_nonce: 6586771265379155927089644749305420610382723873232320906747954786091923851913group.public
|
||||
}" aleo13ssze66adjjkt795z9u5wpq8h6kn0y2657726h4h3e3wfnez4vqsm3008q 20u64
|
||||
|
||||
# Swap in the private key of Alice.
|
||||
echo "
|
||||
NETWORK=testnet3
|
||||
PRIVATE_KEY=APrivateKey1zkp1w8PTxrRgGfAtfKUSq43iQyVbdQHfhGbiNPEg2LVSEXR
|
||||
" > .env
|
||||
|
||||
# Convert 30 public tokens from Alice into 30 private tokens for Bob.
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 5: Convert 30 public tokens from Alice into 30 ########
|
||||
######## private tokens for Bob. ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PUBLIC BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 60 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 10 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PRIVATE BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 20 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 110 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run transfer_public_to_private aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z 30u64
|
||||
|
||||
# Swap in the private key of Bob.
|
||||
echo "
|
||||
NETWORK=testnet3
|
||||
PRIVATE_KEY=APrivateKey1zkpFo72g7N9iFt3JzzeG8CqsS5doAiXyFvNCgk2oHvjRCzF
|
||||
" > .env
|
||||
|
||||
# Convert 40 private tokens from Bob into 40 public tokens for Alice.
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
######## STEP 6: Convert 40 private tokens from Bob into 40 ########
|
||||
######## public tokens for Alice. ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PUBLIC BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 100 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 10 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | PRIVATE BALANCES | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Alice | 20 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## | Bob | 70 | ########
|
||||
######## ----------------------------------------- ########
|
||||
######## ########
|
||||
###############################################################################
|
||||
"
|
||||
leo run transfer_private_to_public "{
|
||||
owner: aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z.private,
|
||||
amount: 80u64.private,
|
||||
_nonce: 1852830456042139988098466781381363679605019151318121788109768539956661608520group.public
|
||||
}" aleo13ssze66adjjkt795z9u5wpq8h6kn0y2657726h4h3e3wfnez4vqsm3008q 40u64
|
||||
|
||||
|
||||
# Swap in the private key of Alice.
|
||||
# This is done to ensure that program.json is the same after every execution of ./run.sh.
|
||||
echo "
|
||||
NETWORK=testnet3
|
||||
PRIVATE_KEY=APrivateKey1zkp1w8PTxrRgGfAtfKUSq43iQyVbdQHfhGbiNPEg2LVSEXR
|
||||
" > .env
|
@ -1,5 +1,6 @@
|
||||
<!-- # 🗳️ Vote -->
|
||||
<img alt="workshop/vote" width="1412" src="../.resources/vote.png">
|
||||
|
||||
[//]: # (<img alt="workshop/vote" width="1412" src="../.resources/vote.png">)
|
||||
|
||||
## Summary
|
||||
|
||||
|
@ -1,3 +1,11 @@
|
||||
#!/bin/bash
|
||||
# First check that Leo is installed.
|
||||
if ! command -v leo &> /dev/null
|
||||
then
|
||||
echo "leo is not installed."
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
######## ########
|
||||
|
@ -18,6 +18,7 @@ use crate::cli::{commands::*, context::*, helpers::*};
|
||||
use leo_errors::Result;
|
||||
|
||||
use clap::Parser;
|
||||
use colored::Colorize;
|
||||
use std::{path::PathBuf, process::exit};
|
||||
|
||||
/// CLI Arguments entry point - includes global parameters and subcommands
|
||||
@ -114,7 +115,22 @@ pub fn run_with_args(cli: CLI) -> Result<()> {
|
||||
|
||||
match cli.command {
|
||||
Commands::New { command } => command.try_execute(context),
|
||||
Commands::Build { command } => command.try_execute(context),
|
||||
Commands::Build { command } => {
|
||||
// Enter tracing span
|
||||
let span = command.log_span();
|
||||
let span = span.enter();
|
||||
|
||||
// Leo build is deprecated in version 1.9.0
|
||||
tracing::info!(
|
||||
"⚠️ Attention - This command is deprecated. Use the {} command.\n",
|
||||
"'run'".to_string().bold()
|
||||
);
|
||||
|
||||
// Drop tracing span
|
||||
drop(span);
|
||||
|
||||
command.try_execute(context)
|
||||
}
|
||||
Commands::Clean { command } => command.try_execute(context),
|
||||
Commands::Run { command } => command.try_execute(context),
|
||||
Commands::Execute { command } => command.try_execute(context),
|
||||
|
@ -165,7 +165,9 @@ impl Command for Build {
|
||||
None
|
||||
};
|
||||
|
||||
// Leo build is deprecated in version 1.9.0
|
||||
// `Package::open` checks that the build directory and that `main.aleo` and all imported files are well-formed.
|
||||
Package::<CurrentNetwork>::open(&build_directory).map_err(CliError::failed_to_execute_build)?;
|
||||
|
||||
// // Unset the Leo panic hook.
|
||||
// let _ = std::panic::take_hook();
|
||||
//
|
||||
@ -237,13 +239,6 @@ fn compile_leo_file(
|
||||
.write_all(instructions.as_bytes())
|
||||
.map_err(CliError::failed_to_load_instructions)?;
|
||||
|
||||
// `Package::open` checks that the build directory and that `main.aleo` is well-formed.
|
||||
match Package::<CurrentNetwork>::open(build) {
|
||||
// Log the build as successful.
|
||||
Ok(_) => tracing::info!("Compiled '{}' into Aleo instructions", file_name),
|
||||
// Log the error.
|
||||
Err(e) => tracing::info!("{}", CliError::failed_to_execute_build(e)),
|
||||
};
|
||||
|
||||
tracing::info!("✅ Compiled '{}' into Aleo instructions", file_name);
|
||||
Ok(symbol_table.structs)
|
||||
}
|
||||
|
@ -37,11 +37,11 @@ impl Command for Clean {
|
||||
|
||||
// Removes the outputs/ directory.
|
||||
let outputs_path = OutputsDirectory::remove(&path)?;
|
||||
tracing::info!("cleaned the outputs directory {}", outputs_path.dimmed());
|
||||
tracing::info!("🧹 Cleaned the outputs directory {}", outputs_path.dimmed());
|
||||
|
||||
// Removes the build/ directory.
|
||||
let build_path = BuildDirectory::remove(&path)?;
|
||||
tracing::info!("cleaned the build directory {}", build_path.dimmed());
|
||||
tracing::info!("🧹 Cleaned the build directory {}", build_path.dimmed());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user