mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-24 02:42:21 +03:00
fix examples
This commit is contained in:
parent
266fdd7a5e
commit
c0e968206b
@ -23,7 +23,7 @@ use std::{collections::HashMap, fmt::Write as _};
|
||||
|
||||
impl<'a> CodeGenerator<'a> {
|
||||
pub(crate) fn visit_program(&mut self, input: &'a Program) -> String {
|
||||
let mut program_string = format!("program {}.{};\n", input.name, input.network);
|
||||
let mut program_string = format!("program {}.{};\n\n", input.name, input.network);
|
||||
|
||||
// Visit each `Circuit` or `Record` in the Leo AST and produce a bytecode circuit.
|
||||
program_string.push_str(
|
||||
|
@ -411,7 +411,7 @@ create_messages!(
|
||||
@backtraced
|
||||
failed_to_load_instructions {
|
||||
args: (error: impl Display),
|
||||
msg: format!("Failed to load compiled Aleo instructions into an Aleo file: {}", error),
|
||||
msg: format!("Failed to load compiled Aleo instructions into an Aleo file:\n{}", error),
|
||||
help: Some("This is a Leo code generation bug. Please report it to https://github.com/AleoHQ/leo/issues/new/choose".to_string()),
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,12 @@
|
||||
program helloworld.aleo;
|
||||
|
||||
|
||||
function compute:
|
||||
input r0 as u32.private;
|
||||
input r1 as u32.private;
|
||||
add r0 r1 into r2;
|
||||
output r2 as u32.private;
|
||||
|
||||
function main:
|
||||
input r0 as u32.public;
|
||||
input r1 as u32.private;
|
||||
|
@ -1,5 +1,7 @@
|
||||
// The 'helloworld' main function.
|
||||
function main(public a: u32, b: u32) -> u32 {
|
||||
let c: u32 = a + b;
|
||||
return c;
|
||||
function compute(a: u32, b: u32) -> u32 {
|
||||
return a + b;
|
||||
}
|
||||
function main(public a: u32, b: u32) -> u32 {
|
||||
return a + b;
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
// The program input for token/src/main.leo
|
||||
[main]
|
||||
a: u32 = 1u32;
|
||||
b: u32 = 2u32;
|
||||
|
11
examples/token/main.aleo
Normal file
11
examples/token/main.aleo
Normal file
@ -0,0 +1,11 @@
|
||||
program token.aleo;
|
||||
|
||||
record token:
|
||||
owner as address.private;
|
||||
balance as u64.private;
|
||||
token_amount as u64.private;
|
||||
|
||||
function compute:
|
||||
input r0 as token.record;
|
||||
add r0.token_amount r0.token_amount into r1;
|
||||
output r1 as u64.private;
|
@ -1,50 +1,9 @@
|
||||
// CAUTION: Work in progress
|
||||
|
||||
record Token {
|
||||
// The token owner.
|
||||
owner: address,
|
||||
// The Aleo balance (in gates).
|
||||
balance: u64,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
owner: address,
|
||||
balance: u64,
|
||||
token_amount: u64,
|
||||
}
|
||||
|
||||
circuit Receiver {
|
||||
// The token owner.
|
||||
owner: address,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
function mint(r0: address, r1: u64) -> Token {
|
||||
let t: Token = Token {
|
||||
owner: r0,
|
||||
balance: 0u64,
|
||||
amount: r1,
|
||||
};
|
||||
return t;
|
||||
}
|
||||
|
||||
// The `transfer` function sends the specified number of tokens
|
||||
// to the receiver from the provided token record.
|
||||
function transfer(r0: Token, r1: Receiver) -> (Token, Token) {
|
||||
// Checks the given token record has sufficient balance.
|
||||
// This `sub` operation is safe, and the proof will fail
|
||||
// if an overflow occurs. The output register `r2` holds
|
||||
// the change amount to be returned to the sender.
|
||||
let r2: u64 = r0.amount - r1.amount;
|
||||
|
||||
// Calls the `mint` function to produce a token record
|
||||
// for the specified receiver.
|
||||
let r3: Token = mint(r1.owner, r1.amount);
|
||||
|
||||
// Calls the `mint` function to produce a token record
|
||||
// with the change amount for the sender.
|
||||
let r4: Token = mint(r0.owner, r0.amount);
|
||||
|
||||
return (r3, r4);
|
||||
}
|
||||
|
||||
function main() -> u8 {
|
||||
return 1u8;
|
||||
function compute(t: Token) -> u64 {
|
||||
return t.token_amount + t.token_amount;
|
||||
}
|
Loading…
Reference in New Issue
Block a user