impl program json, aleo build and run working

This commit is contained in:
collin 2022-07-11 14:10:22 -07:00
parent 616a2e944d
commit c719843223
17 changed files with 166 additions and 47 deletions

33
Cargo.lock generated
View File

@ -590,9 +590,9 @@ dependencies = [
[[package]]
name = "crypto-common"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5999502d32b9c48d492abe66392408144895020ec4709e549e840799f3bb74c0"
checksum = "2ccfd8c0ee4cce11e45b3fd6f9d5e69e0cc62912aa6a0cb1bf4617b0eba5a12f"
dependencies = [
"generic-array",
"typenum",
@ -927,9 +927,9 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
[[package]]
name = "hashbrown"
version = "0.12.1"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3"
checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022"
dependencies = [
"ahash",
]
@ -1000,9 +1000,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "hyper"
version = "0.14.19"
version = "0.14.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42dc3c131584288d375f2d07f822b0cb012d8c6fb899a5b9fdb3cb7eb9b6004f"
checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac"
dependencies = [
"bytes",
"futures-channel",
@ -1214,7 +1214,6 @@ dependencies = [
"serde",
"serde_json",
"snarkvm",
"snarkvm-circuit",
"sys-info",
"test_dir",
"toml",
@ -1531,9 +1530,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "openssl"
version = "0.10.40"
version = "0.10.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e"
checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0"
dependencies = [
"bitflags",
"cfg-if",
@ -1563,9 +1562,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.74"
version = "0.9.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "835363342df5fba8354c5b453325b110ffd54044e588c539cf2f20a8014e4cb1"
checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f"
dependencies = [
"autocfg",
"cc",
@ -2077,9 +2076,9 @@ checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1"
[[package]]
name = "serde"
version = "1.0.138"
version = "1.0.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47"
checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6"
dependencies = [
"serde_derive",
]
@ -2096,9 +2095,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.138"
version = "1.0.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c"
checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb"
dependencies = [
"proc-macro2 1.0.40",
"quote 1.0.20",
@ -2131,9 +2130,9 @@ dependencies = [
[[package]]
name = "serde_yaml"
version = "0.8.24"
version = "0.8.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "707d15895415db6628332b737c838b88c598522e4dc70647e59b72312924aebc"
checksum = "1ec0091e1f5aa338283ce049bd9dfefd55e1f168ac233e85c1ffe0038fb48cbe"
dependencies = [
"indexmap",
"ryu",

View File

@ -54,10 +54,6 @@ version = "1.5.3"
git = "https://github.com/AleoHQ/snarkVM.git"
rev = "18ee4e5"
[dependencies.snarkvm-circuit]
git = "https://github.com/AleoHQ/snarkVM.git"
rev = "18ee4e5"
[dependencies.backtrace]
version = "0.3.66"

View File

@ -27,7 +27,7 @@ path = "../../leo/span"
version = "1.5.3"
[dependencies.indexmap]
version = "1.8.0"
version = "1.9"
features = [ "serde-1" ]
[dependencies.serde]

View File

@ -32,5 +32,5 @@ version = "1.5.3"
path = "../../leo/span"
version = "1.5.3"
[dependencies]
indexmap = "1.7.0"
[dependencies.indexmap]
version = "1.9"

View File

@ -35,7 +35,7 @@ git = "https://github.com/AleoHQ/snarkVM.git"
rev = "85b7a79"
[dependencies.indexmap]
version = "1.8"
version = "1.9"
[dependencies.lazy_static]
version = "1.3.0"

View File

@ -21,8 +21,8 @@ rust-version = "1.56.1"
[lib]
path = "src/lib.rs"
[dependencies]
indexmap = "1.7.0"
[dependencies.indexmap]
version = "1.9"
[dependencies.leo-ast]
path = "../ast"

View File

@ -1,9 +0,0 @@
record Token {
owner: address,
balance: u64,
token_amount: u64,
}
function main(r0: Token) -> u64 {
return r0.token_amount + r0.token_amount;
}

View File

@ -1,5 +1,5 @@
[project]
name = "hello-world"
name = "hello"
version = "0.3.0"
description = "A minimal token program in Leo."
license = "LICENSE-MIT"

View File

@ -0,0 +1,3 @@
function main(a: u32, b: u32) -> u32 {
return a + b;
}

View File

@ -25,10 +25,9 @@ use leo_package::{
source::{MainFile, MAIN_FILENAME, SOURCE_DIRECTORY_NAME},
};
use snarkvm_circuit::prelude::*;
use clap::StructOpt;
use tracing::span::Span;
use leo_package::outputs::ProgramJson;
/// Compiler Options wrapper for Build command. Also used by other commands which
/// require Build command output as their input.
@ -181,6 +180,15 @@ impl Command for Build {
// Write the Aleo file to the output directory.
let aleo_file = AleoFile::new(&package_name, "aleo"); // Specifies `.aleo` in `program foo.aleo;` identifier.
aleo_file.write_to(&path, bytecode)?;
// Write the program.json file to the output directory.
let program_file = ProgramJson::new(
aleo_file.program_id(),
"0.0.0".to_string(),
"".to_string(),
"MIT".to_string(),
);
program_file.write_to(&path)?;
}
// Generate the program on the constraint system and verify correctness

View File

@ -29,7 +29,7 @@ use std::{
path::Path,
};
pub static CHECKSUM_FILE_EXTENSION: &str = ".aleo";
pub static MAIN_ALEO_FILE_NAME: &str = "main.aleo";
#[derive(Deserialize)]
pub struct AleoFile {
@ -65,7 +65,7 @@ impl AleoFile {
let mut file = File::create(&path).map_err(PackageError::io_error_aleo_file)?;
// Write program id to file.
let mut aleo_file = format!("program {}.{};\n\n", self.package_name, self.network);
let mut aleo_file = format!("program {}.{};\n", self.package_name, self.network);
aleo_file.push_str(&program_string);
file.write_all(aleo_file.as_bytes())
@ -92,8 +92,13 @@ impl AleoFile {
path.to_mut().push(OUTPUTS_DIRECTORY_NAME);
}
path.to_mut()
.push(format!("{}{}", self.package_name, CHECKSUM_FILE_EXTENSION));
.push(MAIN_ALEO_FILE_NAME);
}
path
}
/// Returns the program id as a string.
pub fn program_id(&self) -> String {
format!("{}.{}", self.package_name, self.network)
}
}

View File

@ -28,6 +28,9 @@ pub use self::checksum::*;
pub mod directory;
pub use directory::*;
pub mod program_json;
pub use program_json::*;
pub mod proof;
pub use self::proof::*;

View File

@ -0,0 +1,104 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
//! The program JSON file for an aleo file.
use crate::outputs::OUTPUTS_DIRECTORY_NAME;
use leo_errors::{PackageError, Result};
use serde::Deserialize;
use std::{
borrow::Cow,
fs::{
File, {self},
},
io::Write,
path::Path,
};
pub static PROGRAM_JSON_FILE_NAME: &str = "program.json";
#[derive(Deserialize)]
pub struct ProgramJson {
pub program: String,
pub version: String,
pub description: String,
pub license: String,
}
impl ProgramJson {
pub fn new(
program: String,
version: String,
description: String,
license: String,
) -> Self {
Self {
program,
version,
description,
license,
}
}
/// Writes the given program id to a program json file.
pub fn write_to(&self, path: &Path) -> Result<()> {
let path = self.setup_file_path(path);
let mut file = File::create(&path).map_err(PackageError::io_error_aleo_file)?;
// Write program json file.
let aleo_file = format!(
r#"{{
"program": "{program}",
"version": "{version}",
"description": "{description}",
"license": "{license}"
}}"#,
program = self.program,
version = self.version,
description = self.description,
license = self.license,
);
file.write_all(aleo_file.as_bytes())
.map_err(PackageError::io_error_aleo_file)?;
Ok(())
}
/// Removes the program json file at the given path if it exists. Returns `true` on success,
/// `false` if the file doesn't exist, and `Error` if the file system fails during operation.
pub fn remove(&self, path: &Path) -> Result<bool> {
let path = self.setup_file_path(path);
if !path.exists() {
return Ok(false);
}
fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_aleo_file(path.into_owned()))?;
Ok(true)
}
fn setup_file_path<'a>(&self, path: &'a Path) -> Cow<'a, Path> {
let mut path = Cow::from(path);
if path.is_dir() {
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.to_mut().push(OUTPUTS_DIRECTORY_NAME);
}
path.to_mut()
.push(PROGRAM_JSON_FILE_NAME);
}
path
}
}

View File

@ -18,8 +18,18 @@ license = "GPL-3.0"
edition = "2021"
rust-version = "1.56.1"
[dependencies]
fxhash = "0.2.1"
indexmap = { version = "1.8", features = ["serde"] }
serde = { version = "1.0.133", features = [ "derive", "rc" ] }
scoped-tls = { version = "1.0.0" }
[dependencies.indexmap]
version = "1.9"
features = ["serde"]
[dependencies.fxhash]
version = "0.2.1"
[dependencies.scoped-tls]
version = "1.0.0"
[dependencies.serde]
version = "1.0.133"
features = ["derive", "rc"]