Skip to content

Commit

Permalink
Merge pull request #2881 from AleoHQ/feat/stubs
Browse files Browse the repository at this point in the history
[Feature] Support importing local and remote programs.
  • Loading branch information
d0cd authored Jan 10, 2024
2 parents 5cf9f77 + 0bb52d3 commit 8cdab3b
Show file tree
Hide file tree
Showing 916 changed files with 11,752 additions and 5,058 deletions.
5 changes: 5 additions & 0 deletions .circleci/lottery/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
*.avm
*.prover
*.verifier
outputs/
19 changes: 19 additions & 0 deletions .circleci/lottery/README.md
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
```
26 changes: 26 additions & 0 deletions .circleci/lottery/build/main.aleo
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];
6 changes: 6 additions & 0 deletions .circleci/lottery/build/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"program": "lottery.aleo",
"version": "0.0.0",
"description": "",
"license": "MIT"
}
2 changes: 2 additions & 0 deletions .circleci/lottery/inputs/lottery.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// The program input for lottery/src/main.leo
[play]
1 change: 1 addition & 0 deletions .circleci/lottery/leo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package = []
6 changes: 6 additions & 0 deletions .circleci/lottery/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"program": "lottery.aleo",
"version": "0.0.0",
"description": "",
"license": "MIT"
}
10 changes: 10 additions & 0 deletions .circleci/lottery/run.sh
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
30 changes: 30 additions & 0 deletions .circleci/lottery/src/main.leo
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);

}
}
5 changes: 5 additions & 0 deletions .circleci/tictactoe/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
*.avm
*.prover
*.verifier
outputs/
82 changes: 82 additions & 0 deletions .circleci/tictactoe/README.md
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 |
Loading

0 comments on commit 8cdab3b

Please sign in to comment.