Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
KevKevSmth committed Dec 6, 2023
0 parents commit 7ef9a15
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .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 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 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 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 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]
6 changes: 6 additions & 0 deletions 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 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 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);

}
}

0 comments on commit 7ef9a15

Please sign in to comment.