-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f6ecb20
Showing
8 changed files
with
523 additions
and
0 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,12 @@ | ||
<!-- # 🪙 Token --> | ||
|
||
[//]: # (<img alt="workshop/token" width="1412" src="../.resources/token.png">) | ||
|
||
A transparent & shielded custom token in Leo. | ||
|
||
## Run Guide | ||
|
||
To run this program, run: | ||
```bash | ||
./run.sh | ||
``` |
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,93 @@ | ||
program token.aleo; | ||
|
||
record token: | ||
owner as address.private; | ||
amount as u64.private; | ||
|
||
|
||
mapping account: | ||
key as address.public; | ||
value as u64.public; | ||
|
||
function mint_public: | ||
input r0 as address.public; | ||
input r1 as u64.public; | ||
async mint_public r0 r1 into r2; | ||
output r2 as token.aleo/mint_public.future; | ||
|
||
finalize mint_public: | ||
input r0 as address.public; | ||
input r1 as u64.public; | ||
get.or_use account[r0] 0u64 into r2; | ||
add r2 r1 into r3; | ||
set r3 into account[r0]; | ||
|
||
|
||
function mint_private: | ||
input r0 as address.private; | ||
input r1 as u64.private; | ||
cast r0 r1 into r2 as token.record; | ||
output r2 as token.record; | ||
|
||
|
||
function transfer_public: | ||
input r0 as address.public; | ||
input r1 as u64.public; | ||
async transfer_public self.caller r0 r1 into r2; | ||
output r2 as token.aleo/transfer_public.future; | ||
|
||
finalize transfer_public: | ||
input r0 as address.public; | ||
input r1 as address.public; | ||
input r2 as u64.public; | ||
get.or_use account[r0] 0u64 into r3; | ||
sub r3 r2 into r4; | ||
set r4 into account[r0]; | ||
get.or_use account[r1] 0u64 into r5; | ||
add r5 r2 into r6; | ||
set r6 into account[r1]; | ||
|
||
|
||
function transfer_private: | ||
input r0 as token.record; | ||
input r1 as address.private; | ||
input r2 as u64.private; | ||
sub r0.amount r2 into r3; | ||
cast r0.owner r3 into r4 as token.record; | ||
cast r1 r2 into r5 as token.record; | ||
output r4 as token.record; | ||
output r5 as token.record; | ||
|
||
|
||
function transfer_private_to_public: | ||
input r0 as token.record; | ||
input r1 as address.public; | ||
input r2 as u64.public; | ||
sub r0.amount r2 into r3; | ||
cast r0.owner r3 into r4 as token.record; | ||
async transfer_private_to_public r1 r2 into r5; | ||
output r4 as token.record; | ||
output r5 as token.aleo/transfer_private_to_public.future; | ||
|
||
finalize transfer_private_to_public: | ||
input r0 as address.public; | ||
input r1 as u64.public; | ||
get.or_use account[r0] 0u64 into r2; | ||
add r2 r1 into r3; | ||
set r3 into account[r0]; | ||
|
||
|
||
function transfer_public_to_private: | ||
input r0 as address.public; | ||
input r1 as u64.public; | ||
cast r0 r1 into r2 as token.record; | ||
async transfer_public_to_private self.caller r1 into r3; | ||
output r2 as token.record; | ||
output r3 as token.aleo/transfer_public_to_private.future; | ||
|
||
finalize transfer_public_to_private: | ||
input r0 as address.public; | ||
input r1 as u64.public; | ||
get.or_use account[r0] 0u64 into r2; | ||
sub r2 r1 into r3; | ||
set r3 into account[r0]; |
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": "token.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,34 @@ | ||
// The program input for token/src/main.leo | ||
[mint_public] | ||
receiver: address = aleo1ptqvxu4gjfge8tuhgq2pqap0u5pms4p97gwhu7dwngxshpfzcszsswzpzd; | ||
amount: u64 = 100u64; | ||
|
||
[mint_private] | ||
receiver: address = aleo1ptqvxu4gjfge8tuhgq2pqap0u5pms4p97gwhu7dwngxshpfzcszsswzpzd; | ||
amount: u64 = 100u64; | ||
|
||
[transfer_public] | ||
receiver: address = aleo1mgfq6g40l6zkhsm063n3uhr43qk5e0zsua5aszeq5080dsvlcvxsn0rrau; | ||
amount: u64 = 50u64; | ||
|
||
[transfer_private] | ||
sender: token = token { | ||
owner: aleo1ptqvxu4gjfge8tuhgq2pqap0u5pms4p97gwhu7dwngxshpfzcszsswzpzd, | ||
amount: 100u64, | ||
_nonce: 0group, | ||
}; | ||
receiver: address = aleo1mgfq6g40l6zkhsm063n3uhr43qk5e0zsua5aszeq5080dsvlcvxsn0rrau; | ||
amount: u64 = 50u64; | ||
|
||
[transfer_private_to_public] | ||
sender: token = token { | ||
owner: aleo1ptqvxu4gjfge8tuhgq2pqap0u5pms4p97gwhu7dwngxshpfzcszsswzpzd, | ||
amount: 100u64, | ||
_nonce: 0group, | ||
}; | ||
receiver: address = aleo1mgfq6g40l6zkhsm063n3uhr43qk5e0zsua5aszeq5080dsvlcvxsn0rrau; | ||
amount: u64 = 50u64; | ||
|
||
[transfer_public_to_private] | ||
receiver: address = aleo1mgfq6g40l6zkhsm063n3uhr43qk5e0zsua5aszeq5080dsvlcvxsn0rrau; | ||
amount: u64 = 50u64; |
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": "token.aleo", | ||
"version": "0.0.0", | ||
"description": "", | ||
"license": "MIT" | ||
} |
Oops, something went wrong.