-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2881 from AleoHQ/feat/stubs
[Feature] Support importing local and remote programs.
- Loading branch information
Showing
916 changed files
with
11,752 additions
and
5,058 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.env | ||
*.avm | ||
*.prover | ||
*.verifier | ||
outputs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# lottery.aleo | ||
|
||
## Run Guide | ||
|
||
To run this program, run: | ||
```bash | ||
leo run play | ||
|
||
or | ||
|
||
./run.sh | ||
``` | ||
|
||
## Execute Guide | ||
|
||
To execute this program, run: | ||
```bash | ||
leo execute play | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
program lottery.aleo; | ||
|
||
record Ticket: | ||
owner as address.private; | ||
|
||
|
||
mapping num_winners: | ||
key as u8.public; | ||
value as u8.public; | ||
|
||
function play: | ||
cast self.caller into r0 as Ticket.record; | ||
async play into r1; | ||
output r0 as Ticket.record; | ||
output r1 as lottery.aleo/play.future; | ||
|
||
finalize play: | ||
lte block.height 1000u32 into r0; | ||
assert.eq r0 true; | ||
rand.chacha into r1 as boolean; | ||
assert.eq r1 true; | ||
get.or_use num_winners[0u8] 0u8 into r2; | ||
lt r2 5u8 into r3; | ||
assert.eq r3 true; | ||
add r2 1u8 into r4; | ||
set r4 into num_winners[0u8]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"program": "lottery.aleo", | ||
"version": "0.0.0", | ||
"description": "", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// The program input for lottery/src/main.leo | ||
[play] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"program": "lottery.aleo", | ||
"version": "0.0.0", | ||
"description": "", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
# First check that Leo is installed. | ||
if ! command -v leo &> /dev/null | ||
then | ||
echo "leo is not installed." | ||
exit | ||
fi | ||
|
||
# Run the lottery example | ||
leo run play || exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// The 'lottery' program. | ||
program lottery.aleo { | ||
|
||
mapping num_winners: u8 => u8; | ||
|
||
record Ticket { | ||
owner: address, | ||
} | ||
|
||
transition play() -> Ticket { | ||
let ticket: Ticket = Ticket { | ||
owner: self.caller, | ||
}; | ||
return ticket then finalize(); | ||
} | ||
|
||
finalize play() { | ||
// Check that the lottery has not expired. | ||
assert(block.height <= 1000u32); | ||
|
||
// Randomly select whether or not the ticket is a winner. | ||
assert(ChaCha::rand_bool()); | ||
|
||
// Check that the maximum number of winners have not been reached. | ||
let winners: u8 = num_winners.get_or_use(0u8, 0u8); | ||
assert(winners < 5u8); | ||
num_winners.set(0u8, winners + 1u8); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.env | ||
*.avm | ||
*.prover | ||
*.verifier | ||
outputs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!-- # ⭕ Tic-Tac-Toe --> | ||
|
||
[//]: # (<img alt="workshop/tictactoe" width="1412" src="../.resources/tictactoe.png">) | ||
|
||
A standard game of Tic-Tac-Toe in Leo. | ||
|
||
⭕ ❕ ⭕ ❕ ❌ | ||
|
||
➖ ➕ ➖ ➕ ➖ | ||
|
||
⭕ ❕ ❌ ❕ ⭕ | ||
|
||
➖ ➕ ➖ ➕ ➖ | ||
|
||
❌ ❕ ❌ ❕ ⭕ | ||
|
||
## Representing State | ||
Leo allows users to define composite data types with the `struct` keyword. | ||
The game board is represented by a struct called `Board`, which contains three `Row`s. | ||
An alternative representation would be to use an array, however, these are not yet supported in Leo. | ||
|
||
## Language Features | ||
- `struct` declarations | ||
- conditional statements | ||
- early termination. Leo allows users to return from a function early using the `return` keyword. | ||
|
||
## Running the Program | ||
|
||
Leo provides users with a command line interface for compiling and running Leo programs. | ||
Users may either specify input values via the command line or provide an input file in `inputs/`. | ||
|
||
### Providing inputs via the command line. | ||
1. Run | ||
```bash | ||
leo run <function_name> <input_1> <input_2> ... | ||
``` | ||
See `./run.sh` for an example. | ||
|
||
|
||
### Using an input file. | ||
1. Modify `inputs/tictactoe.in` with the desired inputs. | ||
2. Run | ||
```bash | ||
leo run <function_name> | ||
``` | ||
|
||
## Executing the Program | ||
```bash | ||
leo execute <function_name> <input_1> <input_2> ... | ||
``` | ||
|
||
## Playing the Game | ||
|
||
### 1. Create a new game board | ||
```bash | ||
leo run new | ||
``` | ||
| | | | | ||
|---|---|---| | ||
| 0 | 0 | 0 | | ||
| 0 | 0 | 0 | | ||
| 0 | 0 | 0 | | ||
|
||
### 2. Player 1 makes a move | ||
```bash | ||
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 } }" | ||
``` | ||
| | | | | ||
|---|---|---| | ||
| 1 | 0 | 0 | | ||
| 0 | 0 | 0 | | ||
| 0 | 0 | 0 | | ||
|
||
### 3. Player 2 makes a move | ||
```bash | ||
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 } }" | ||
``` | ||
| | | | | ||
|---|---|---| | ||
| 1 | 0 | 0 | | ||
| 0 | 2 | 0 | | ||
| 0 | 0 | 0 | |
Oops, something went wrong.