From b7eac7864461aff4085206700a45e2d5eb3a22d3 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:44:21 -0700 Subject: [PATCH 01/20] add ENDPOINT to .env --- compiler/compiler/tests/utilities/mod.rs | 3 +- leo/cli/cli.rs | 77 +++++++++++++++++++++--- leo/cli/commands/account.rs | 68 ++++++++++++++++----- leo/cli/commands/example.rs | 10 ++- leo/cli/commands/new.rs | 11 +++- leo/package/src/package.rs | 4 +- leo/package/src/root/env.rs | 18 +++--- 7 files changed, 151 insertions(+), 40 deletions(-) diff --git a/compiler/compiler/tests/utilities/mod.rs b/compiler/compiler/tests/utilities/mod.rs index 3eeab76f6d..053fc93f39 100644 --- a/compiler/compiler/tests/utilities/mod.rs +++ b/compiler/compiler/tests/utilities/mod.rs @@ -121,6 +121,7 @@ pub fn setup_build_directory( program_name: &str, bytecode: &String, handler: &Handler, + endpoint: String, ) -> Result, ()> { // Initialize a temporary directory. let directory = temp_dir(); @@ -137,7 +138,7 @@ pub fn setup_build_directory( let _manifest_file = Manifest::create(&directory, &program_id).unwrap(); // Create the environment file. - Env::::new().unwrap().write_to(&directory).unwrap(); + Env::::new(None, endpoint).unwrap().write_to(&directory).unwrap(); if Env::::exists_at(&directory) { println!(".env file created at {:?}", &directory); } diff --git a/leo/cli/cli.rs b/leo/cli/cli.rs index 67b009bb21..0679349e0c 100644 --- a/leo/cli/cli.rs +++ b/leo/cli/cli.rs @@ -315,6 +315,7 @@ mod test_helpers { use std::path::Path; const NETWORK: &str = "mainnet"; + const ENDPOINT: &str = "https://api.explorer.aleo.org/v1"; pub(crate) fn sample_nested_package(temp_dir: &Path) { let name = "nested"; @@ -329,7 +330,9 @@ mod test_helpers { let new = CLI { debug: false, quiet: false, - command: Commands::New { command: New { name: name.to_string(), network: NETWORK.to_string() } }, + command: Commands::New { + command: New { name: name.to_string(), network: NETWORK.to_string(), endpoint: ENDPOINT.to_string() }, + }, path: Some(project_directory.clone()), home: None, }; @@ -430,7 +433,13 @@ function external_nested_function: let create_grandparent_project = CLI { debug: false, quiet: false, - command: Commands::New { command: New { name: "grandparent".to_string(), network: NETWORK.to_string() } }, + command: Commands::New { + command: New { + name: "grandparent".to_string(), + network: NETWORK.to_string(), + endpoint: ENDPOINT.to_string(), + }, + }, path: Some(grandparent_directory.clone()), home: None, }; @@ -438,7 +447,13 @@ function external_nested_function: let create_parent_project = CLI { debug: false, quiet: false, - command: Commands::New { command: New { name: "parent".to_string(), network: NETWORK.to_string() } }, + command: Commands::New { + command: New { + name: "parent".to_string(), + network: NETWORK.to_string(), + endpoint: ENDPOINT.to_string(), + }, + }, path: Some(parent_directory.clone()), home: None, }; @@ -446,7 +461,13 @@ function external_nested_function: let create_child_project = CLI { debug: false, quiet: false, - command: Commands::New { command: New { name: "child".to_string(), network: NETWORK.to_string() } }, + command: Commands::New { + command: New { + name: "child".to_string(), + network: NETWORK.to_string(), + endpoint: ENDPOINT.to_string(), + }, + }, path: Some(child_directory.clone()), home: None, }; @@ -561,7 +582,13 @@ program child.aleo { let create_outer_project = CLI { debug: false, quiet: false, - command: Commands::New { command: New { name: "outer".to_string(), network: NETWORK.to_string() } }, + command: Commands::New { + command: New { + name: "outer".to_string(), + network: NETWORK.to_string(), + endpoint: ENDPOINT.to_string(), + }, + }, path: Some(outer_directory.clone()), home: None, }; @@ -569,7 +596,13 @@ program child.aleo { let create_inner_1_project = CLI { debug: false, quiet: false, - command: Commands::New { command: New { name: "inner_1".to_string(), network: NETWORK.to_string() } }, + command: Commands::New { + command: New { + name: "inner_1".to_string(), + network: NETWORK.to_string(), + endpoint: ENDPOINT.to_string(), + }, + }, path: Some(inner_1_directory.clone()), home: None, }; @@ -577,7 +610,13 @@ program child.aleo { let create_inner_2_project = CLI { debug: false, quiet: false, - command: Commands::New { command: New { name: "inner_2".to_string(), network: NETWORK.to_string() } }, + command: Commands::New { + command: New { + name: "inner_2".to_string(), + network: NETWORK.to_string(), + endpoint: ENDPOINT.to_string(), + }, + }, path: Some(inner_2_directory.clone()), home: None, }; @@ -699,7 +738,13 @@ program outer.aleo { let create_outer_project = CLI { debug: false, quiet: false, - command: Commands::New { command: New { name: "outer_2".to_string(), network: NETWORK.to_string() } }, + command: Commands::New { + command: New { + name: "outer_2".to_string(), + network: NETWORK.to_string(), + endpoint: ENDPOINT.to_string(), + }, + }, path: Some(outer_directory.clone()), home: None, }; @@ -707,7 +752,13 @@ program outer.aleo { let create_inner_1_project = CLI { debug: false, quiet: false, - command: Commands::New { command: New { name: "inner_1".to_string(), network: NETWORK.to_string() } }, + command: Commands::New { + command: New { + name: "inner_1".to_string(), + network: NETWORK.to_string(), + endpoint: ENDPOINT.to_string(), + }, + }, path: Some(inner_1_directory.clone()), home: None, }; @@ -715,7 +766,13 @@ program outer.aleo { let create_inner_2_project = CLI { debug: false, quiet: false, - command: Commands::New { command: New { name: "inner_2".to_string(), network: NETWORK.to_string() } }, + command: Commands::New { + command: New { + name: "inner_2".to_string(), + network: NETWORK.to_string(), + endpoint: ENDPOINT.to_string(), + }, + }, path: Some(inner_2_directory.clone()), home: None, }; diff --git a/leo/cli/commands/account.rs b/leo/cli/commands/account.rs index 8951519c07..4440fefc17 100644 --- a/leo/cli/commands/account.rs +++ b/leo/cli/commands/account.rs @@ -49,6 +49,13 @@ pub enum Account { discreet: bool, #[clap(short = 'n', long, help = "Name of the network to use", default_value = "mainnet")] network: String, + #[clap( + short = 'e', + long, + help = "Endpoint to retrieve network state from.", + default_value = "https://api.explorer.aleo.org/v1" + )] + endpoint: String, }, /// Derive an Aleo account from a private key. Import { @@ -62,6 +69,13 @@ pub enum Account { discreet: bool, #[clap(short = 'n', long, help = "Name of the network to use", default_value = "mainnet")] network: String, + #[clap( + short = 'e', + long, + help = "Endpoint to retrieve network state from.", + default_value = "https://api.explorer.aleo.org/v1" + )] + endpoint: String, }, /// Sign a message using your Aleo private key. Sign { @@ -82,6 +96,13 @@ pub enum Account { raw: bool, #[clap(short = 'n', long, help = "Name of the network to use", default_value = "mainnet")] network: String, + #[clap( + short = 'e', + long, + help = "Endpoint to retrieve network state from.", + default_value = "https://api.explorer.aleo.org/v1" + )] + endpoint: String, }, /// Verify a message from an Aleo address. Verify { @@ -99,6 +120,13 @@ pub enum Account { raw: bool, #[clap(short = 'n', long, help = "Name of the network to use", default_value = "mainnet")] network: String, + #[clap( + short = 'e', + long, + help = "Endpoint to retrieve network state from.", + default_value = "https://api.explorer.aleo.org/v1" + )] + endpoint: String, }, } @@ -118,23 +146,23 @@ impl Command for Account { Self: Sized, { match self { - Account::New { seed, write, discreet, network } => { + Account::New { seed, write, discreet, network, endpoint } => { // Parse the network. let network = NetworkName::try_from(network.as_str())?; match network { - NetworkName::MainnetV0 => generate_new_account::(seed, write, discreet, &ctx), - NetworkName::TestnetV0 => generate_new_account::(seed, write, discreet, &ctx), + NetworkName::MainnetV0 => generate_new_account::(seed, write, discreet, &ctx, endpoint), + NetworkName::TestnetV0 => generate_new_account::(seed, write, discreet, &ctx, endpoint), }? } - Account::Import { private_key, write, discreet, network } => { + Account::Import { private_key, write, discreet, network, endpoint } => { // Parse the network. let network = NetworkName::try_from(network.as_str())?; match network { - NetworkName::MainnetV0 => import_account::(private_key, write, discreet, &ctx), - NetworkName::TestnetV0 => import_account::(private_key, write, discreet, &ctx), + NetworkName::MainnetV0 => import_account::(private_key, write, discreet, &ctx, endpoint), + NetworkName::TestnetV0 => import_account::(private_key, write, discreet, &ctx, endpoint), }? } - Self::Sign { message, seed, raw, private_key, private_key_file, network } => { + Self::Sign { message, seed, raw, private_key, private_key_file, network, endpoint: _ } => { // Parse the network. let network = NetworkName::try_from(network.as_str())?; let result = match network { @@ -147,7 +175,7 @@ impl Command for Account { }?; println!("{result}") } - Self::Verify { address, signature, message, raw, network } => { + Self::Verify { address, signature, message, raw, network, endpoint: _ } => { // Parse the network. let network = NetworkName::try_from(network.as_str())?; let result = match network { @@ -164,7 +192,13 @@ impl Command for Account { // Helper functions // Generate a new account. -fn generate_new_account(seed: Option, write: bool, discreet: bool, ctx: &Context) -> Result<()> { +fn generate_new_account( + seed: Option, + write: bool, + discreet: bool, + ctx: &Context, + endpoint: String, +) -> Result<()> { // Sample a new Aleo account. let private_key = match seed { // Recover the field element deterministically. @@ -179,13 +213,19 @@ fn generate_new_account(seed: Option, write: bool, discreet: bo // Save key data to .env file. if write { - write_to_env_file(private_key, ctx)?; + write_to_env_file(private_key, ctx, endpoint)?; } Ok(()) } // Import an account. -fn import_account(private_key: Option, write: bool, discreet: bool, ctx: &Context) -> Result<()> { +fn import_account( + private_key: Option, + write: bool, + discreet: bool, + ctx: &Context, + endpoint: String, +) -> Result<()> { let priv_key = match discreet { true => { let private_key_input = rpassword::prompt_password("Please enter your private key: ").unwrap(); @@ -207,7 +247,7 @@ fn import_account(private_key: Option, write: bool, discreet // Save key data to .env file. if write { - write_to_env_file::(priv_key, ctx)?; + write_to_env_file::(priv_key, ctx, endpoint)?; } Ok(()) @@ -323,9 +363,9 @@ pub(crate) fn verify_message( } // Write the network and private key to the .env file in project directory. -fn write_to_env_file(private_key: PrivateKey, ctx: &Context) -> Result<()> { +fn write_to_env_file(private_key: PrivateKey, ctx: &Context, endpoint: String) -> Result<()> { let program_dir = ctx.dir()?; - Env::::from(private_key).write_to(&program_dir)?; + Env::::new(Some(private_key), endpoint)?.write_to(&program_dir)?; tracing::info!("✅ Private Key written to {}", program_dir.join(".env").display()); Ok(()) } diff --git a/leo/cli/commands/example.rs b/leo/cli/commands/example.rs index 3c759fe077..44863c4c98 100644 --- a/leo/cli/commands/example.rs +++ b/leo/cli/commands/example.rs @@ -25,6 +25,13 @@ pub struct Example { pub(crate) name: String, #[clap(short = 'n', long, help = "Name of the network to use", default_value = "mainnet")] pub(crate) network: String, + #[clap( + short = 'e', + long, + help = "Endpoint to retrieve network state from.", + default_value = "https://api.explorer.aleo.org/v1" + )] + pub(crate) endpoint: String, } impl Command for Example { @@ -33,7 +40,8 @@ impl Command for Example { fn prelude(&self, context: Context) -> Result { // Run leo new --network - (New { name: self.name.clone(), network: self.network.clone() }).execute(context) + (New { name: self.name.clone(), network: self.network.clone(), endpoint: self.endpoint.clone() }) + .execute(context) } fn apply(self, context: Context, _: Self::Input) -> Result diff --git a/leo/cli/commands/new.rs b/leo/cli/commands/new.rs index 6b494bc2c4..56f7f821fa 100644 --- a/leo/cli/commands/new.rs +++ b/leo/cli/commands/new.rs @@ -26,6 +26,13 @@ pub struct New { pub(crate) name: String, #[clap(short = 'n', long, help = "Name of the network to use", default_value = "mainnet")] pub(crate) network: String, + #[clap( + short = 'e', + long, + help = "Endpoint to retrieve network state from.", + default_value = "https://api.explorer.aleo.org/v1" + )] + pub(crate) endpoint: String, } impl Command for New { @@ -53,8 +60,8 @@ impl Command for New { // Initialize the package. match network { - NetworkName::MainnetV0 => Package::initialize::(&self.name, &package_path), - NetworkName::TestnetV0 => Package::initialize::(&self.name, &package_path), + NetworkName::MainnetV0 => Package::initialize::(&self.name, &package_path, self.endpoint), + NetworkName::TestnetV0 => Package::initialize::(&self.name, &package_path, self.endpoint), }?; Ok(()) diff --git a/leo/package/src/package.rs b/leo/package/src/package.rs index abc6aad9d5..0f813fdc8d 100644 --- a/leo/package/src/package.rs +++ b/leo/package/src/package.rs @@ -125,7 +125,7 @@ impl Package { } /// Creates a Leo package at the given path - pub fn initialize(package_name: &str, path: &Path) -> Result<()> { + pub fn initialize(package_name: &str, path: &Path, endpoint: String) -> Result<()> { // Construct the path to the package directory. let path = path.join(package_name); @@ -147,7 +147,7 @@ impl Package { Gitignore::new().write_to(&path)?; // Create the .env file. - Env::::new()?.write_to(&path)?; + Env::::new(None, endpoint)?.write_to(&path)?; // Create a manifest. let manifest = Manifest::default(package_name); diff --git a/leo/package/src/root/env.rs b/leo/package/src/root/env.rs index f909d6270d..91201e0619 100644 --- a/leo/package/src/root/env.rs +++ b/leo/package/src/root/env.rs @@ -30,17 +30,21 @@ pub static ENV_FILENAME: &str = ".env"; pub struct Env { #[serde(bound(deserialize = ""))] private_key: PrivateKey, + endpoint: String, } impl Env { - pub fn new() -> Result { + pub fn new(private_key: Option>, endpoint: String) -> Result { // Initialize an RNG. let rng = &mut rand::thread_rng(); // Generate a development private key. - let private_key = PrivateKey::::new(rng)?; + let private_key = match private_key { + Some(private_key) => private_key, + None => PrivateKey::::new(rng)?, + }; - Ok(Self { private_key }) + Ok(Self { private_key, endpoint }) } pub fn exists_at(path: &Path) -> bool { @@ -63,12 +67,6 @@ impl Env { } } -impl From> for Env { - fn from(private_key: PrivateKey) -> Self { - Self { private_key } - } -} - impl ToString for Env { fn to_string(&self) -> String { // Get the network name. @@ -78,6 +76,6 @@ impl ToString for Env { _ => unimplemented!("Unsupported network"), }; // Return the formatted string. - format!("NETWORK={network}\nPRIVATE_KEY={}\n", self.private_key) + format!("NETWORK={network}\nPRIVATE_KEY={}\nENDPOINT={}\n", self.private_key, self.endpoint) } } From b79c0a1ab64c7bb0917c2bc269b9042fa5ef3435 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:45:57 -0700 Subject: [PATCH 02/20] require confirmation for execution/deployment unless -y or --yes present --- Cargo.lock | 21 +++++++++++++++++++++ Cargo.toml | 1 + leo/cli/commands/deploy.rs | 23 ++++++++++++++++++++--- leo/cli/commands/execute.rs | 25 +++++++++++++++++++++---- leo/cli/commands/mod.rs | 10 ++++++---- leo/package/Cargo.toml | 3 +++ 6 files changed, 72 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d6aedbda84..47133183d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -742,6 +742,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "dialoguer" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de" +dependencies = [ + "console", + "shell-words", + "tempfile", + "thiserror", + "zeroize", +] + [[package]] name = "difflib" version = "0.4.0" @@ -1544,6 +1557,7 @@ dependencies = [ "colored", "console", "crossterm", + "dialoguer", "dirs 5.0.1", "dotenvy", "indexmap 1.9.3", @@ -1582,6 +1596,7 @@ name = "leo-package" version = "1.12.0" dependencies = [ "aleo-std", + "dialoguer", "indexmap 1.9.3", "lazy_static", "leo-errors", @@ -2740,6 +2755,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + [[package]] name = "signal-hook" version = "0.3.17" diff --git a/Cargo.toml b/Cargo.toml index 08e094dd42..4548c75f49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,7 @@ ci_skip = [ "leo-compiler/ci_skip" ] noconfig = [ ] [dependencies] +dialoguer = "0.11.0" num-format = "0.4.4" text-tables = "0.3.1" ureq = "2.9.7" diff --git a/leo/cli/commands/deploy.rs b/leo/cli/commands/deploy.rs index 40d7399f0c..b28923bcae 100644 --- a/leo/cli/commands/deploy.rs +++ b/leo/cli/commands/deploy.rs @@ -16,6 +16,7 @@ use super::*; use aleo_std::StorageMode; +use dialoguer::{theme::ColorfulTheme, Confirm}; use leo_retriever::NetworkName; use snarkvm::{ circuit::{Aleo, AleoTestnetV0, AleoV0}, @@ -94,6 +95,7 @@ fn handle_deploy, N: Network>( &dotenv_private_key().map_err(CliError::failed_to_read_environment_private_key)?.to_string(), )?, }; + let address = Address::try_from(&private_key)?; // Specify the query let query = SnarkVMQuery::from(&command.options.endpoint); @@ -185,7 +187,22 @@ fn handle_deploy, N: Network>( // Determine if the transaction should be broadcast, stored, or displayed to the user. if !command.fee_options.dry_run { - println!("✅ Created deployment transaction for '{}'", name.bold()); + if !command.fee_options.yes { + let prompt = format!( + "Do you want to submit deployment of program `{name}.aleo` to network {} via endpoint {} using address {}?", + command.options.network, command.options.endpoint, address + ); + let confirmation = Confirm::with_theme(&ColorfulTheme::default()) + .with_prompt(prompt) + .default(false) + .interact() + .unwrap(); + if !confirmation { + println!("✅ Successfully aborted the execution transaction for '{}'\n", name.bold()); + return Ok(()); + } + } + println!("✅ Created deployment transaction for '{}'\n", name.bold()); handle_broadcast( &format!("{}/{}/transaction/broadcast", command.options.endpoint, command.options.network), transaction, @@ -196,7 +213,7 @@ fn handle_deploy, N: Network>( std::thread::sleep(std::time::Duration::from_secs(command.wait)); } } else { - println!("✅ Successful dry run deployment for '{}'", name.bold()); + println!("✅ Successful dry run deployment for '{}'\n", name.bold()); } } @@ -212,7 +229,7 @@ fn deploy_cost_breakdown( namespace_cost: f64, priority_fee: f64, ) { - println!("Base deployment cost for '{}' is {} credits.", name.bold(), total_cost); + println!("\nBase deployment cost for '{}' is {} credits.\n", name.bold(), total_cost); // Display the cost breakdown in a table. let data = [ [name, "Cost (credits)"], diff --git a/leo/cli/commands/execute.rs b/leo/cli/commands/execute.rs index acbe198716..f7225bdcbe 100644 --- a/leo/cli/commands/execute.rs +++ b/leo/cli/commands/execute.rs @@ -24,6 +24,7 @@ use snarkvm::{ use std::collections::HashMap; use crate::cli::query::QueryCommands; +use dialoguer::{theme::ColorfulTheme, Confirm}; use leo_retriever::NetworkName; use snarkvm::{ circuit::{Aleo, AleoTestnetV0, AleoV0}, @@ -133,6 +134,7 @@ fn handle_execute(command: Execute, context: Context) -> Result<(command: Execute, context: Context) -> Result<(command: Execute, context: Context) -> Result<(command: Execute, context: Context) -> Result<( // A helper function to display a cost breakdown of the execution. fn execution_cost_breakdown(name: &String, total_cost: f64, storage_cost: f64, finalize_cost: f64, priority_fee: f64) { - println!("Base execution cost for '{}' is {} credits.", name.bold(), total_cost); + println!("\nBase execution cost for '{}' is {} credits.\n", name.bold(), total_cost); // Display the cost breakdown in a table. let data = [ [name, "Cost (credits)"], diff --git a/leo/cli/commands/mod.rs b/leo/cli/commands/mod.rs index 99fd2a46d0..cf4c63b3fe 100644 --- a/leo/cli/commands/mod.rs +++ b/leo/cli/commands/mod.rs @@ -210,6 +210,8 @@ impl Default for BuildOptions { /// Used by Execute and Deploy commands. #[derive(Parser, Clone, Debug, Default)] pub struct FeeOptions { + #[clap(short, long, help = "Don't ask for confirmation.", default_value = "false")] + pub(crate) yes: bool, #[clap(short, long, help = "Performs a dry-run of transaction generation")] pub(crate) dry_run: bool, #[clap(long, help = "Priority fee in microcredits. Defaults to 0.", default_value = "0")] @@ -273,7 +275,7 @@ fn check_balance( /// Determine if the transaction should be broadcast or displayed to user. fn handle_broadcast(endpoint: &String, transaction: Transaction, operation: &String) -> Result<()> { - println!("Broadcasting transaction to {}...", endpoint.clone()); + println!("Broadcasting transaction to {}...\n", endpoint.clone()); // Get the transaction id. let transaction_id = transaction.id(); @@ -287,20 +289,20 @@ fn handle_broadcast(endpoint: &String, transaction: Transaction, match transaction { Transaction::Deploy(..) => { println!( - "⌛ Deployment {transaction_id} ('{}') has been broadcast to {}.", + "⌛ Deployment {transaction_id} ('{}') has been broadcast to {}.\n", operation.bold(), endpoint ) } Transaction::Execute(..) => { println!( - "⌛ Execution {transaction_id} ('{}') has been broadcast to {}.", + "⌛ Execution {transaction_id} ('{}') has been broadcast to {}.\n", operation.bold(), endpoint ) } Transaction::Fee(..) => { - println!("❌ Failed to broadcast fee '{}' to the {}.", operation.bold(), endpoint) + println!("❌ Failed to broadcast fee '{}' to the {}.\n", operation.bold(), endpoint) } } Ok(()) diff --git a/leo/package/Cargo.toml b/leo/package/Cargo.toml index ed2c7a6299..340ac49352 100644 --- a/leo/package/Cargo.toml +++ b/leo/package/Cargo.toml @@ -37,6 +37,9 @@ default-features = false version = "1.9" features = [ "serde" ] +[dependencies.dialoguer] +version = "0.11.0" + [dependencies.num-format] version = "0.4.4" From 2f3265782824ef859857f1f045ea60c38a629062 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:31:22 -0700 Subject: [PATCH 03/20] use `.env` for network, sk, endpoint (can override with CLI flag) --- compiler/compiler/tests/utilities/mod.rs | 11 +--- errors/src/errors/cli/cli_errors.rs | 21 ++++++++ errors/src/errors/mod.rs | 4 +- leo/cli/commands/build.rs | 4 +- leo/cli/commands/deploy.rs | 26 +++++---- leo/cli/commands/execute.rs | 31 ++++++----- leo/cli/commands/mod.rs | 18 +++---- leo/cli/commands/query/mod.rs | 24 ++++----- leo/cli/commands/run.rs | 2 +- leo/cli/helpers/context.rs | 53 ++++++++++++++++++- leo/package/src/package.rs | 8 +-- .../src/program_context/network_name.rs | 13 +++++ 12 files changed, 146 insertions(+), 69 deletions(-) diff --git a/compiler/compiler/tests/utilities/mod.rs b/compiler/compiler/tests/utilities/mod.rs index 053fc93f39..0f84c06ce7 100644 --- a/compiler/compiler/tests/utilities/mod.rs +++ b/compiler/compiler/tests/utilities/mod.rs @@ -285,13 +285,4 @@ pub fn compile_and_process<'a>(parsed: &'a mut Compiler<'a, CurrentNetwork>) -> Ok(bytecode) } -/// Returns the private key from the .env file specified in the directory. -#[allow(unused)] -pub fn dotenv_private_key(directory: &Path) -> Result> { - use std::str::FromStr; - dotenvy::from_path(directory.join(".env")).map_err(|_| anyhow!("Missing a '.env' file in the test directory."))?; - // Load the private key from the environment. - let private_key = dotenvy::var("PRIVATE_KEY").map_err(|e| anyhow!("Missing PRIVATE_KEY - {e}"))?; - // Parse the private key. - PrivateKey::::from_str(&private_key) -} + diff --git a/errors/src/errors/cli/cli_errors.rs b/errors/src/errors/cli/cli_errors.rs index 15f9308394..d380de040c 100644 --- a/errors/src/errors/cli/cli_errors.rs +++ b/errors/src/errors/cli/cli_errors.rs @@ -264,4 +264,25 @@ create_messages!( msg: format!("{error}"), help: None, } + + @backtraced + failed_to_get_endpoint_from_env { + args: (command: impl Display), + msg: "Failed to get an endpoint.".to_string(), + help: Some(format!("Either make sure you have a `.env` file in current project directory with an `ENDPOINT` variable set, or set the `--endpoint` flag when invoking the CLI command.\n Example: `ENDPOINT=https://api.explorer.aleo.org/v1` or `leo {command} --endpoint \"https://api.explorer.aleo.org/v1\"`.")), + } + + @backtraced + failed_to_get_private_key_from_env { + args: (command: impl Display), + msg: "Failed to get a private key.".to_string(), + help: Some(format!("Either make sure you have a `.env` file in current project directory with a `PRIVATE_KEY` variable set, or set the `--private-key` flag when invoking the CLI command.\n Example: `PRIVATE_KEY=0x1234...` or `leo {command} --private-key \"APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH\"`.")), + } + + @backtraced + failed_to_get_network_from_env { + args: (command: impl Display), + msg: "Failed to get a network.".to_string(), + help: Some(format!("Either make sure you have a `.env` file in current project directory with a `NETWORK` variable set, or set the `--network` flag when invoking the CLI command.\n Example: `NETWORK=testnet` or `leo {command} --network testnet`.")), + } ); diff --git a/errors/src/errors/mod.rs b/errors/src/errors/mod.rs index bbebd974a7..f52f608696 100644 --- a/errors/src/errors/mod.rs +++ b/errors/src/errors/mod.rs @@ -109,7 +109,7 @@ impl LeoError { FlattenError(error) => error.error_code(), UtilError(error) => error.error_code(), LastErrorCode(_) => unreachable!(), - Anyhow(_) => unimplemented!(), // todo: implement error codes for snarkvm errors. + Anyhow(_) => "SnarkVM Error".to_string(), // todo: implement error codes for snarkvm errors. } } @@ -128,7 +128,7 @@ impl LeoError { FlattenError(error) => error.exit_code(), UtilError(error) => error.exit_code(), LastErrorCode(code) => *code, - Anyhow(_) => unimplemented!(), // todo: implement exit codes for snarkvm errors. + Anyhow(_) => 11000, // todo: implement exit codes for snarkvm errors. } } } diff --git a/leo/cli/commands/build.rs b/leo/cli/commands/build.rs index 1999df9f79..79b581fc7e 100644 --- a/leo/cli/commands/build.rs +++ b/leo/cli/commands/build.rs @@ -93,7 +93,7 @@ impl Command for Build { fn apply(self, context: Context, _: Self::Input) -> Result { // Parse the network. - let network = NetworkName::try_from(self.options.network.as_str())?; + let network = NetworkName::try_from(context.get_network(&self.options.network, "build")?)?; match network { NetworkName::MainnetV0 => handle_build::(&self, context), NetworkName::TestnetV0 => handle_build::(&self, context), @@ -123,7 +123,7 @@ fn handle_build(command: &Build, context: Context) -> Result<::new(main_sym, &package_path, &home_path, command.options.endpoint.clone()) + let mut retriever = Retriever::::new(main_sym, &package_path, &home_path, context.get_endpoint(&command.options.endpoint, "build")?.to_string()) .map_err(|err| UtilError::failed_to_retrieve_dependencies(err, Default::default()))?; let mut local_dependencies = retriever.retrieve().map_err(|err| UtilError::failed_to_retrieve_dependencies(err, Default::default()))?; diff --git a/leo/cli/commands/deploy.rs b/leo/cli/commands/deploy.rs index b28923bcae..11ff4d86f2 100644 --- a/leo/cli/commands/deploy.rs +++ b/leo/cli/commands/deploy.rs @@ -72,10 +72,11 @@ impl Command for Deploy { fn apply(self, context: Context, _: Self::Input) -> Result { // Parse the network. - let network = NetworkName::try_from(self.options.network.as_str())?; + let network = NetworkName::try_from(context.get_network(&self.options.network, "deploy")?)?; + let endpoint = context.get_endpoint(&self.options.endpoint, "deploy")?; match network { - NetworkName::MainnetV0 => handle_deploy::(&self, context), - NetworkName::TestnetV0 => handle_deploy::(&self, context), + NetworkName::MainnetV0 => handle_deploy::(&self, context, network, &endpoint), + NetworkName::TestnetV0 => handle_deploy::(&self, context, network, &endpoint), } } } @@ -84,21 +85,18 @@ impl Command for Deploy { fn handle_deploy, N: Network>( command: &Deploy, context: Context, + network: NetworkName, + endpoint: &str, ) -> Result<::Output> { // Get the program name. let project_name = context.open_manifest::()?.program_id().to_string(); // Get the private key. - let private_key = match &command.fee_options.private_key { - Some(key) => PrivateKey::from_str(key)?, - None => PrivateKey::from_str( - &dotenv_private_key().map_err(CliError::failed_to_read_environment_private_key)?.to_string(), - )?, - }; + let private_key = context.get_private_key(&command.fee_options.private_key, "deploy")?; let address = Address::try_from(&private_key)?; // Specify the query - let query = SnarkVMQuery::from(&command.options.endpoint); + let query = SnarkVMQuery::from(endpoint); let mut all_paths: Vec<(String, PathBuf)> = Vec::new(); @@ -164,8 +162,8 @@ fn handle_deploy, N: Network>( // Make sure the user has enough public balance to pay for the deployment. check_balance( &private_key, - &command.options.endpoint, - &command.options.network, + &endpoint, + &network.to_string(), context.clone(), total_cost, )?; @@ -190,7 +188,7 @@ fn handle_deploy, N: Network>( if !command.fee_options.yes { let prompt = format!( "Do you want to submit deployment of program `{name}.aleo` to network {} via endpoint {} using address {}?", - command.options.network, command.options.endpoint, address + network, endpoint, address ); let confirmation = Confirm::with_theme(&ColorfulTheme::default()) .with_prompt(prompt) @@ -204,7 +202,7 @@ fn handle_deploy, N: Network>( } println!("✅ Created deployment transaction for '{}'\n", name.bold()); handle_broadcast( - &format!("{}/{}/transaction/broadcast", command.options.endpoint, command.options.network), + &format!("{}/{}/transaction/broadcast", endpoint, network), transaction, name, )?; diff --git a/leo/cli/commands/execute.rs b/leo/cli/commands/execute.rs index f7225bdcbe..8e5caf47ed 100644 --- a/leo/cli/commands/execute.rs +++ b/leo/cli/commands/execute.rs @@ -87,16 +87,17 @@ impl Command for Execute { fn apply(self, context: Context, _input: Self::Input) -> Result { // Parse the network. - let network = NetworkName::try_from(self.compiler_options.network.as_str())?; + let network = NetworkName::try_from(context.get_network(&self.compiler_options.network, "deploy")?)?; + let endpoint = context.get_endpoint(&self.compiler_options.endpoint, "deploy")?; match network { - NetworkName::MainnetV0 => handle_execute::(self, context), - NetworkName::TestnetV0 => handle_execute::(self, context), + NetworkName::MainnetV0 => handle_execute::(self, context, network, &endpoint), + NetworkName::TestnetV0 => handle_execute::(self, context, network, &endpoint), } } } // A helper function to handle the `execute` command. -fn handle_execute(command: Execute, context: Context) -> Result<::Output> { +fn handle_execute(command: Execute, context: Context, network: NetworkName, endpoint: &str) -> Result<::Output> { // If input values are provided, then run the program with those inputs. // Otherwise, use the input file. let mut inputs = command.inputs.clone(); @@ -156,7 +157,7 @@ fn handle_execute(command: Execute, context: Context) -> Result<>::from(command.compiler_options.endpoint.clone()); + SnarkVMQuery::>::from(endpoint); // Initialize the storage. let store = ConsensusStore::>::open(StorageMode::Production)?; @@ -167,7 +168,7 @@ fn handle_execute(command: Execute, context: Context) -> Result<::from_str(&format!("{}.aleo", program_name))?; // TODO: X - load_program_from_network(&command, context.clone(), &mut vm.process().write(), program_id)?; + load_program_from_network(&command, context.clone(), &mut vm.process().write(), program_id, network, endpoint)?; let fee_record = if let Some(record) = command.fee_options.record { Some(parse_record(&private_key, &record)?) @@ -208,8 +209,8 @@ fn handle_execute(command: Execute, context: Context) -> Result<( &private_key, - &command.compiler_options.endpoint, - &command.compiler_options.network, + endpoint, + &network.to_string(), context, total_cost, )?; @@ -220,7 +221,7 @@ fn handle_execute(command: Execute, context: Context) -> Result<(command: Execute, context: Context) -> Result<(command: Execute, context: Context) -> Result<( - command.compiler_options.endpoint.clone(), + endpoint.to_string(), &private_key, Identifier::try_from(command.name.clone())?, &inputs, @@ -339,11 +340,13 @@ fn load_program_from_network( context: Context, process: &mut Process, program_id: &ProgramID, + network: NetworkName, + endpoint: &str, ) -> Result<()> { // Fetch the program. let program_src = Query { - endpoint: command.compiler_options.endpoint.clone(), - network: command.compiler_options.network.clone(), + endpoint: Some(endpoint.to_string()), + network: Some(network.to_string()), command: QueryCommands::Program { command: crate::cli::commands::query::Program { name: program_id.to_string(), @@ -365,7 +368,7 @@ fn load_program_from_network( // Add the imports to the process if does not exist yet. if !process.contains_program(import_program_id) { // Recursively load the program and its imports. - load_program_from_network(command, context.clone(), process, import_program_id)?; + load_program_from_network(command, context.clone(), process, import_program_id, network, endpoint)?; } } diff --git a/leo/cli/commands/mod.rs b/leo/cli/commands/mod.rs index cf4c63b3fe..b8e90e5531 100644 --- a/leo/cli/commands/mod.rs +++ b/leo/cli/commands/mod.rs @@ -135,12 +135,10 @@ pub trait Command { pub struct BuildOptions { #[clap( long, - help = "Endpoint to retrieve network state from.", - default_value = "https://api.explorer.aleo.org/v1" - )] - pub endpoint: String, - #[clap(long, help = "Network to broadcast to. Defaults to mainnet.", default_value = "mainnet")] - pub(crate) network: String, + help = "Endpoint to retrieve network state from. Overrides setting in `.env`.")] + pub endpoint: Option, + #[clap(long, help = "Network to broadcast to. Overrides setting in `.env`.")] + pub(crate) network: Option, #[clap(long, help = "Does not recursively compile dependencies.")] pub non_recursive: bool, #[clap(long, help = "Enables offline mode.")] @@ -182,8 +180,8 @@ pub struct BuildOptions { impl Default for BuildOptions { fn default() -> Self { Self { - endpoint: "http://api.explorer.aleo.org/v1".to_string(), - network: "mainnet".to_string(), + endpoint: None, + network:None, non_recursive: false, offline: false, enable_symbol_table_spans: false, @@ -252,8 +250,8 @@ fn check_balance( let address = Address::::try_from(ViewKey::try_from(private_key)?)?; // Query the public balance of the address on the `account` mapping from `credits.aleo`. let mut public_balance = Query { - endpoint: endpoint.to_string(), - network: network.to_string(), + endpoint: Some(endpoint.to_string()), + network: Some(network.to_string()), command: QueryCommands::Program { command: crate::cli::commands::query::Program { name: "credits".to_string(), diff --git a/leo/cli/commands/query/mod.rs b/leo/cli/commands/query/mod.rs index b50ac2e88e..8de80b5fe5 100644 --- a/leo/cli/commands/query/mod.rs +++ b/leo/cli/commands/query/mod.rs @@ -51,12 +51,11 @@ pub struct Query { short, long, global = true, - help = "Endpoint to retrieve network state from. Defaults to https://api.explorer.aleo.org/v1.", - default_value = "https://api.explorer.aleo.org/v1" + help = "Endpoint to retrieve network state from. Defaults to entry in `.env`.", )] - pub endpoint: String, - #[clap(short, long, global = true, help = "Network to use. Defaults to mainnet.", default_value = "mainnet")] - pub(crate) network: String, + pub endpoint: Option, + #[clap(short, long, global = true, help = "Network to use. Defaults to entry in `.env`.")] + pub(crate) network: Option, #[clap(subcommand)] pub command: QueryCommands, } @@ -75,16 +74,17 @@ impl Command for Query { fn apply(self, context: Context, _: Self::Input) -> Result { // Parse the network. - let network = NetworkName::try_from(self.network.as_str())?; + let network = NetworkName::try_from(context.get_network(&self.network, "query")?)?; + let endpoint = context.get_endpoint(&self.endpoint, "query")?; match network { - NetworkName::MainnetV0 => handle_query::(self, context), - NetworkName::TestnetV0 => handle_query::(self, context), + NetworkName::MainnetV0 => handle_query::(self, context, &network.to_string(), &endpoint), + NetworkName::TestnetV0 => handle_query::(self, context, &network.to_string(), &endpoint), } } } // A helper function to handle the `query` command. -fn handle_query(query: Query, context: Context) -> Result<::Output> { +fn handle_query(query: Query, context: Context, network: &str, endpoint: &str) -> Result<::Output> { let recursive = context.recursive; let (program, output) = match query.command { QueryCommands::Block { command } => (None, command.apply(context, ())?), @@ -98,7 +98,7 @@ fn handle_query(query: Query, context: Context) -> Result< (None, command.apply(context, ())?), QueryCommands::Committee { command } => (None, command.apply(context, ())?), QueryCommands::Mempool { command } => { - if query.endpoint == "https://api.explorer.aleo.org/v1" { + if endpoint == "https://api.explorer.aleo.org/v1" { tracing::warn!( "⚠️ `leo query mempool` is only valid when using a custom endpoint. Specify one using `--endpoint`." ); @@ -106,7 +106,7 @@ fn handle_query(query: Query, context: Context) -> Result< { - if query.endpoint == "https://api.explorer.aleo.org/v1" { + if endpoint == "https://api.explorer.aleo.org/v1" { tracing::warn!( "⚠️ `leo query peers` is only valid when using a custom endpoint. Specify one using `--endpoint`." ); @@ -116,7 +116,7 @@ fn handle_query(query: Query, context: Context) -> Result< Result { // Parse the network. - let network = NetworkName::try_from(self.compiler_options.network.as_str())?; + let network = NetworkName::try_from(context.get_network(&self.compiler_options.network, "run")?)?; match network { NetworkName::MainnetV0 => handle_run::(self, context), NetworkName::TestnetV0 => handle_run::(self, context), diff --git a/leo/cli/helpers/context.rs b/leo/cli/helpers/context.rs index ca1cbdde3e..03e6188277 100644 --- a/leo/cli/helpers/context.rs +++ b/leo/cli/helpers/context.rs @@ -23,13 +23,14 @@ use snarkvm::file::Manifest; use aleo_std::aleo_dir; use indexmap::IndexMap; -use snarkvm::prelude::Network; +use snarkvm::prelude::{anyhow, Itertools, Network, PrivateKey}; use std::{ env::current_dir, fs::File, io::Write, path::{Path, PathBuf}, }; +use std::str::FromStr; /// Project context, manifest, current directory etc /// All the info that is relevant in most of the commands @@ -140,4 +141,54 @@ impl Context { Ok(list) } + + /// Returns the private key from the .env file specified in the directory. + pub fn dotenv_private_key(&self, command: &str) -> Result> { + dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_private_key_from_env(command))?; + // Load the private key from the environment. + let private_key = dotenvy::var("PRIVATE_KEY").map_err(|_| CliError::failed_to_get_private_key_from_env(command))?; + // Parse the private key. + Ok(PrivateKey::::from_str(&private_key)?) + } + + /// Returns the endpoint from the .env file specified in the directory. + pub fn dotenv_endpoint(&self, command: &str) -> Result { + dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_endpoint_from_env(command))?; + // Load the endpoint from the environment. + Ok(dotenvy::var("ENDPOINT").map_err(|_| CliError::failed_to_get_endpoint_from_env(command))?) + } + + /// Returns the network from the .env file specified in the directory. + pub fn dotenv_network(&self, command: &str) -> Result { + dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_network_from_env(command))?; + // Load the network from the environment. + Ok(dotenvy::var("NETWORK").map_err(|_| CliError::failed_to_get_network_from_env(command))?) + } + + /// Returns the endpoint to interact with the network. + /// If the `--endpoint` options is not provided, it will default to the one in the `.env` file. + pub fn get_endpoint(&self, endpoint: &Option, command: &str) -> Result { + match endpoint { + Some(endpoint) => Ok(endpoint.clone()), + None => Ok(self.dotenv_endpoint(command)?), + } + } + + /// Returns the network name. + /// If the `--network` options is not provided, it will default to the one in the `.env` file. + pub fn get_network(&self, network: &Option, command: &str) -> Result { + match network { + Some(network) => Ok(network.clone()), + None => Ok(self.dotenv_network(command)?), + } + } + + /// Returns the private key. + /// If the `--private-key` options is not provided, it will default to the one in the `.env` file. + pub fn get_private_key(&self, private_key: &Option, command: &str) -> Result> { + match private_key { + Some(private_key) => Ok(PrivateKey::::from_str(&private_key)?), + None => self.dotenv_private_key(command), + } + } } diff --git a/leo/package/src/package.rs b/leo/package/src/package.rs index 0f813fdc8d..4538544508 100644 --- a/leo/package/src/package.rs +++ b/leo/package/src/package.rs @@ -22,8 +22,9 @@ use leo_errors::{PackageError, Result}; use leo_retriever::{Manifest, NetworkName}; use serde::Deserialize; -use snarkvm::prelude::Network; +use snarkvm::prelude::{Network, PrivateKey}; use std::path::Path; +use std::str::FromStr; #[derive(Deserialize)] pub struct Package { @@ -146,8 +147,9 @@ impl Package { // Create the .gitignore file. Gitignore::new().write_to(&path)?; - // Create the .env file. - Env::::new(None, endpoint)?.write_to(&path)?; + // Create the .env file. + // Include the private key of validator 0 for ease of use with local devnets, as it will automatically be seeded with funds. + Env::::new(Some(PrivateKey::::from_str("APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH")?), endpoint)?.write_to(&path)?; // Create a manifest. let manifest = Manifest::default(package_name); diff --git a/utils/retriever/src/program_context/network_name.rs b/utils/retriever/src/program_context/network_name.rs index 9708581e5e..660aaac3c3 100644 --- a/utils/retriever/src/program_context/network_name.rs +++ b/utils/retriever/src/program_context/network_name.rs @@ -48,6 +48,19 @@ impl TryFrom<&str> for NetworkName { } } } +impl TryFrom for NetworkName { + type Error = LeoError; + + fn try_from(network: String) -> Result { + if network == "testnet" { + Ok(NetworkName::TestnetV0) + } else if network == "mainnet" { + Ok(NetworkName::MainnetV0) + } else { + Err(LeoError::CliError(CliError::invalid_network_name(&network))) + } + } +} impl fmt::Display for NetworkName { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { From acb8f46655d1706095b8193aa15d171c208f198e Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:03:45 -0700 Subject: [PATCH 04/20] error if constraint / variable limit is exceeded for deployment on current network --- errors/src/errors/cli/cli_errors.rs | 14 ++++++++++++++ leo/cli/commands/deploy.rs | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/errors/src/errors/cli/cli_errors.rs b/errors/src/errors/cli/cli_errors.rs index d380de040c..2e604f29b1 100644 --- a/errors/src/errors/cli/cli_errors.rs +++ b/errors/src/errors/cli/cli_errors.rs @@ -285,4 +285,18 @@ create_messages!( msg: "Failed to get a network.".to_string(), help: Some(format!("Either make sure you have a `.env` file in current project directory with a `NETWORK` variable set, or set the `--network` flag when invoking the CLI command.\n Example: `NETWORK=testnet` or `leo {command} --network testnet`.")), } + + @backtraced + constraint_limit_exceeded { + args: (program: impl Display, limit: u64, network: impl Display), + msg: format!("Program `{program}` exceeds the constraint limit {limit} for deployment on network {network}."), + help: Some("Reduce the number of constraints in the program by reducing the number of instructions in transition functions.".to_string()), + } + + @backtraced + variable_limit_exceeded { + args: (program: impl Display, limit: u64, network: impl Display), + msg: format!("Program `{program}` exceeds the variable limit {limit} for deployment on network {network}."), + help: Some("Reduce the number of variables in the program by reducing the number of instructions in transition functions.".to_string()), + } ); diff --git a/leo/cli/commands/deploy.rs b/leo/cli/commands/deploy.rs index 11ff4d86f2..443f44b027 100644 --- a/leo/cli/commands/deploy.rs +++ b/leo/cli/commands/deploy.rs @@ -120,6 +120,15 @@ fn handle_deploy, N: Network>( // Generate the deployment let deployment = package.deploy::(None)?; + + // Check if the number of variables and constraints are within the limits. + if deployment.num_combined_variables()? > N::MAX_DEPLOYMENT_VARIABLES { + return Err(CliError::variable_limit_exceeded(name, N::MAX_DEPLOYMENT_VARIABLES, network).into()); + } + if deployment.num_combined_constraints()? > N::MAX_DEPLOYMENT_CONSTRAINTS { + return Err(CliError::constraint_limit_exceeded(name, N::MAX_DEPLOYMENT_CONSTRAINTS, network).into()); + } + let deployment_id = deployment.to_deployment_id()?; let store = ConsensusStore::>::open(StorageMode::Production)?; From 31aa70dab1acab9c7345dfe35826e4e3077fc0bf Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:03:57 -0700 Subject: [PATCH 05/20] display public balance --- leo/cli/commands/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/leo/cli/commands/mod.rs b/leo/cli/commands/mod.rs index b8e90e5531..c30c7cd9df 100644 --- a/leo/cli/commands/mod.rs +++ b/leo/cli/commands/mod.rs @@ -264,9 +264,11 @@ fn check_balance( // Remove the last 3 characters since they represent the `u64` suffix. public_balance.truncate(public_balance.len() - 3); // Compare balance. - if public_balance.parse::().unwrap() < total_cost { + let balance = public_balance.parse::().unwrap(); + if balance < total_cost { Err(PackageError::insufficient_balance(address, public_balance, total_cost).into()) } else { + println!("Your current public balance is {} credits.\n", balance as f64 / 1_000_000.0); Ok(()) } } From ecac53ef9401ae9e57bc7a2be078deef82170a3a Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:20:31 -0700 Subject: [PATCH 06/20] add canary + clippy --- Cargo.lock | 136 ++++++++++-------- Cargo.toml | 2 +- compiler/compiler/tests/utilities/mod.rs | 2 - errors/src/errors/cli/cli_errors.rs | 10 +- leo/cli/commands/account.rs | 6 + leo/cli/commands/build.rs | 10 +- leo/cli/commands/deploy.rs | 25 +--- leo/cli/commands/execute.rs | 36 ++--- leo/cli/commands/mod.rs | 8 +- leo/cli/commands/new.rs | 1 + leo/cli/commands/query/mod.rs | 15 +- leo/cli/commands/run.rs | 1 + leo/cli/helpers/context.rs | 22 +-- leo/package/src/package.rs | 11 +- .../src/program_context/network_name.rs | 9 +- 15 files changed, 157 insertions(+), 137 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 47133183d5..75c111b688 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -871,6 +871,26 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "enum-iterator" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c280b9e6b3ae19e152d8e31cf47f18389781e119d4013a2a2bb0180e5facc635" +dependencies = [ + "enum-iterator-derive", +] + +[[package]] +name = "enum-iterator-derive" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ab991c1362ac86c61ab6f556cff143daa22e5a15e4e189df818b2fd19fe65b" +dependencies = [ + "proc-macro2", + "quote 1.0.36", + "syn 2.0.66", +] + [[package]] name = "enum_index" version = "0.2.0" @@ -2831,7 +2851,7 @@ dependencies = [ [[package]] name = "snarkvm" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "anstyle", "anyhow", @@ -2860,7 +2880,7 @@ dependencies = [ [[package]] name = "snarkvm-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "aleo-std", "anyhow", @@ -2890,7 +2910,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-account", "snarkvm-circuit-algorithms", @@ -2904,7 +2924,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-account" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-network", @@ -2915,7 +2935,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-types", "snarkvm-console-algorithms", @@ -2925,7 +2945,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-collections" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-types", @@ -2935,7 +2955,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "indexmap 2.2.6", "itertools 0.11.0", @@ -2953,12 +2973,12 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment-witness" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" [[package]] name = "snarkvm-circuit-network" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-collections", @@ -2969,7 +2989,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "paste", "snarkvm-circuit-account", @@ -2984,7 +3004,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-address", @@ -2999,7 +3019,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-address" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3012,7 +3032,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-boolean" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-environment", "snarkvm-console-types-boolean", @@ -3021,7 +3041,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-field" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3031,7 +3051,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-group" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3043,7 +3063,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-integers" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3055,7 +3075,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-scalar" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3066,7 +3086,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-string" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3078,7 +3098,7 @@ dependencies = [ [[package]] name = "snarkvm-console" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-console-account", "snarkvm-console-algorithms", @@ -3091,7 +3111,7 @@ dependencies = [ [[package]] name = "snarkvm-console-account" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "bs58", "snarkvm-console-network", @@ -3102,7 +3122,7 @@ dependencies = [ [[package]] name = "snarkvm-console-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "blake2s_simd", "smallvec", @@ -3115,7 +3135,7 @@ dependencies = [ [[package]] name = "snarkvm-console-collections" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "aleo-std", "rayon", @@ -3126,7 +3146,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "anyhow", "indexmap 2.2.6", @@ -3149,7 +3169,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network-environment" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "anyhow", "bech32", @@ -3167,8 +3187,9 @@ dependencies = [ [[package]] name = "snarkvm-console-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ + "enum-iterator", "enum_index", "enum_index_derive", "indexmap 2.2.6", @@ -3188,7 +3209,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-address", @@ -3203,7 +3224,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-address" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3214,7 +3235,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-boolean" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-console-network-environment", ] @@ -3222,7 +3243,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-field" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3232,7 +3253,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-group" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3243,7 +3264,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-integers" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3254,7 +3275,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-scalar" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3265,7 +3286,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-string" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3276,7 +3297,7 @@ dependencies = [ [[package]] name = "snarkvm-curves" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "rand", "rayon", @@ -3290,7 +3311,7 @@ dependencies = [ [[package]] name = "snarkvm-fields" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "aleo-std", "anyhow", @@ -3307,7 +3328,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "aleo-std", "anyhow", @@ -3331,7 +3352,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-authority" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "anyhow", "rand", @@ -3343,7 +3364,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-block" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3362,7 +3383,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-committee" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3374,7 +3395,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-ledger-narwhal-batch-certificate", "snarkvm-ledger-narwhal-batch-header", @@ -3387,7 +3408,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-certificate" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3400,7 +3421,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-header" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3412,7 +3433,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-data" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "bytes", "serde_json", @@ -3423,7 +3444,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-subdag" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3438,7 +3459,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-transmission" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "bytes", "serde_json", @@ -3451,7 +3472,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-transmission-id" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "snarkvm-console", "snarkvm-ledger-puzzle", @@ -3460,7 +3481,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-puzzle" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "aleo-std", "anyhow", @@ -3480,7 +3501,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-puzzle-epoch" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "anyhow", "colored", @@ -3495,7 +3516,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-query" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "async-trait", "reqwest 0.11.27", @@ -3508,7 +3529,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-store" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "aleo-std-storage", "anyhow", @@ -3531,7 +3552,7 @@ dependencies = [ [[package]] name = "snarkvm-parameters" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "aleo-std", "anyhow", @@ -3556,7 +3577,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "aleo-std", "anyhow", @@ -3566,6 +3587,7 @@ dependencies = [ "parking_lot", "rand", "rayon", + "serde_json", "snarkvm-algorithms", "snarkvm-circuit", "snarkvm-console", @@ -3585,7 +3607,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-process" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "aleo-std", "colored", @@ -3608,7 +3630,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "indexmap 2.2.6", "paste", @@ -3622,7 +3644,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-snark" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "bincode", "once_cell", @@ -3635,7 +3657,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "aleo-std", "anyhow", @@ -3656,7 +3678,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities-derives" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=fddd8b9#fddd8b92b4c6417e37d62722b3b937534dc4fb26" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" dependencies = [ "proc-macro2", "quote 1.0.36", diff --git a/Cargo.toml b/Cargo.toml index 4548c75f49..2084287362 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ members = [ [workspace.dependencies.snarkvm] #version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "fddd8b9" +rev = "6d64025" [lib] path = "leo/lib.rs" diff --git a/compiler/compiler/tests/utilities/mod.rs b/compiler/compiler/tests/utilities/mod.rs index 0f84c06ce7..f0456cbc85 100644 --- a/compiler/compiler/tests/utilities/mod.rs +++ b/compiler/compiler/tests/utilities/mod.rs @@ -284,5 +284,3 @@ pub fn compile_and_process<'a>(parsed: &'a mut Compiler<'a, CurrentNetwork>) -> Ok(bytecode) } - - diff --git a/errors/src/errors/cli/cli_errors.rs b/errors/src/errors/cli/cli_errors.rs index 2e604f29b1..99c67120b1 100644 --- a/errors/src/errors/cli/cli_errors.rs +++ b/errors/src/errors/cli/cli_errors.rs @@ -264,35 +264,35 @@ create_messages!( msg: format!("{error}"), help: None, } - + @backtraced failed_to_get_endpoint_from_env { args: (command: impl Display), msg: "Failed to get an endpoint.".to_string(), help: Some(format!("Either make sure you have a `.env` file in current project directory with an `ENDPOINT` variable set, or set the `--endpoint` flag when invoking the CLI command.\n Example: `ENDPOINT=https://api.explorer.aleo.org/v1` or `leo {command} --endpoint \"https://api.explorer.aleo.org/v1\"`.")), } - + @backtraced failed_to_get_private_key_from_env { args: (command: impl Display), msg: "Failed to get a private key.".to_string(), help: Some(format!("Either make sure you have a `.env` file in current project directory with a `PRIVATE_KEY` variable set, or set the `--private-key` flag when invoking the CLI command.\n Example: `PRIVATE_KEY=0x1234...` or `leo {command} --private-key \"APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH\"`.")), } - + @backtraced failed_to_get_network_from_env { args: (command: impl Display), msg: "Failed to get a network.".to_string(), help: Some(format!("Either make sure you have a `.env` file in current project directory with a `NETWORK` variable set, or set the `--network` flag when invoking the CLI command.\n Example: `NETWORK=testnet` or `leo {command} --network testnet`.")), } - + @backtraced constraint_limit_exceeded { args: (program: impl Display, limit: u64, network: impl Display), msg: format!("Program `{program}` exceeds the constraint limit {limit} for deployment on network {network}."), help: Some("Reduce the number of constraints in the program by reducing the number of instructions in transition functions.".to_string()), } - + @backtraced variable_limit_exceeded { args: (program: impl Display, limit: u64, network: impl Display), diff --git a/leo/cli/commands/account.rs b/leo/cli/commands/account.rs index 4440fefc17..b94c99209c 100644 --- a/leo/cli/commands/account.rs +++ b/leo/cli/commands/account.rs @@ -152,6 +152,7 @@ impl Command for Account { match network { NetworkName::MainnetV0 => generate_new_account::(seed, write, discreet, &ctx, endpoint), NetworkName::TestnetV0 => generate_new_account::(seed, write, discreet, &ctx, endpoint), + NetworkName::CanaryV0 => generate_new_account::(seed, write, discreet, &ctx, endpoint), }? } Account::Import { private_key, write, discreet, network, endpoint } => { @@ -160,6 +161,7 @@ impl Command for Account { match network { NetworkName::MainnetV0 => import_account::(private_key, write, discreet, &ctx, endpoint), NetworkName::TestnetV0 => import_account::(private_key, write, discreet, &ctx, endpoint), + NetworkName::CanaryV0 => import_account::(private_key, write, discreet, &ctx, endpoint), }? } Self::Sign { message, seed, raw, private_key, private_key_file, network, endpoint: _ } => { @@ -172,6 +174,9 @@ impl Command for Account { NetworkName::TestnetV0 => { sign_message::(message, seed, raw, private_key, private_key_file) } + NetworkName::CanaryV0 => { + sign_message::(message, seed, raw, private_key, private_key_file) + } }?; println!("{result}") } @@ -181,6 +186,7 @@ impl Command for Account { let result = match network { NetworkName::MainnetV0 => verify_message::(address, signature, message, raw), NetworkName::TestnetV0 => verify_message::(address, signature, message, raw), + NetworkName::CanaryV0 => verify_message::(address, signature, message, raw), }?; println!("{result}") } diff --git a/leo/cli/commands/build.rs b/leo/cli/commands/build.rs index 79b581fc7e..d367777926 100644 --- a/leo/cli/commands/build.rs +++ b/leo/cli/commands/build.rs @@ -97,6 +97,7 @@ impl Command for Build { match network { NetworkName::MainnetV0 => handle_build::(&self, context), NetworkName::TestnetV0 => handle_build::(&self, context), + NetworkName::CanaryV0 => handle_build::(&self, context), } } } @@ -123,8 +124,13 @@ fn handle_build(command: &Build, context: Context) -> Result<::new(main_sym, &package_path, &home_path, context.get_endpoint(&command.options.endpoint, "build")?.to_string()) - .map_err(|err| UtilError::failed_to_retrieve_dependencies(err, Default::default()))?; + let mut retriever = Retriever::::new( + main_sym, + &package_path, + &home_path, + context.get_endpoint(&command.options.endpoint, "build")?.to_string(), + ) + .map_err(|err| UtilError::failed_to_retrieve_dependencies(err, Default::default()))?; let mut local_dependencies = retriever.retrieve().map_err(|err| UtilError::failed_to_retrieve_dependencies(err, Default::default()))?; diff --git a/leo/cli/commands/deploy.rs b/leo/cli/commands/deploy.rs index 443f44b027..b2a2a21056 100644 --- a/leo/cli/commands/deploy.rs +++ b/leo/cli/commands/deploy.rs @@ -20,20 +20,18 @@ use dialoguer::{theme::ColorfulTheme, Confirm}; use leo_retriever::NetworkName; use snarkvm::{ circuit::{Aleo, AleoTestnetV0, AleoV0}, - cli::helpers::dotenv_private_key, ledger::query::Query as SnarkVMQuery, package::Package as SnarkVMPackage, prelude::{ deployment_cost, store::{helpers::memory::ConsensusMemory, ConsensusStore}, MainnetV0, - PrivateKey, ProgramOwner, TestnetV0, VM, }, }; -use std::{path::PathBuf, str::FromStr}; +use std::path::PathBuf; use text_tables; /// Deploys an Aleo program. @@ -77,6 +75,7 @@ impl Command for Deploy { match network { NetworkName::MainnetV0 => handle_deploy::(&self, context, network, &endpoint), NetworkName::TestnetV0 => handle_deploy::(&self, context, network, &endpoint), + NetworkName::CanaryV0 => handle_deploy::(&self, context, network, &endpoint), } } } @@ -120,15 +119,15 @@ fn handle_deploy, N: Network>( // Generate the deployment let deployment = package.deploy::(None)?; - + // Check if the number of variables and constraints are within the limits. if deployment.num_combined_variables()? > N::MAX_DEPLOYMENT_VARIABLES { return Err(CliError::variable_limit_exceeded(name, N::MAX_DEPLOYMENT_VARIABLES, network).into()); - } + } if deployment.num_combined_constraints()? > N::MAX_DEPLOYMENT_CONSTRAINTS { return Err(CliError::constraint_limit_exceeded(name, N::MAX_DEPLOYMENT_CONSTRAINTS, network).into()); } - + let deployment_id = deployment.to_deployment_id()?; let store = ConsensusStore::>::open(StorageMode::Production)?; @@ -169,13 +168,7 @@ fn handle_deploy, N: Network>( } None => { // Make sure the user has enough public balance to pay for the deployment. - check_balance( - &private_key, - &endpoint, - &network.to_string(), - context.clone(), - total_cost, - )?; + check_balance(&private_key, endpoint, &network.to_string(), context.clone(), total_cost)?; let fee_authorization = vm.authorize_fee_public( &private_key, total_cost, @@ -210,11 +203,7 @@ fn handle_deploy, N: Network>( } } println!("✅ Created deployment transaction for '{}'\n", name.bold()); - handle_broadcast( - &format!("{}/{}/transaction/broadcast", endpoint, network), - transaction, - name, - )?; + handle_broadcast(&format!("{}/{}/transaction/broadcast", endpoint, network), transaction, name)?; // Wait between successive deployments to prevent out of order deployments. if index < all_paths.len() - 1 { std::thread::sleep(std::time::Duration::from_secs(command.wait)); diff --git a/leo/cli/commands/execute.rs b/leo/cli/commands/execute.rs index 8e5caf47ed..50dcfac2ae 100644 --- a/leo/cli/commands/execute.rs +++ b/leo/cli/commands/execute.rs @@ -92,12 +92,18 @@ impl Command for Execute { match network { NetworkName::MainnetV0 => handle_execute::(self, context, network, &endpoint), NetworkName::TestnetV0 => handle_execute::(self, context, network, &endpoint), + NetworkName::CanaryV0 => handle_execute::(self, context, network, &endpoint), } } } // A helper function to handle the `execute` command. -fn handle_execute(command: Execute, context: Context, network: NetworkName, endpoint: &str) -> Result<::Output> { +fn handle_execute( + command: Execute, + context: Context, + network: NetworkName, + endpoint: &str, +) -> Result<::Output> { // If input values are provided, then run the program with those inputs. // Otherwise, use the input file. let mut inputs = command.inputs.clone(); @@ -156,8 +162,7 @@ fn handle_execute(command: Execute, context: Context, network: NetworkN }; // Specify the query - let query = - SnarkVMQuery::>::from(endpoint); + let query = SnarkVMQuery::>::from(endpoint); // Initialize the storage. let store = ConsensusStore::>::open(StorageMode::Production)?; @@ -207,13 +212,7 @@ fn handle_execute(command: Execute, context: Context, network: NetworkN // Check if the public balance is sufficient. if fee_record.is_none() { - check_balance::( - &private_key, - endpoint, - &network.to_string(), - context, - total_cost, - )?; + check_balance::(&private_key, endpoint, &network.to_string(), context, total_cost)?; } // Broadcast the execution transaction. @@ -234,14 +233,7 @@ fn handle_execute(command: Execute, context: Context, network: NetworkN } } println!("✅ Created execution transaction for '{}'\n", program_id.to_string().bold()); - handle_broadcast( - &format!( - "{}/{}/transaction/broadcast", - endpoint, network - ), - transaction, - &program_name, - )?; + handle_broadcast(&format!("{}/{}/transaction/broadcast", endpoint, network), transaction, &program_name)?; } else { println!("✅ Successful dry run execution for '{}'\n", program_id.to_string().bold()); } @@ -262,13 +254,7 @@ fn handle_execute(command: Execute, context: Context, network: NetworkN let inputs = inputs.iter().map(|input| Value::from_str(input).unwrap()).collect::>>(); // Execute the request. let (response, execution, metrics) = package - .execute::( - endpoint.to_string(), - &private_key, - Identifier::try_from(command.name.clone())?, - &inputs, - rng, - ) + .execute::(endpoint.to_string(), &private_key, Identifier::try_from(command.name.clone())?, &inputs, rng) .map_err(PackageError::execution_error)?; let fee = None; diff --git a/leo/cli/commands/mod.rs b/leo/cli/commands/mod.rs index c30c7cd9df..debb1aa57c 100644 --- a/leo/cli/commands/mod.rs +++ b/leo/cli/commands/mod.rs @@ -133,11 +133,9 @@ pub trait Command { /// require Build command output as their input. #[derive(Parser, Clone, Debug)] pub struct BuildOptions { - #[clap( - long, - help = "Endpoint to retrieve network state from. Overrides setting in `.env`.")] + #[clap(long, help = "Endpoint to retrieve network state from. Overrides setting in `.env`.")] pub endpoint: Option, - #[clap(long, help = "Network to broadcast to. Overrides setting in `.env`.")] + #[clap(long, help = "Network to broadcast to. Overrides setting in `.env`.")] pub(crate) network: Option, #[clap(long, help = "Does not recursively compile dependencies.")] pub non_recursive: bool, @@ -181,7 +179,7 @@ impl Default for BuildOptions { fn default() -> Self { Self { endpoint: None, - network:None, + network: None, non_recursive: false, offline: false, enable_symbol_table_spans: false, diff --git a/leo/cli/commands/new.rs b/leo/cli/commands/new.rs index 56f7f821fa..64c89050e7 100644 --- a/leo/cli/commands/new.rs +++ b/leo/cli/commands/new.rs @@ -62,6 +62,7 @@ impl Command for New { match network { NetworkName::MainnetV0 => Package::initialize::(&self.name, &package_path, self.endpoint), NetworkName::TestnetV0 => Package::initialize::(&self.name, &package_path, self.endpoint), + NetworkName::CanaryV0 => Package::initialize::(&self.name, &package_path, self.endpoint), }?; Ok(()) diff --git a/leo/cli/commands/query/mod.rs b/leo/cli/commands/query/mod.rs index 8de80b5fe5..c505d70213 100644 --- a/leo/cli/commands/query/mod.rs +++ b/leo/cli/commands/query/mod.rs @@ -47,12 +47,7 @@ use leo_retriever::{fetch_from_network, verify_valid_program, NetworkName}; /// Query live data from the Aleo network. #[derive(Parser, Debug)] pub struct Query { - #[clap( - short, - long, - global = true, - help = "Endpoint to retrieve network state from. Defaults to entry in `.env`.", - )] + #[clap(short, long, global = true, help = "Endpoint to retrieve network state from. Defaults to entry in `.env`.")] pub endpoint: Option, #[clap(short, long, global = true, help = "Network to use. Defaults to entry in `.env`.")] pub(crate) network: Option, @@ -79,12 +74,18 @@ impl Command for Query { match network { NetworkName::MainnetV0 => handle_query::(self, context, &network.to_string(), &endpoint), NetworkName::TestnetV0 => handle_query::(self, context, &network.to_string(), &endpoint), + NetworkName::CanaryV0 => handle_query::(self, context, &network.to_string(), &endpoint), } } } // A helper function to handle the `query` command. -fn handle_query(query: Query, context: Context, network: &str, endpoint: &str) -> Result<::Output> { +fn handle_query( + query: Query, + context: Context, + network: &str, + endpoint: &str, +) -> Result<::Output> { let recursive = context.recursive; let (program, output) = match query.command { QueryCommands::Block { command } => (None, command.apply(context, ())?), diff --git a/leo/cli/commands/run.rs b/leo/cli/commands/run.rs index b612f684c0..119fcccef5 100644 --- a/leo/cli/commands/run.rs +++ b/leo/cli/commands/run.rs @@ -56,6 +56,7 @@ impl Command for Run { match network { NetworkName::MainnetV0 => handle_run::(self, context), NetworkName::TestnetV0 => handle_run::(self, context), + NetworkName::CanaryV0 => handle_run::(self, context), } } } diff --git a/leo/cli/helpers/context.rs b/leo/cli/helpers/context.rs index 03e6188277..9d7eb5a230 100644 --- a/leo/cli/helpers/context.rs +++ b/leo/cli/helpers/context.rs @@ -23,14 +23,14 @@ use snarkvm::file::Manifest; use aleo_std::aleo_dir; use indexmap::IndexMap; -use snarkvm::prelude::{anyhow, Itertools, Network, PrivateKey}; +use snarkvm::prelude::{Itertools, Network, PrivateKey}; use std::{ env::current_dir, fs::File, io::Write, path::{Path, PathBuf}, + str::FromStr, }; -use std::str::FromStr; /// Project context, manifest, current directory etc /// All the info that is relevant in most of the commands @@ -144,27 +144,29 @@ impl Context { /// Returns the private key from the .env file specified in the directory. pub fn dotenv_private_key(&self, command: &str) -> Result> { - dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_private_key_from_env(command))?; + dotenvy::from_path(self.dir()?.join(".env")) + .map_err(|_| CliError::failed_to_get_private_key_from_env(command))?; // Load the private key from the environment. - let private_key = dotenvy::var("PRIVATE_KEY").map_err(|_| CliError::failed_to_get_private_key_from_env(command))?; + let private_key = + dotenvy::var("PRIVATE_KEY").map_err(|_| CliError::failed_to_get_private_key_from_env(command))?; // Parse the private key. Ok(PrivateKey::::from_str(&private_key)?) } - + /// Returns the endpoint from the .env file specified in the directory. pub fn dotenv_endpoint(&self, command: &str) -> Result { dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_endpoint_from_env(command))?; // Load the endpoint from the environment. Ok(dotenvy::var("ENDPOINT").map_err(|_| CliError::failed_to_get_endpoint_from_env(command))?) } - + /// Returns the network from the .env file specified in the directory. pub fn dotenv_network(&self, command: &str) -> Result { dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_network_from_env(command))?; // Load the network from the environment. Ok(dotenvy::var("NETWORK").map_err(|_| CliError::failed_to_get_network_from_env(command))?) } - + /// Returns the endpoint to interact with the network. /// If the `--endpoint` options is not provided, it will default to the one in the `.env` file. pub fn get_endpoint(&self, endpoint: &Option, command: &str) -> Result { @@ -173,7 +175,7 @@ impl Context { None => Ok(self.dotenv_endpoint(command)?), } } - + /// Returns the network name. /// If the `--network` options is not provided, it will default to the one in the `.env` file. pub fn get_network(&self, network: &Option, command: &str) -> Result { @@ -182,12 +184,12 @@ impl Context { None => Ok(self.dotenv_network(command)?), } } - + /// Returns the private key. /// If the `--private-key` options is not provided, it will default to the one in the `.env` file. pub fn get_private_key(&self, private_key: &Option, command: &str) -> Result> { match private_key { - Some(private_key) => Ok(PrivateKey::::from_str(&private_key)?), + Some(private_key) => Ok(PrivateKey::::from_str(private_key)?), None => self.dotenv_private_key(command), } } diff --git a/leo/package/src/package.rs b/leo/package/src/package.rs index 4538544508..ed4804acf5 100644 --- a/leo/package/src/package.rs +++ b/leo/package/src/package.rs @@ -23,8 +23,7 @@ use leo_errors::{PackageError, Result}; use leo_retriever::{Manifest, NetworkName}; use serde::Deserialize; use snarkvm::prelude::{Network, PrivateKey}; -use std::path::Path; -use std::str::FromStr; +use std::{path::Path, str::FromStr}; #[derive(Deserialize)] pub struct Package { @@ -147,9 +146,13 @@ impl Package { // Create the .gitignore file. Gitignore::new().write_to(&path)?; - // Create the .env file. + // Create the .env file. // Include the private key of validator 0 for ease of use with local devnets, as it will automatically be seeded with funds. - Env::::new(Some(PrivateKey::::from_str("APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH")?), endpoint)?.write_to(&path)?; + Env::::new( + Some(PrivateKey::::from_str("APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH")?), + endpoint, + )? + .write_to(&path)?; // Create a manifest. let manifest = Manifest::default(package_name); diff --git a/utils/retriever/src/program_context/network_name.rs b/utils/retriever/src/program_context/network_name.rs index 660aaac3c3..e9a87d07fc 100644 --- a/utils/retriever/src/program_context/network_name.rs +++ b/utils/retriever/src/program_context/network_name.rs @@ -16,7 +16,7 @@ use leo_errors::{CliError, LeoError}; use serde::{Deserialize, Serialize}; -use snarkvm::prelude::{MainnetV0, Network, TestnetV0}; +use snarkvm::prelude::{CanaryV0, MainnetV0, Network, TestnetV0}; use std::fmt; // Retrievable networks for an external program @@ -26,6 +26,8 @@ pub enum NetworkName { TestnetV0, #[serde(rename = "mainnet")] MainnetV0, + #[serde(rename = "canary")] + CanaryV0, } impl NetworkName { @@ -33,6 +35,7 @@ impl NetworkName { match self { NetworkName::TestnetV0 => TestnetV0::ID, NetworkName::MainnetV0 => MainnetV0::ID, + NetworkName::CanaryV0 => CanaryV0::ID, } } } @@ -44,6 +47,7 @@ impl TryFrom<&str> for NetworkName { match network { "testnet" => Ok(NetworkName::TestnetV0), "mainnet" => Ok(NetworkName::MainnetV0), + "canary" => Ok(NetworkName::CanaryV0), _ => Err(LeoError::CliError(CliError::invalid_network_name(network))), } } @@ -56,6 +60,8 @@ impl TryFrom for NetworkName { Ok(NetworkName::TestnetV0) } else if network == "mainnet" { Ok(NetworkName::MainnetV0) + } else if network == "canary" { + Ok(NetworkName::CanaryV0) } else { Err(LeoError::CliError(CliError::invalid_network_name(&network))) } @@ -67,6 +73,7 @@ impl fmt::Display for NetworkName { match self { NetworkName::TestnetV0 => write!(f, "testnet"), NetworkName::MainnetV0 => write!(f, "mainnet"), + NetworkName::CanaryV0 => write!(f, "canary"), } } } From f9371771e679f9cd1bb8a087cc4bb243321d47c1 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:04:59 -0700 Subject: [PATCH 07/20] fix --- .circleci/token/run.sh | 4 ++++ examples/auction/.env | 2 +- examples/auction/run.sh | 2 ++ examples/basic_bank/.env | 1 + examples/basic_bank/run.sh | 2 ++ examples/battleship/run.sh | 4 ++++ examples/bubblesort/.env | 1 + examples/core/.env | 1 + examples/fibonacci/.env | 1 + examples/groups/.env | 1 + examples/hackers-delight/ntzdebruijn/.env | 1 + examples/hackers-delight/ntzgaudet/.env | 1 + examples/hackers-delight/ntzloops/.env | 1 + examples/hackers-delight/ntzmasks/.env | 1 + examples/hackers-delight/ntzreisers/.env | 1 + examples/hackers-delight/ntzseals/.env | 1 + examples/hackers-delight/ntzsearchtree/.env | 1 + examples/hackers-delight/ntzsmallvals/.env | 1 + examples/helloworld/.env | 1 + examples/interest/.env | 1 + examples/lottery/.env | 1 + examples/message/.env | 1 + examples/simple_token/.env | 1 + examples/tictactoe/.env | 1 + examples/token/.env | 1 + examples/token/run.sh | 4 ++++ examples/twoadicity/.env | 1 + examples/vote/.env | 1 + leo/cli/commands/execute.rs | 6 ++---- leo/cli/helpers/context.rs | 2 +- 30 files changed, 42 insertions(+), 6 deletions(-) diff --git a/.circleci/token/run.sh b/.circleci/token/run.sh index e52735ed54..431fdff172 100644 --- a/.circleci/token/run.sh +++ b/.circleci/token/run.sh @@ -21,6 +21,7 @@ fi echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Publicly mint 100 tokens for Alice. @@ -89,6 +90,7 @@ leo run mint_private aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshd echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Publicly transfer 10 tokens from Alice to Bob. @@ -161,6 +163,7 @@ leo run transfer_private "{ echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Convert 30 public tokens from Alice into 30 private tokens for Bob. @@ -237,4 +240,5 @@ leo run transfer_private_to_public "{ echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env diff --git a/examples/auction/.env b/examples/auction/.env index 391701926c..22a5c2dd00 100644 --- a/examples/auction/.env +++ b/examples/auction/.env @@ -1,4 +1,4 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH - +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/auction/run.sh b/examples/auction/run.sh index d13f3de839..40f668611e 100755 --- a/examples/auction/run.sh +++ b/examples/auction/run.sh @@ -40,6 +40,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Have the first bidder place a bid of 10. @@ -141,6 +142,7 @@ leo run finish "{ echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env diff --git a/examples/basic_bank/.env b/examples/basic_bank/.env index 391701926c..f79f0a688b 100644 --- a/examples/basic_bank/.env +++ b/examples/basic_bank/.env @@ -1,4 +1,5 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/basic_bank/run.sh b/examples/basic_bank/run.sh index 9ac451db87..a96e475aa4 100755 --- a/examples/basic_bank/run.sh +++ b/examples/basic_bank/run.sh @@ -20,6 +20,7 @@ fi echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Have the bank issue 100 tokens to the user. @@ -164,6 +165,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Have the bank withdraw all of the user's tokens with compound interest over 15 periods at 12.34%. diff --git a/examples/battleship/run.sh b/examples/battleship/run.sh index e6e86718aa..af718af6b6 100755 --- a/examples/battleship/run.sh +++ b/examples/battleship/run.sh @@ -19,6 +19,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env echo "✅ Successfully initialized Player 1." @@ -117,6 +118,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env leo run play '{ @@ -187,6 +189,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env leo run play '{ @@ -250,4 +253,5 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env diff --git a/examples/bubblesort/.env b/examples/bubblesort/.env index c7836c7232..abae561342 100644 --- a/examples/bubblesort/.env +++ b/examples/bubblesort/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/core/.env b/examples/core/.env index c7836c7232..abae561342 100644 --- a/examples/core/.env +++ b/examples/core/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/fibonacci/.env b/examples/fibonacci/.env index c7836c7232..abae561342 100644 --- a/examples/fibonacci/.env +++ b/examples/fibonacci/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/groups/.env b/examples/groups/.env index c7836c7232..abae561342 100644 --- a/examples/groups/.env +++ b/examples/groups/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/hackers-delight/ntzdebruijn/.env b/examples/hackers-delight/ntzdebruijn/.env index c7836c7232..abae561342 100644 --- a/examples/hackers-delight/ntzdebruijn/.env +++ b/examples/hackers-delight/ntzdebruijn/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/hackers-delight/ntzgaudet/.env b/examples/hackers-delight/ntzgaudet/.env index c7836c7232..abae561342 100644 --- a/examples/hackers-delight/ntzgaudet/.env +++ b/examples/hackers-delight/ntzgaudet/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/hackers-delight/ntzloops/.env b/examples/hackers-delight/ntzloops/.env index c7836c7232..abae561342 100644 --- a/examples/hackers-delight/ntzloops/.env +++ b/examples/hackers-delight/ntzloops/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/hackers-delight/ntzmasks/.env b/examples/hackers-delight/ntzmasks/.env index c7836c7232..abae561342 100644 --- a/examples/hackers-delight/ntzmasks/.env +++ b/examples/hackers-delight/ntzmasks/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/hackers-delight/ntzreisers/.env b/examples/hackers-delight/ntzreisers/.env index c7836c7232..abae561342 100644 --- a/examples/hackers-delight/ntzreisers/.env +++ b/examples/hackers-delight/ntzreisers/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/hackers-delight/ntzseals/.env b/examples/hackers-delight/ntzseals/.env index c7836c7232..abae561342 100644 --- a/examples/hackers-delight/ntzseals/.env +++ b/examples/hackers-delight/ntzseals/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/hackers-delight/ntzsearchtree/.env b/examples/hackers-delight/ntzsearchtree/.env index c7836c7232..abae561342 100644 --- a/examples/hackers-delight/ntzsearchtree/.env +++ b/examples/hackers-delight/ntzsearchtree/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/hackers-delight/ntzsmallvals/.env b/examples/hackers-delight/ntzsmallvals/.env index c7836c7232..abae561342 100644 --- a/examples/hackers-delight/ntzsmallvals/.env +++ b/examples/hackers-delight/ntzsmallvals/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/helloworld/.env b/examples/helloworld/.env index c7836c7232..abae561342 100644 --- a/examples/helloworld/.env +++ b/examples/helloworld/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/interest/.env b/examples/interest/.env index c7836c7232..abae561342 100644 --- a/examples/interest/.env +++ b/examples/interest/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/lottery/.env b/examples/lottery/.env index c7836c7232..abae561342 100644 --- a/examples/lottery/.env +++ b/examples/lottery/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/message/.env b/examples/message/.env index c7836c7232..abae561342 100644 --- a/examples/message/.env +++ b/examples/message/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/simple_token/.env b/examples/simple_token/.env index c7836c7232..abae561342 100644 --- a/examples/simple_token/.env +++ b/examples/simple_token/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/tictactoe/.env b/examples/tictactoe/.env index c7836c7232..abae561342 100644 --- a/examples/tictactoe/.env +++ b/examples/tictactoe/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/token/.env b/examples/token/.env index 391701926c..f79f0a688b 100644 --- a/examples/token/.env +++ b/examples/token/.env @@ -1,4 +1,5 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/token/run.sh b/examples/token/run.sh index 1b212bf0fa..11f5951d14 100755 --- a/examples/token/run.sh +++ b/examples/token/run.sh @@ -20,6 +20,7 @@ fi echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Publicly mint 100 tokens for Alice. @@ -88,6 +89,7 @@ leo run mint_private aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Publicly transfer 10 tokens from Alice to Bob. @@ -160,6 +162,7 @@ leo run transfer_private "{ echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Convert 30 public tokens from Alice into 30 private tokens for Bob. @@ -236,4 +239,5 @@ leo run transfer_private_to_public "{ echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env diff --git a/examples/twoadicity/.env b/examples/twoadicity/.env index c7836c7232..abae561342 100644 --- a/examples/twoadicity/.env +++ b/examples/twoadicity/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/vote/.env b/examples/vote/.env index c7836c7232..abae561342 100644 --- a/examples/vote/.env +++ b/examples/vote/.env @@ -1,2 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/leo/cli/commands/execute.rs b/leo/cli/commands/execute.rs index 50dcfac2ae..35a1ac57bd 100644 --- a/leo/cli/commands/execute.rs +++ b/leo/cli/commands/execute.rs @@ -172,8 +172,7 @@ fn handle_execute( // Load the main program, and all of its imports. let program_id = &ProgramID::::from_str(&format!("{}.aleo", program_name))?; - // TODO: X - load_program_from_network(&command, context.clone(), &mut vm.process().write(), program_id, network, endpoint)?; + load_program_from_network(context.clone(), &mut vm.process().write(), program_id, network, endpoint)?; let fee_record = if let Some(record) = command.fee_options.record { Some(parse_record(&private_key, &record)?) @@ -322,7 +321,6 @@ fn handle_execute( /// A helper function to recursively load the program and all of its imports into the process. Lifted from snarkOS. fn load_program_from_network( - command: &Execute, context: Context, process: &mut Process, program_id: &ProgramID, @@ -354,7 +352,7 @@ fn load_program_from_network( // Add the imports to the process if does not exist yet. if !process.contains_program(import_program_id) { // Recursively load the program and its imports. - load_program_from_network(command, context.clone(), process, import_program_id, network, endpoint)?; + load_program_from_network(context.clone(), process, import_program_id, network, endpoint)?; } } diff --git a/leo/cli/helpers/context.rs b/leo/cli/helpers/context.rs index 9d7eb5a230..2d367a8038 100644 --- a/leo/cli/helpers/context.rs +++ b/leo/cli/helpers/context.rs @@ -23,7 +23,7 @@ use snarkvm::file::Manifest; use aleo_std::aleo_dir; use indexmap::IndexMap; -use snarkvm::prelude::{Itertools, Network, PrivateKey}; +use snarkvm::prelude::{Network, PrivateKey}; use std::{ env::current_dir, fs::File, From 4215c327fdbf371801671b243611ce245d380917 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:52:59 -0700 Subject: [PATCH 08/20] add endpoints to examples .env --- .circleci/token/run.sh | 3 +++ examples/auction/run.sh | 2 ++ examples/basic_bank/.env | 1 - examples/basic_bank/run.sh | 1 + examples/battleship/.env | 1 + examples/battleship/run.sh | 3 +++ examples/token/.env | 1 - examples/token/run.sh | 3 +++ 8 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.circleci/token/run.sh b/.circleci/token/run.sh index 431fdff172..fb6e582a2a 100644 --- a/.circleci/token/run.sh +++ b/.circleci/token/run.sh @@ -56,6 +56,7 @@ leo run mint_public aleo13ssze66adjjkt795z9u5wpq8h6kn0y2657726h4h3e3wfnez4vqsm30 echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Privately mint 100 tokens for Bob. @@ -125,6 +126,7 @@ leo run transfer_public aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqy echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Privately transfer 20 tokens from Bob to Alice. @@ -199,6 +201,7 @@ leo run transfer_public_to_private aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4 echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Convert 40 private tokens from Bob into 40 public tokens for Alice. diff --git a/examples/auction/run.sh b/examples/auction/run.sh index 40f668611e..fa8e9a62d2 100755 --- a/examples/auction/run.sh +++ b/examples/auction/run.sh @@ -63,6 +63,7 @@ leo run place_bid aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9p echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Have the second bidder place a bid of 90. @@ -85,6 +86,7 @@ leo run place_bid aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4 echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2GUmKbVsuc1NSj28pa1WTQuZaK5f1DQJAT6vPcHyWokG +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Have the auctioneer select the winning bid. diff --git a/examples/basic_bank/.env b/examples/basic_bank/.env index f79f0a688b..22a5c2dd00 100644 --- a/examples/basic_bank/.env +++ b/examples/basic_bank/.env @@ -2,4 +2,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH ENDPOINT=https://api.explorer.aleo.org/v1 - diff --git a/examples/basic_bank/run.sh b/examples/basic_bank/run.sh index a96e475aa4..f29d079438 100755 --- a/examples/basic_bank/run.sh +++ b/examples/basic_bank/run.sh @@ -71,6 +71,7 @@ leo run issue aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t 10 echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Have the user deposit 50 tokens into the bank. diff --git a/examples/battleship/.env b/examples/battleship/.env index 59936403c4..a4b3c79999 100644 --- a/examples/battleship/.env +++ b/examples/battleship/.env @@ -1,4 +1,5 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 diff --git a/examples/battleship/run.sh b/examples/battleship/run.sh index af718af6b6..42fe90a988 100755 --- a/examples/battleship/run.sh +++ b/examples/battleship/run.sh @@ -70,6 +70,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env leo run initialize_board 31u64 2207646875648u64 224u64 9042383626829824u64 aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t || exit @@ -154,6 +155,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env leo run play '{ @@ -225,6 +227,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env leo run play '{ diff --git a/examples/token/.env b/examples/token/.env index f79f0a688b..22a5c2dd00 100644 --- a/examples/token/.env +++ b/examples/token/.env @@ -2,4 +2,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH ENDPOINT=https://api.explorer.aleo.org/v1 - diff --git a/examples/token/run.sh b/examples/token/run.sh index 11f5951d14..a15525f8f9 100755 --- a/examples/token/run.sh +++ b/examples/token/run.sh @@ -55,6 +55,7 @@ leo run mint_public aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Privately mint 100 tokens for Bob. @@ -124,6 +125,7 @@ leo run transfer_public aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5p echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Privately transfer 20 tokens from Bob to Alice. @@ -198,6 +200,7 @@ leo run transfer_public_to_private aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0x echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh +ENDPOINT=https://api.explorer.aleo.org/v1 " > .env # Convert 40 private tokens from Bob into 40 public tokens for Alice. From e6c6541d70e82e32e128e9c1de84315dd9a0dd09 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 10:36:38 +0000 Subject: [PATCH 09/20] Bump lazy_static from 1.4.0 to 1.5.0 Bumps [lazy_static](https://github.com/rust-lang-nursery/lazy-static.rs) from 1.4.0 to 1.5.0. - [Release notes](https://github.com/rust-lang-nursery/lazy-static.rs/releases) - [Commits](https://github.com/rust-lang-nursery/lazy-static.rs/compare/1.4.0...1.5.0) --- updated-dependencies: - dependency-name: lazy_static dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- compiler/parser/Cargo.toml | 2 +- leo/package/Cargo.toml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef1f9404e9..5099dad311 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1470,9 +1470,9 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "leo-abnf" diff --git a/Cargo.toml b/Cargo.toml index 689ec0f93e..01c739450d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -124,7 +124,7 @@ version = "1.9" features = [ "serde" ] [dependencies.lazy_static] -version = "1.4.0" +version = "1.5.0" [dependencies.rand] version = "0.8" diff --git a/compiler/parser/Cargo.toml b/compiler/parser/Cargo.toml index b539229d0d..c616ade9aa 100644 --- a/compiler/parser/Cargo.toml +++ b/compiler/parser/Cargo.toml @@ -41,7 +41,7 @@ features = [ "derive" ] version = "1.9" [dependencies.lazy_static] -version = "1.3.0" +version = "1.5.0" [dependencies.serde] version = "1.0" diff --git a/leo/package/Cargo.toml b/leo/package/Cargo.toml index ed2c7a6299..e1528df21b 100644 --- a/leo/package/Cargo.toml +++ b/leo/package/Cargo.toml @@ -60,7 +60,7 @@ version = "0.8" version = "0.1" [dev-dependencies.lazy_static] -version = "1.3.0" +version = "1.5.0" [dev-dependencies.snarkvm] workspace = true From eda937a5b19e8b125f852efd5636f48bf3ce5f5b Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:14:25 -0700 Subject: [PATCH 10/20] fixes --- Cargo.lock | 114 +++++++++--------- Cargo.toml | 2 +- compiler/compiler/tests/utilities/mod.rs | 2 +- errors/src/errors/cli/cli_errors.rs | 20 ++- errors/src/errors/package/package_errors.rs | 14 +++ leo/cli/commands/account.rs | 26 +--- leo/cli/commands/build.rs | 7 +- leo/cli/commands/deploy.rs | 30 +++-- leo/cli/commands/execute.rs | 41 ++++--- leo/cli/commands/mod.rs | 3 +- leo/cli/commands/new.rs | 4 +- leo/cli/commands/query/mod.rs | 8 +- leo/cli/commands/run.rs | 6 +- leo/cli/helpers/context.rs | 32 +++-- .../retriever/src/program_context/manifest.rs | 2 +- 15 files changed, 163 insertions(+), 148 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 75c111b688..210aef6332 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2851,7 +2851,7 @@ dependencies = [ [[package]] name = "snarkvm" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "anstyle", "anyhow", @@ -2880,7 +2880,7 @@ dependencies = [ [[package]] name = "snarkvm-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "aleo-std", "anyhow", @@ -2910,7 +2910,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-account", "snarkvm-circuit-algorithms", @@ -2924,7 +2924,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-account" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-network", @@ -2935,7 +2935,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-types", "snarkvm-console-algorithms", @@ -2945,7 +2945,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-collections" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-types", @@ -2955,7 +2955,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "indexmap 2.2.6", "itertools 0.11.0", @@ -2973,12 +2973,12 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment-witness" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" [[package]] name = "snarkvm-circuit-network" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-collections", @@ -2989,7 +2989,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "paste", "snarkvm-circuit-account", @@ -3004,7 +3004,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-address", @@ -3019,7 +3019,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-address" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3032,7 +3032,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-boolean" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-environment", "snarkvm-console-types-boolean", @@ -3041,7 +3041,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-field" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3051,7 +3051,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-group" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3063,7 +3063,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-integers" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3075,7 +3075,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-scalar" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3086,7 +3086,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-string" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3098,7 +3098,7 @@ dependencies = [ [[package]] name = "snarkvm-console" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-console-account", "snarkvm-console-algorithms", @@ -3111,7 +3111,7 @@ dependencies = [ [[package]] name = "snarkvm-console-account" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "bs58", "snarkvm-console-network", @@ -3122,7 +3122,7 @@ dependencies = [ [[package]] name = "snarkvm-console-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "blake2s_simd", "smallvec", @@ -3135,7 +3135,7 @@ dependencies = [ [[package]] name = "snarkvm-console-collections" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "aleo-std", "rayon", @@ -3146,7 +3146,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "anyhow", "indexmap 2.2.6", @@ -3169,7 +3169,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network-environment" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "anyhow", "bech32", @@ -3187,7 +3187,7 @@ dependencies = [ [[package]] name = "snarkvm-console-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "enum-iterator", "enum_index", @@ -3209,7 +3209,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-address", @@ -3224,7 +3224,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-address" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3235,7 +3235,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-boolean" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-console-network-environment", ] @@ -3243,7 +3243,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-field" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3253,7 +3253,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-group" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3264,7 +3264,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-integers" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3275,7 +3275,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-scalar" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3286,7 +3286,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-string" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3297,7 +3297,7 @@ dependencies = [ [[package]] name = "snarkvm-curves" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "rand", "rayon", @@ -3311,7 +3311,7 @@ dependencies = [ [[package]] name = "snarkvm-fields" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "aleo-std", "anyhow", @@ -3328,7 +3328,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "aleo-std", "anyhow", @@ -3352,7 +3352,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-authority" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "anyhow", "rand", @@ -3364,7 +3364,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-block" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3383,7 +3383,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-committee" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3395,7 +3395,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-ledger-narwhal-batch-certificate", "snarkvm-ledger-narwhal-batch-header", @@ -3408,7 +3408,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-certificate" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3421,7 +3421,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-header" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3433,7 +3433,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-data" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "bytes", "serde_json", @@ -3444,7 +3444,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-subdag" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3459,7 +3459,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-transmission" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "bytes", "serde_json", @@ -3472,7 +3472,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-transmission-id" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "snarkvm-console", "snarkvm-ledger-puzzle", @@ -3481,7 +3481,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-puzzle" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "aleo-std", "anyhow", @@ -3501,7 +3501,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-puzzle-epoch" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "anyhow", "colored", @@ -3516,7 +3516,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-query" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "async-trait", "reqwest 0.11.27", @@ -3529,7 +3529,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-store" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "aleo-std-storage", "anyhow", @@ -3552,7 +3552,7 @@ dependencies = [ [[package]] name = "snarkvm-parameters" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "aleo-std", "anyhow", @@ -3577,7 +3577,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "aleo-std", "anyhow", @@ -3607,7 +3607,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-process" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "aleo-std", "colored", @@ -3630,7 +3630,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "indexmap 2.2.6", "paste", @@ -3644,7 +3644,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-snark" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "bincode", "once_cell", @@ -3657,7 +3657,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "aleo-std", "anyhow", @@ -3678,7 +3678,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities-derives" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=6d64025#6d64025f3f775fa164d70d9a8177ec93c97cd36e" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" dependencies = [ "proc-macro2", "quote 1.0.36", diff --git a/Cargo.toml b/Cargo.toml index 2084287362..8c41b5421b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ members = [ [workspace.dependencies.snarkvm] #version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "6d64025" +rev = "8a05317" [lib] path = "leo/lib.rs" diff --git a/compiler/compiler/tests/utilities/mod.rs b/compiler/compiler/tests/utilities/mod.rs index f0456cbc85..227e65fed0 100644 --- a/compiler/compiler/tests/utilities/mod.rs +++ b/compiler/compiler/tests/utilities/mod.rs @@ -138,7 +138,7 @@ pub fn setup_build_directory( let _manifest_file = Manifest::create(&directory, &program_id).unwrap(); // Create the environment file. - Env::::new(None, endpoint).unwrap().write_to(&directory).unwrap(); + Env::::new(None, endpoint).unwrap().write_to(&directory); if Env::::exists_at(&directory) { println!(".env file created at {:?}", &directory); } diff --git a/errors/src/errors/cli/cli_errors.rs b/errors/src/errors/cli/cli_errors.rs index 99c67120b1..634cb6551a 100644 --- a/errors/src/errors/cli/cli_errors.rs +++ b/errors/src/errors/cli/cli_errors.rs @@ -267,23 +267,23 @@ create_messages!( @backtraced failed_to_get_endpoint_from_env { - args: (command: impl Display), + args: (), msg: "Failed to get an endpoint.".to_string(), - help: Some(format!("Either make sure you have a `.env` file in current project directory with an `ENDPOINT` variable set, or set the `--endpoint` flag when invoking the CLI command.\n Example: `ENDPOINT=https://api.explorer.aleo.org/v1` or `leo {command} --endpoint \"https://api.explorer.aleo.org/v1\"`.")), + help: Some("Either make sure you have a `.env` file in current project directory with an `ENDPOINT` variable set, or set the `--endpoint` flag when invoking the CLI command.\n Example: `ENDPOINT=https://api.explorer.aleo.org/v1` or `leo build --endpoint \"https://api.explorer.aleo.org/v1\"`.".to_string()), } @backtraced failed_to_get_private_key_from_env { - args: (command: impl Display), + args: (), msg: "Failed to get a private key.".to_string(), - help: Some(format!("Either make sure you have a `.env` file in current project directory with a `PRIVATE_KEY` variable set, or set the `--private-key` flag when invoking the CLI command.\n Example: `PRIVATE_KEY=0x1234...` or `leo {command} --private-key \"APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH\"`.")), + help: Some("Either make sure you have a `.env` file in current project directory with a `PRIVATE_KEY` variable set, or set the `--private-key` flag when invoking the CLI command.\n Example: `PRIVATE_KEY=0x1234...` or `leo deploy --private-key \"APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH\"`.".to_string()), } @backtraced failed_to_get_network_from_env { - args: (command: impl Display), + args: (), msg: "Failed to get a network.".to_string(), - help: Some(format!("Either make sure you have a `.env` file in current project directory with a `NETWORK` variable set, or set the `--network` flag when invoking the CLI command.\n Example: `NETWORK=testnet` or `leo {command} --network testnet`.")), + help: Some("Either make sure you have a `.env` file in current project directory with a `NETWORK` variable set, or set the `--network` flag when invoking the CLI command.\n Example: `NETWORK=testnet` or `leo build --network testnet`.".to_string()), } @backtraced @@ -299,4 +299,12 @@ create_messages!( msg: format!("Program `{program}` exceeds the variable limit {limit} for deployment on network {network}."), help: Some("Reduce the number of variables in the program by reducing the number of instructions in transition functions.".to_string()), } + + @backtraced + confirmation_failed { + args: (), + msg: "Failed to confirm transaction".to_string(), + help: None, + } + ); diff --git a/errors/src/errors/package/package_errors.rs b/errors/src/errors/package/package_errors.rs index c33ca4accd..b5b7c93d2e 100644 --- a/errors/src/errors/package/package_errors.rs +++ b/errors/src/errors/package/package_errors.rs @@ -418,4 +418,18 @@ create_messages!( msg: format!("❌ Execution error: {error}"), help: Some("Make sure that you are using the right `--network` options.".to_string()), } + + @backtraced + snarkvm_error { + args: (error: impl Display), + msg: format!("{error}"), + help: None, + } + + @backtraced + failed_to_load_package { + args: (path: impl Display), + msg: format!("Failed to load leo project at path {path}"), + help: Some("Make sure that the path is correct and that the project exists.".to_string()), + } ); diff --git a/leo/cli/commands/account.rs b/leo/cli/commands/account.rs index b94c99209c..e9a36159c7 100644 --- a/leo/cli/commands/account.rs +++ b/leo/cli/commands/account.rs @@ -26,7 +26,7 @@ use crossterm::ExecutableCommand; use leo_retriever::NetworkName; use rand::SeedableRng; use rand_chacha::ChaChaRng; -use snarkvm::prelude::{MainnetV0, Network, TestnetV0}; +use snarkvm::prelude::{CanaryV0, MainnetV0, Network, TestnetV0}; use std::{ io::{self, Read, Write}, path::PathBuf, @@ -96,13 +96,6 @@ pub enum Account { raw: bool, #[clap(short = 'n', long, help = "Name of the network to use", default_value = "mainnet")] network: String, - #[clap( - short = 'e', - long, - help = "Endpoint to retrieve network state from.", - default_value = "https://api.explorer.aleo.org/v1" - )] - endpoint: String, }, /// Verify a message from an Aleo address. Verify { @@ -120,13 +113,6 @@ pub enum Account { raw: bool, #[clap(short = 'n', long, help = "Name of the network to use", default_value = "mainnet")] network: String, - #[clap( - short = 'e', - long, - help = "Endpoint to retrieve network state from.", - default_value = "https://api.explorer.aleo.org/v1" - )] - endpoint: String, }, } @@ -152,7 +138,7 @@ impl Command for Account { match network { NetworkName::MainnetV0 => generate_new_account::(seed, write, discreet, &ctx, endpoint), NetworkName::TestnetV0 => generate_new_account::(seed, write, discreet, &ctx, endpoint), - NetworkName::CanaryV0 => generate_new_account::(seed, write, discreet, &ctx, endpoint), + NetworkName::CanaryV0 => generate_new_account::(seed, write, discreet, &ctx, endpoint), }? } Account::Import { private_key, write, discreet, network, endpoint } => { @@ -161,10 +147,10 @@ impl Command for Account { match network { NetworkName::MainnetV0 => import_account::(private_key, write, discreet, &ctx, endpoint), NetworkName::TestnetV0 => import_account::(private_key, write, discreet, &ctx, endpoint), - NetworkName::CanaryV0 => import_account::(private_key, write, discreet, &ctx, endpoint), + NetworkName::CanaryV0 => import_account::(private_key, write, discreet, &ctx, endpoint), }? } - Self::Sign { message, seed, raw, private_key, private_key_file, network, endpoint: _ } => { + Self::Sign { message, seed, raw, private_key, private_key_file, network } => { // Parse the network. let network = NetworkName::try_from(network.as_str())?; let result = match network { @@ -180,13 +166,13 @@ impl Command for Account { }?; println!("{result}") } - Self::Verify { address, signature, message, raw, network, endpoint: _ } => { + Self::Verify { address, signature, message, raw, network } => { // Parse the network. let network = NetworkName::try_from(network.as_str())?; let result = match network { NetworkName::MainnetV0 => verify_message::(address, signature, message, raw), NetworkName::TestnetV0 => verify_message::(address, signature, message, raw), - NetworkName::CanaryV0 => verify_message::(address, signature, message, raw), + NetworkName::CanaryV0 => verify_message::(address, signature, message, raw), }?; println!("{result}") } diff --git a/leo/cli/commands/build.rs b/leo/cli/commands/build.rs index d367777926..bc9816df44 100644 --- a/leo/cli/commands/build.rs +++ b/leo/cli/commands/build.rs @@ -29,6 +29,7 @@ use snarkvm::{ }; use indexmap::IndexMap; +use snarkvm::prelude::CanaryV0; use std::{ io::Write, path::{Path, PathBuf}, @@ -93,11 +94,11 @@ impl Command for Build { fn apply(self, context: Context, _: Self::Input) -> Result { // Parse the network. - let network = NetworkName::try_from(context.get_network(&self.options.network, "build")?)?; + let network = NetworkName::try_from(context.get_network(&self.options.network)?)?; match network { NetworkName::MainnetV0 => handle_build::(&self, context), NetworkName::TestnetV0 => handle_build::(&self, context), - NetworkName::CanaryV0 => handle_build::(&self, context), + NetworkName::CanaryV0 => handle_build::(&self, context), } } } @@ -128,7 +129,7 @@ fn handle_build(command: &Build, context: Context) -> Result< Result { // Parse the network. - let network = NetworkName::try_from(context.get_network(&self.options.network, "deploy")?)?; - let endpoint = context.get_endpoint(&self.options.endpoint, "deploy")?; + let network = NetworkName::try_from(context.get_network(&self.options.network)?)?; + let endpoint = context.get_endpoint(&self.options.endpoint)?; match network { NetworkName::MainnetV0 => handle_deploy::(&self, context, network, &endpoint), NetworkName::TestnetV0 => handle_deploy::(&self, context, network, &endpoint), - NetworkName::CanaryV0 => handle_deploy::(&self, context, network, &endpoint), + NetworkName::CanaryV0 => handle_deploy::(&self, context, network, &endpoint), } } } @@ -91,7 +92,7 @@ fn handle_deploy, N: Network>( let project_name = context.open_manifest::()?.program_id().to_string(); // Get the private key. - let private_key = context.get_private_key(&command.fee_options.private_key, "deploy")?; + let private_key = context.get_private_key(&command.fee_options.private_key)?; let address = Address::try_from(&private_key)?; // Specify the query @@ -192,14 +193,17 @@ fn handle_deploy, N: Network>( "Do you want to submit deployment of program `{name}.aleo` to network {} via endpoint {} using address {}?", network, endpoint, address ); - let confirmation = Confirm::with_theme(&ColorfulTheme::default()) - .with_prompt(prompt) - .default(false) - .interact() - .unwrap(); - if !confirmation { - println!("✅ Successfully aborted the execution transaction for '{}'\n", name.bold()); - return Ok(()); + let confirmation = + Confirm::with_theme(&ColorfulTheme::default()).with_prompt(prompt).default(false).interact(); + + // Check if the user confirmed the transaction. + if let Ok(confirmation) = confirmation { + if !confirmation { + println!("✅ Successfully aborted the execution transaction for '{}'\n", name.bold()); + return Ok(()); + } + } else { + return Err(CliError::confirmation_failed().into()); } } println!("✅ Created deployment transaction for '{}'\n", name.bold()); diff --git a/leo/cli/commands/execute.rs b/leo/cli/commands/execute.rs index 35a1ac57bd..b37fd17941 100644 --- a/leo/cli/commands/execute.rs +++ b/leo/cli/commands/execute.rs @@ -27,7 +27,7 @@ use crate::cli::query::QueryCommands; use dialoguer::{theme::ColorfulTheme, Confirm}; use leo_retriever::NetworkName; use snarkvm::{ - circuit::{Aleo, AleoTestnetV0, AleoV0}, + circuit::{Aleo, AleoCanaryV0, AleoTestnetV0, AleoV0}, cli::LOCALE, ledger::Transaction::Execute as ExecuteTransaction, package::Package as SnarkVMPackage, @@ -87,12 +87,12 @@ impl Command for Execute { fn apply(self, context: Context, _input: Self::Input) -> Result { // Parse the network. - let network = NetworkName::try_from(context.get_network(&self.compiler_options.network, "deploy")?)?; - let endpoint = context.get_endpoint(&self.compiler_options.endpoint, "deploy")?; + let network = NetworkName::try_from(context.get_network(&self.compiler_options.network)?)?; + let endpoint = context.get_endpoint(&self.compiler_options.endpoint)?; match network { NetworkName::MainnetV0 => handle_execute::(self, context, network, &endpoint), NetworkName::TestnetV0 => handle_execute::(self, context, network, &endpoint), - NetworkName::CanaryV0 => handle_execute::(self, context, network, &endpoint), + NetworkName::CanaryV0 => handle_execute::(self, context, network, &endpoint), } } } @@ -221,14 +221,18 @@ fn handle_execute( "Do you want to submit execution of function `{}` on program `{program_name}.aleo` to network {} via endpoint {} using address {}?", &command.name, network, endpoint, address ); - let confirmation = Confirm::with_theme(&ColorfulTheme::default()) - .with_prompt(prompt) - .default(false) - .interact() - .unwrap(); - if !confirmation { - println!("✅ Successfully aborted the execution transaction for '{}'\n", program_name.bold()); - return Ok(()); + // Ask the user for confirmation of the transaction. + let confirmation = + Confirm::with_theme(&ColorfulTheme::default()).with_prompt(prompt).default(false).interact(); + + // Check if the user confirmed the transaction. + if let Ok(confirmation) = confirmation { + if !confirmation { + println!("✅ Successfully aborted the execution transaction for '{}'\n", program_name.bold()); + return Ok(()); + } + } else { + return Err(CliError::confirmation_failed().into()); } } println!("✅ Created execution transaction for '{}'\n", program_id.to_string().bold()); @@ -250,7 +254,10 @@ fn handle_execute( // Load the package. let package = SnarkVMPackage::open(&path)?; // Convert the inputs. - let inputs = inputs.iter().map(|input| Value::from_str(input).unwrap()).collect::>>(); + let inputs = inputs + .iter() + .map(|input| Value::from_str(input).map_err(PackageError::snarkvm_error).unwrap()) + .collect::>>(); // Execute the request. let (response, execution, metrics) = package .execute::(endpoint.to_string(), &private_key, Identifier::try_from(command.name.clone())?, &inputs, rng) @@ -332,11 +339,7 @@ fn load_program_from_network( endpoint: Some(endpoint.to_string()), network: Some(network.to_string()), command: QueryCommands::Program { - command: crate::cli::commands::query::Program { - name: program_id.to_string(), - mappings: false, - mapping_value: None, - }, + command: query::Program { name: program_id.to_string(), mappings: false, mapping_value: None }, }, } .execute(Context::new(context.path.clone(), context.home.clone(), true)?)?; @@ -377,5 +380,5 @@ fn execution_cost_breakdown(name: &String, total_cost: f64, storage_cost: f64, f ]; let mut out = Vec::new(); text_tables::render(&mut out, data).unwrap(); - println!("{}", ::std::str::from_utf8(&out).unwrap()); + println!("{}", std::str::from_utf8(&out).unwrap()); } diff --git a/leo/cli/commands/mod.rs b/leo/cli/commands/mod.rs index debb1aa57c..d1bc4dcd0e 100644 --- a/leo/cli/commands/mod.rs +++ b/leo/cli/commands/mod.rs @@ -261,8 +261,9 @@ fn check_balance( .execute(Context::new(context.path.clone(), context.home.clone(), true)?)?; // Remove the last 3 characters since they represent the `u64` suffix. public_balance.truncate(public_balance.len() - 3); - // Compare balance. + // This unwrap is safe as the Query will error if it cannot retrieve a public balance, and if it returns a balance that will be a u64. let balance = public_balance.parse::().unwrap(); + // Compare balance. if balance < total_cost { Err(PackageError::insufficient_balance(address, public_balance, total_cost).into()) } else { diff --git a/leo/cli/commands/new.rs b/leo/cli/commands/new.rs index 64c89050e7..df5fe53062 100644 --- a/leo/cli/commands/new.rs +++ b/leo/cli/commands/new.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use super::*; -use snarkvm::prelude::{MainnetV0, TestnetV0}; +use snarkvm::prelude::{CanaryV0, MainnetV0, TestnetV0}; use leo_retriever::NetworkName; @@ -62,7 +62,7 @@ impl Command for New { match network { NetworkName::MainnetV0 => Package::initialize::(&self.name, &package_path, self.endpoint), NetworkName::TestnetV0 => Package::initialize::(&self.name, &package_path, self.endpoint), - NetworkName::CanaryV0 => Package::initialize::(&self.name, &package_path, self.endpoint), + NetworkName::CanaryV0 => Package::initialize::(&self.name, &package_path, self.endpoint), }?; Ok(()) diff --git a/leo/cli/commands/query/mod.rs b/leo/cli/commands/query/mod.rs index c505d70213..591f935d32 100644 --- a/leo/cli/commands/query/mod.rs +++ b/leo/cli/commands/query/mod.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use super::*; -use snarkvm::prelude::{MainnetV0, TestnetV0}; +use snarkvm::prelude::{CanaryV0, MainnetV0, TestnetV0}; mod block; use block::Block; @@ -69,12 +69,12 @@ impl Command for Query { fn apply(self, context: Context, _: Self::Input) -> Result { // Parse the network. - let network = NetworkName::try_from(context.get_network(&self.network, "query")?)?; - let endpoint = context.get_endpoint(&self.endpoint, "query")?; + let network = NetworkName::try_from(context.get_network(&self.network)?)?; + let endpoint = context.get_endpoint(&self.endpoint)?; match network { NetworkName::MainnetV0 => handle_query::(self, context, &network.to_string(), &endpoint), NetworkName::TestnetV0 => handle_query::(self, context, &network.to_string(), &endpoint), - NetworkName::CanaryV0 => handle_query::(self, context, &network.to_string(), &endpoint), + NetworkName::CanaryV0 => handle_query::(self, context, &network.to_string(), &endpoint), } } } diff --git a/leo/cli/commands/run.rs b/leo/cli/commands/run.rs index 119fcccef5..2c1e348db8 100644 --- a/leo/cli/commands/run.rs +++ b/leo/cli/commands/run.rs @@ -19,7 +19,7 @@ use super::*; use leo_retriever::NetworkName; use snarkvm::{ cli::Run as SnarkVMRun, - prelude::{MainnetV0, Network, Parser as SnarkVMParser, TestnetV0}, + prelude::{CanaryV0, MainnetV0, Network, Parser as SnarkVMParser, TestnetV0}, }; /// Build, Prove and Run Leo program with inputs @@ -52,11 +52,11 @@ impl Command for Run { fn apply(self, context: Context, _: Self::Input) -> Result { // Parse the network. - let network = NetworkName::try_from(context.get_network(&self.compiler_options.network, "run")?)?; + let network = NetworkName::try_from(context.get_network(&self.compiler_options.network)?)?; match network { NetworkName::MainnetV0 => handle_run::(self, context), NetworkName::TestnetV0 => handle_run::(self, context), - NetworkName::CanaryV0 => handle_run::(self, context), + NetworkName::CanaryV0 => handle_run::(self, context), } } } diff --git a/leo/cli/helpers/context.rs b/leo/cli/helpers/context.rs index 2d367a8038..38309ce04e 100644 --- a/leo/cli/helpers/context.rs +++ b/leo/cli/helpers/context.rs @@ -143,54 +143,52 @@ impl Context { } /// Returns the private key from the .env file specified in the directory. - pub fn dotenv_private_key(&self, command: &str) -> Result> { - dotenvy::from_path(self.dir()?.join(".env")) - .map_err(|_| CliError::failed_to_get_private_key_from_env(command))?; + pub fn dotenv_private_key(&self) -> Result> { + dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_private_key_from_env())?; // Load the private key from the environment. - let private_key = - dotenvy::var("PRIVATE_KEY").map_err(|_| CliError::failed_to_get_private_key_from_env(command))?; + let private_key = dotenvy::var("PRIVATE_KEY").map_err(|_| CliError::failed_to_get_private_key_from_env())?; // Parse the private key. Ok(PrivateKey::::from_str(&private_key)?) } /// Returns the endpoint from the .env file specified in the directory. - pub fn dotenv_endpoint(&self, command: &str) -> Result { - dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_endpoint_from_env(command))?; + pub fn dotenv_endpoint(&self) -> Result { + dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_endpoint_from_env())?; // Load the endpoint from the environment. - Ok(dotenvy::var("ENDPOINT").map_err(|_| CliError::failed_to_get_endpoint_from_env(command))?) + Ok(dotenvy::var("ENDPOINT").map_err(|_| CliError::failed_to_get_endpoint_from_env())?) } /// Returns the network from the .env file specified in the directory. - pub fn dotenv_network(&self, command: &str) -> Result { - dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_network_from_env(command))?; + pub fn dotenv_network(&self) -> Result { + dotenvy::from_path(self.dir()?.join(".env")).map_err(|_| CliError::failed_to_get_network_from_env())?; // Load the network from the environment. - Ok(dotenvy::var("NETWORK").map_err(|_| CliError::failed_to_get_network_from_env(command))?) + Ok(dotenvy::var("NETWORK").map_err(|_| CliError::failed_to_get_network_from_env())?) } /// Returns the endpoint to interact with the network. /// If the `--endpoint` options is not provided, it will default to the one in the `.env` file. - pub fn get_endpoint(&self, endpoint: &Option, command: &str) -> Result { + pub fn get_endpoint(&self, endpoint: &Option) -> Result { match endpoint { Some(endpoint) => Ok(endpoint.clone()), - None => Ok(self.dotenv_endpoint(command)?), + None => Ok(self.dotenv_endpoint()?), } } /// Returns the network name. /// If the `--network` options is not provided, it will default to the one in the `.env` file. - pub fn get_network(&self, network: &Option, command: &str) -> Result { + pub fn get_network(&self, network: &Option) -> Result { match network { Some(network) => Ok(network.clone()), - None => Ok(self.dotenv_network(command)?), + None => Ok(self.dotenv_network()?), } } /// Returns the private key. /// If the `--private-key` options is not provided, it will default to the one in the `.env` file. - pub fn get_private_key(&self, private_key: &Option, command: &str) -> Result> { + pub fn get_private_key(&self, private_key: &Option) -> Result> { match private_key { Some(private_key) => Ok(PrivateKey::::from_str(private_key)?), - None => self.dotenv_private_key(command), + None => self.dotenv_private_key(), } } } diff --git a/utils/retriever/src/program_context/manifest.rs b/utils/retriever/src/program_context/manifest.rs index 076959371b..eef1c22120 100644 --- a/utils/retriever/src/program_context/manifest.rs +++ b/utils/retriever/src/program_context/manifest.rs @@ -87,7 +87,7 @@ impl Manifest { pub fn read_from_dir(path: &Path) -> Result { // Read the manifest file. let contents = std::fs::read_to_string(path.join("program.json")) - .map_err(|err| PackageError::failed_to_read_file(path.to_str().unwrap(), err))?; + .map_err(|_| PackageError::failed_to_load_package(path.to_str().unwrap()))?; // Deserialize the manifest. serde_json::from_str(&contents) .map_err(|err| PackageError::failed_to_deserialize_manifest_file(path.to_str().unwrap(), err)) From b9667ef1909190e8fc4a1239101243262a9537dd Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:40:33 -0700 Subject: [PATCH 11/20] change endpoint for local examples --- .circleci/token/run.sh | 14 +++++++------- examples/auction/.env | 2 +- examples/auction/run.sh | 8 ++++---- examples/basic_bank/.env | 2 +- examples/basic_bank/run.sh | 6 +++--- examples/battleship/.env | 2 +- examples/battleship/run.sh | 14 +++++++------- examples/bubblesort/.env | 2 +- examples/core/.env | 2 +- examples/fibonacci/.env | 2 +- examples/groups/.env | 2 +- examples/hackers-delight/ntzdebruijn/.env | 2 +- examples/hackers-delight/ntzgaudet/.env | 2 +- examples/hackers-delight/ntzloops/.env | 2 +- examples/hackers-delight/ntzmasks/.env | 2 +- examples/hackers-delight/ntzreisers/.env | 2 +- examples/hackers-delight/ntzseals/.env | 2 +- examples/hackers-delight/ntzsearchtree/.env | 2 +- examples/hackers-delight/ntzsmallvals/.env | 2 +- examples/helloworld/.env | 2 +- examples/interest/.env | 2 +- examples/lottery/.env | 2 +- examples/message/.env | 2 +- examples/simple_token/.env | 2 +- examples/tictactoe/.env | 2 +- examples/token/.env | 2 +- examples/token/run.sh | 14 +++++++------- examples/twoadicity/.env | 2 +- examples/vote/.env | 2 +- 29 files changed, 52 insertions(+), 52 deletions(-) diff --git a/.circleci/token/run.sh b/.circleci/token/run.sh index fb6e582a2a..812d1c2b85 100644 --- a/.circleci/token/run.sh +++ b/.circleci/token/run.sh @@ -21,7 +21,7 @@ fi echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Publicly mint 100 tokens for Alice. @@ -56,7 +56,7 @@ leo run mint_public aleo13ssze66adjjkt795z9u5wpq8h6kn0y2657726h4h3e3wfnez4vqsm30 echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Privately mint 100 tokens for Bob. @@ -91,7 +91,7 @@ leo run mint_private aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshd echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Publicly transfer 10 tokens from Alice to Bob. @@ -126,7 +126,7 @@ leo run transfer_public aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqy echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Privately transfer 20 tokens from Bob to Alice. @@ -165,7 +165,7 @@ leo run transfer_private "{ echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Convert 30 public tokens from Alice into 30 private tokens for Bob. @@ -201,7 +201,7 @@ leo run transfer_public_to_private aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4 echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Convert 40 private tokens from Bob into 40 public tokens for Alice. @@ -243,5 +243,5 @@ leo run transfer_private_to_public "{ echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env diff --git a/examples/auction/.env b/examples/auction/.env index 22a5c2dd00..f5b42ea894 100644 --- a/examples/auction/.env +++ b/examples/auction/.env @@ -1,4 +1,4 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/auction/run.sh b/examples/auction/run.sh index fa8e9a62d2..d94296f936 100755 --- a/examples/auction/run.sh +++ b/examples/auction/run.sh @@ -40,7 +40,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Have the first bidder place a bid of 10. @@ -63,7 +63,7 @@ leo run place_bid aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9p echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Have the second bidder place a bid of 90. @@ -86,7 +86,7 @@ leo run place_bid aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4 echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2GUmKbVsuc1NSj28pa1WTQuZaK5f1DQJAT6vPcHyWokG -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Have the auctioneer select the winning bid. @@ -144,7 +144,7 @@ leo run finish "{ echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env diff --git a/examples/basic_bank/.env b/examples/basic_bank/.env index 22a5c2dd00..f5b42ea894 100644 --- a/examples/basic_bank/.env +++ b/examples/basic_bank/.env @@ -1,4 +1,4 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/basic_bank/run.sh b/examples/basic_bank/run.sh index f29d079438..7ba84051f8 100755 --- a/examples/basic_bank/run.sh +++ b/examples/basic_bank/run.sh @@ -20,7 +20,7 @@ fi echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Have the bank issue 100 tokens to the user. @@ -71,7 +71,7 @@ leo run issue aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t 10 echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Have the user deposit 50 tokens into the bank. @@ -166,7 +166,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Have the bank withdraw all of the user's tokens with compound interest over 15 periods at 12.34%. diff --git a/examples/battleship/.env b/examples/battleship/.env index a4b3c79999..f0216e5f1b 100644 --- a/examples/battleship/.env +++ b/examples/battleship/.env @@ -1,5 +1,5 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/battleship/run.sh b/examples/battleship/run.sh index 42fe90a988..0f6d6eacae 100755 --- a/examples/battleship/run.sh +++ b/examples/battleship/run.sh @@ -19,7 +19,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env echo "✅ Successfully initialized Player 1." @@ -70,7 +70,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env leo run initialize_board 31u64 2207646875648u64 224u64 9042383626829824u64 aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t || exit @@ -119,7 +119,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env leo run play '{ @@ -155,7 +155,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env leo run play '{ @@ -191,7 +191,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env leo run play '{ @@ -227,7 +227,7 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env leo run play '{ @@ -256,5 +256,5 @@ echo " echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env diff --git a/examples/bubblesort/.env b/examples/bubblesort/.env index abae561342..ab80b96bf5 100644 --- a/examples/bubblesort/.env +++ b/examples/bubblesort/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/core/.env b/examples/core/.env index abae561342..ab80b96bf5 100644 --- a/examples/core/.env +++ b/examples/core/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/fibonacci/.env b/examples/fibonacci/.env index abae561342..ab80b96bf5 100644 --- a/examples/fibonacci/.env +++ b/examples/fibonacci/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/groups/.env b/examples/groups/.env index abae561342..ab80b96bf5 100644 --- a/examples/groups/.env +++ b/examples/groups/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/hackers-delight/ntzdebruijn/.env b/examples/hackers-delight/ntzdebruijn/.env index abae561342..ab80b96bf5 100644 --- a/examples/hackers-delight/ntzdebruijn/.env +++ b/examples/hackers-delight/ntzdebruijn/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/hackers-delight/ntzgaudet/.env b/examples/hackers-delight/ntzgaudet/.env index abae561342..ab80b96bf5 100644 --- a/examples/hackers-delight/ntzgaudet/.env +++ b/examples/hackers-delight/ntzgaudet/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/hackers-delight/ntzloops/.env b/examples/hackers-delight/ntzloops/.env index abae561342..ab80b96bf5 100644 --- a/examples/hackers-delight/ntzloops/.env +++ b/examples/hackers-delight/ntzloops/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/hackers-delight/ntzmasks/.env b/examples/hackers-delight/ntzmasks/.env index abae561342..ab80b96bf5 100644 --- a/examples/hackers-delight/ntzmasks/.env +++ b/examples/hackers-delight/ntzmasks/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/hackers-delight/ntzreisers/.env b/examples/hackers-delight/ntzreisers/.env index abae561342..ab80b96bf5 100644 --- a/examples/hackers-delight/ntzreisers/.env +++ b/examples/hackers-delight/ntzreisers/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/hackers-delight/ntzseals/.env b/examples/hackers-delight/ntzseals/.env index abae561342..ab80b96bf5 100644 --- a/examples/hackers-delight/ntzseals/.env +++ b/examples/hackers-delight/ntzseals/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/hackers-delight/ntzsearchtree/.env b/examples/hackers-delight/ntzsearchtree/.env index abae561342..ab80b96bf5 100644 --- a/examples/hackers-delight/ntzsearchtree/.env +++ b/examples/hackers-delight/ntzsearchtree/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/hackers-delight/ntzsmallvals/.env b/examples/hackers-delight/ntzsmallvals/.env index abae561342..ab80b96bf5 100644 --- a/examples/hackers-delight/ntzsmallvals/.env +++ b/examples/hackers-delight/ntzsmallvals/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/helloworld/.env b/examples/helloworld/.env index abae561342..ab80b96bf5 100644 --- a/examples/helloworld/.env +++ b/examples/helloworld/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/interest/.env b/examples/interest/.env index abae561342..ab80b96bf5 100644 --- a/examples/interest/.env +++ b/examples/interest/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/lottery/.env b/examples/lottery/.env index abae561342..ab80b96bf5 100644 --- a/examples/lottery/.env +++ b/examples/lottery/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/message/.env b/examples/message/.env index abae561342..ab80b96bf5 100644 --- a/examples/message/.env +++ b/examples/message/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/simple_token/.env b/examples/simple_token/.env index abae561342..ab80b96bf5 100644 --- a/examples/simple_token/.env +++ b/examples/simple_token/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/tictactoe/.env b/examples/tictactoe/.env index abae561342..ab80b96bf5 100644 --- a/examples/tictactoe/.env +++ b/examples/tictactoe/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/token/.env b/examples/token/.env index 22a5c2dd00..f5b42ea894 100644 --- a/examples/token/.env +++ b/examples/token/.env @@ -1,4 +1,4 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/token/run.sh b/examples/token/run.sh index a15525f8f9..69b9f81993 100755 --- a/examples/token/run.sh +++ b/examples/token/run.sh @@ -20,7 +20,7 @@ fi echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Publicly mint 100 tokens for Alice. @@ -55,7 +55,7 @@ leo run mint_public aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Privately mint 100 tokens for Bob. @@ -90,7 +90,7 @@ leo run mint_private aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Publicly transfer 10 tokens from Alice to Bob. @@ -125,7 +125,7 @@ leo run transfer_public aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5p echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Privately transfer 20 tokens from Bob to Alice. @@ -164,7 +164,7 @@ leo run transfer_private "{ echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Convert 30 public tokens from Alice into 30 private tokens for Bob. @@ -200,7 +200,7 @@ leo run transfer_public_to_private aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0x echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env # Convert 40 private tokens from Bob into 40 public tokens for Alice. @@ -242,5 +242,5 @@ leo run transfer_private_to_public "{ echo " NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 " > .env diff --git a/examples/twoadicity/.env b/examples/twoadicity/.env index abae561342..ab80b96bf5 100644 --- a/examples/twoadicity/.env +++ b/examples/twoadicity/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 diff --git a/examples/vote/.env b/examples/vote/.env index abae561342..ab80b96bf5 100644 --- a/examples/vote/.env +++ b/examples/vote/.env @@ -1,3 +1,3 @@ NETWORK=mainnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH -ENDPOINT=https://api.explorer.aleo.org/v1 +ENDPOINT=https://localhost:3030 From f25ce4cbccf68d1474d7f769351e8bcb084f77d7 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:40:56 -0700 Subject: [PATCH 12/20] error instead of panic on invalid balance --- errors/src/errors/cli/cli_errors.rs | 8 +++++++- leo/cli/commands/mod.rs | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/errors/src/errors/cli/cli_errors.rs b/errors/src/errors/cli/cli_errors.rs index 634cb6551a..7b37438e58 100644 --- a/errors/src/errors/cli/cli_errors.rs +++ b/errors/src/errors/cli/cli_errors.rs @@ -306,5 +306,11 @@ create_messages!( msg: "Failed to confirm transaction".to_string(), help: None, } - + + @backtraced + invalid_balance { + args: (account: impl Display), + msg: format!("Invalid public balance for account: {account}"), + help: Some("Make sure the account has enough balance to pay for the deployment.".to_string()), + } ); diff --git a/leo/cli/commands/mod.rs b/leo/cli/commands/mod.rs index d1bc4dcd0e..024e1ade26 100644 --- a/leo/cli/commands/mod.rs +++ b/leo/cli/commands/mod.rs @@ -261,8 +261,12 @@ fn check_balance( .execute(Context::new(context.path.clone(), context.home.clone(), true)?)?; // Remove the last 3 characters since they represent the `u64` suffix. public_balance.truncate(public_balance.len() - 3); - // This unwrap is safe as the Query will error if it cannot retrieve a public balance, and if it returns a balance that will be a u64. - let balance = public_balance.parse::().unwrap(); + // Make sure the balance is valid. + let balance = if let Ok(credits) = public_balance.parse::() { + credits + } else { + return Err(CliError::invalid_balance(address).into()); + }; // Compare balance. if balance < total_cost { Err(PackageError::insufficient_balance(address, public_balance, total_cost).into()) From b3d712bb15fd6c011ffed9926c7b85f3d15c242c Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:16:13 -0700 Subject: [PATCH 13/20] remove unwraps --- errors/src/errors/cli/cli_errors.rs | 7 +++++++ errors/src/errors/utils/util_errors.rs | 7 +++++++ leo/cli/commands/deploy.rs | 7 ++++--- leo/cli/commands/execute.rs | 20 +++++++++++--------- leo/cli/commands/query/block.rs | 5 ++++- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/errors/src/errors/cli/cli_errors.rs b/errors/src/errors/cli/cli_errors.rs index 7b37438e58..aedf394d95 100644 --- a/errors/src/errors/cli/cli_errors.rs +++ b/errors/src/errors/cli/cli_errors.rs @@ -313,4 +313,11 @@ create_messages!( msg: format!("Invalid public balance for account: {account}"), help: Some("Make sure the account has enough balance to pay for the deployment.".to_string()), } + + @backtraced + table_render_failed { + args: (error: impl Display), + msg: format!("Failed to render table.\nError: {error}"), + help: None, + } ); diff --git a/errors/src/errors/utils/util_errors.rs b/errors/src/errors/utils/util_errors.rs index dbab5af28d..cc92ac5435 100644 --- a/errors/src/errors/utils/util_errors.rs +++ b/errors/src/errors/utils/util_errors.rs @@ -193,4 +193,11 @@ create_messages!( msg: format!("Invalid field: {field}."), help: Some("Field element must be numerical string with optional \"field\" suffix.".to_string()), } + + @backtraced + invalid_bound { + args: (bound: impl Display), + msg: format!("Invalid bound: {bound}."), + help: Some("Bound must be a valid u32.".to_string()), + } ); diff --git a/leo/cli/commands/deploy.rs b/leo/cli/commands/deploy.rs index 05f4939e82..640868da80 100644 --- a/leo/cli/commands/deploy.rs +++ b/leo/cli/commands/deploy.rs @@ -228,7 +228,7 @@ fn deploy_cost_breakdown( synthesis_cost: f64, namespace_cost: f64, priority_fee: f64, -) { +) -> Result<()> { println!("\nBase deployment cost for '{}' is {} credits.\n", name.bold(), total_cost); // Display the cost breakdown in a table. let data = [ @@ -240,6 +240,7 @@ fn deploy_cost_breakdown( ["Total", &format!("{:.6}", total_cost)], ]; let mut out = Vec::new(); - text_tables::render(&mut out, data).unwrap(); - println!("{}", ::std::str::from_utf8(&out).unwrap()); + text_tables::render(&mut out, data).map_err(|err| CliError::table_render_failed(err))?; + println!("{}", ::std::str::from_utf8(&out).map_err(|err| CliError::table_render_failed(err))?); + Ok(()) } diff --git a/leo/cli/commands/execute.rs b/leo/cli/commands/execute.rs index b37fd17941..63aa8bbc4c 100644 --- a/leo/cli/commands/execute.rs +++ b/leo/cli/commands/execute.rs @@ -254,13 +254,14 @@ fn handle_execute( // Load the package. let package = SnarkVMPackage::open(&path)?; // Convert the inputs. - let inputs = inputs - .iter() - .map(|input| Value::from_str(input).map_err(PackageError::snarkvm_error).unwrap()) - .collect::>>(); + let mut parsed_inputs: Vec> = Vec::new(); + for input in inputs.iter() { + let value = Value::from_str(input)?; + parsed_inputs.push(value); + } // Execute the request. let (response, execution, metrics) = package - .execute::(endpoint.to_string(), &private_key, Identifier::try_from(command.name.clone())?, &inputs, rng) + .execute::(endpoint.to_string(), &private_key, Identifier::try_from(command.name.clone())?, &parsed_inputs, rng) .map_err(PackageError::execution_error)?; let fee = None; @@ -343,7 +344,7 @@ fn load_program_from_network( }, } .execute(Context::new(context.path.clone(), context.home.clone(), true)?)?; - let program = SnarkVMProgram::::from_str(&program_src).unwrap(); + let program = SnarkVMProgram::::from_str(&program_src)?; // Return early if the program is already loaded. if process.contains_program(program.id()) { @@ -368,7 +369,7 @@ fn load_program_from_network( } // A helper function to display a cost breakdown of the execution. -fn execution_cost_breakdown(name: &String, total_cost: f64, storage_cost: f64, finalize_cost: f64, priority_fee: f64) { +fn execution_cost_breakdown(name: &String, total_cost: f64, storage_cost: f64, finalize_cost: f64, priority_fee: f64) -> Result<()> { println!("\nBase execution cost for '{}' is {} credits.\n", name.bold(), total_cost); // Display the cost breakdown in a table. let data = [ @@ -379,6 +380,7 @@ fn execution_cost_breakdown(name: &String, total_cost: f64, storage_cost: f64, f ["Total", &format!("{:.6}", total_cost)], ]; let mut out = Vec::new(); - text_tables::render(&mut out, data).unwrap(); - println!("{}", std::str::from_utf8(&out).unwrap()); + text_tables::render(&mut out, data).map_err(|err| CliError::table_render_failed(err))?; + println!("{}", std::str::from_utf8(&out).map_err(|err| CliError::table_render_failed(err))?); + Ok(()) } diff --git a/leo/cli/commands/query/block.rs b/leo/cli/commands/query/block.rs index 84ef81f9e8..def8386fb8 100644 --- a/leo/cli/commands/query/block.rs +++ b/leo/cli/commands/query/block.rs @@ -69,8 +69,11 @@ impl Command for Block { is_valid_numerical_input(&range[0])?; is_valid_numerical_input(&range[1])?; + // Parse the range values. + let end = &range[1].parse::().map_err(|_| UtilError::invalid_bound(&range[1]))?; + let start = &range[0].parse::().map_err(|_| UtilError::invalid_bound(&range[0]))?; // Make sure the range is not too large. - if range[1].parse::().unwrap() - range[0].parse::().unwrap() > 50 { + if end - start > 50 { return Err(UtilError::invalid_range().into()); } format!("blocks?start={}&end={}", range[0], range[1]) From 92a0ff4c28f114a1cd6e5633d9b26b4c1fe3f7d0 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:17:56 -0700 Subject: [PATCH 14/20] clippy --- errors/src/errors/cli/cli_errors.rs | 4 ++-- errors/src/errors/utils/util_errors.rs | 2 +- leo/cli/commands/deploy.rs | 6 +++--- leo/cli/commands/execute.rs | 22 +++++++++++++++++----- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/errors/src/errors/cli/cli_errors.rs b/errors/src/errors/cli/cli_errors.rs index aedf394d95..556fdec39e 100644 --- a/errors/src/errors/cli/cli_errors.rs +++ b/errors/src/errors/cli/cli_errors.rs @@ -306,14 +306,14 @@ create_messages!( msg: "Failed to confirm transaction".to_string(), help: None, } - + @backtraced invalid_balance { args: (account: impl Display), msg: format!("Invalid public balance for account: {account}"), help: Some("Make sure the account has enough balance to pay for the deployment.".to_string()), } - + @backtraced table_render_failed { args: (error: impl Display), diff --git a/errors/src/errors/utils/util_errors.rs b/errors/src/errors/utils/util_errors.rs index cc92ac5435..da25660922 100644 --- a/errors/src/errors/utils/util_errors.rs +++ b/errors/src/errors/utils/util_errors.rs @@ -193,7 +193,7 @@ create_messages!( msg: format!("Invalid field: {field}."), help: Some("Field element must be numerical string with optional \"field\" suffix.".to_string()), } - + @backtraced invalid_bound { args: (bound: impl Display), diff --git a/leo/cli/commands/deploy.rs b/leo/cli/commands/deploy.rs index 640868da80..08cd8897c5 100644 --- a/leo/cli/commands/deploy.rs +++ b/leo/cli/commands/deploy.rs @@ -148,7 +148,7 @@ fn handle_deploy, N: Network>( synthesis_cost as f64 / 1_000_000.0, namespace_cost as f64 / 1_000_000.0, command.fee_options.priority_fee as f64 / 1_000_000.0, - ); + )?; // Initialize an RNG. let rng = &mut rand::thread_rng(); @@ -240,7 +240,7 @@ fn deploy_cost_breakdown( ["Total", &format!("{:.6}", total_cost)], ]; let mut out = Vec::new(); - text_tables::render(&mut out, data).map_err(|err| CliError::table_render_failed(err))?; - println!("{}", ::std::str::from_utf8(&out).map_err(|err| CliError::table_render_failed(err))?); + text_tables::render(&mut out, data).map_err(CliError::table_render_failed)?; + println!("{}", ::std::str::from_utf8(&out).map_err(CliError::table_render_failed)?); Ok(()) } diff --git a/leo/cli/commands/execute.rs b/leo/cli/commands/execute.rs index 63aa8bbc4c..ce07e70153 100644 --- a/leo/cli/commands/execute.rs +++ b/leo/cli/commands/execute.rs @@ -207,7 +207,7 @@ fn handle_execute( storage_cost as f64 / 1_000_000.0, finalize_cost as f64 / 1_000_000.0, command.fee_options.priority_fee as f64 / 1_000_000.0, - ); + )?; // Check if the public balance is sufficient. if fee_record.is_none() { @@ -261,7 +261,13 @@ fn handle_execute( } // Execute the request. let (response, execution, metrics) = package - .execute::(endpoint.to_string(), &private_key, Identifier::try_from(command.name.clone())?, &parsed_inputs, rng) + .execute::( + endpoint.to_string(), + &private_key, + Identifier::try_from(command.name.clone())?, + &parsed_inputs, + rng, + ) .map_err(PackageError::execution_error)?; let fee = None; @@ -369,7 +375,13 @@ fn load_program_from_network( } // A helper function to display a cost breakdown of the execution. -fn execution_cost_breakdown(name: &String, total_cost: f64, storage_cost: f64, finalize_cost: f64, priority_fee: f64) -> Result<()> { +fn execution_cost_breakdown( + name: &String, + total_cost: f64, + storage_cost: f64, + finalize_cost: f64, + priority_fee: f64, +) -> Result<()> { println!("\nBase execution cost for '{}' is {} credits.\n", name.bold(), total_cost); // Display the cost breakdown in a table. let data = [ @@ -380,7 +392,7 @@ fn execution_cost_breakdown(name: &String, total_cost: f64, storage_cost: f64, f ["Total", &format!("{:.6}", total_cost)], ]; let mut out = Vec::new(); - text_tables::render(&mut out, data).map_err(|err| CliError::table_render_failed(err))?; - println!("{}", std::str::from_utf8(&out).map_err(|err| CliError::table_render_failed(err))?); + text_tables::render(&mut out, data).map_err(CliError::table_render_failed)?; + println!("{}", std::str::from_utf8(&out).map_err(CliError::table_render_failed)?); Ok(()) } From c621ad4bd9672f1cb613ffbc41728a5792e31551 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 10:42:45 +0000 Subject: [PATCH 15/20] Bump clap from 4.5.7 to 4.5.8 Bumps [clap](https://github.com/clap-rs/clap) from 4.5.7 to 4.5.8. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.7...v4.5.8) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5099dad311..afb074f279 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -429,9 +429,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.7" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" +checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" dependencies = [ "clap_builder", "clap_derive", @@ -439,9 +439,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.7" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" +checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" dependencies = [ "anstream", "anstyle", @@ -451,9 +451,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.5" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" +checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" dependencies = [ "heck", "proc-macro2", From 057df0b54e2be5a2534e0789b8fc8c495c7e2fb6 Mon Sep 17 00:00:00 2001 From: d0cd <23022326+d0cd@users.noreply.github.com> Date: Mon, 1 Jul 2024 09:51:22 -0700 Subject: [PATCH 16/20] Update errors/src/errors/package/package_errors.rs Signed-off-by: d0cd <23022326+d0cd@users.noreply.github.com> --- errors/src/errors/package/package_errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errors/src/errors/package/package_errors.rs b/errors/src/errors/package/package_errors.rs index b5b7c93d2e..74ce8eada6 100644 --- a/errors/src/errors/package/package_errors.rs +++ b/errors/src/errors/package/package_errors.rs @@ -422,7 +422,7 @@ create_messages!( @backtraced snarkvm_error { args: (error: impl Display), - msg: format!("{error}"), + msg: format!("[snarkVM Error] {error}"), help: None, } From a547efa7665b273e92e280e4adfa24a4b2ca7237 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Mon, 1 Jul 2024 11:15:43 -0700 Subject: [PATCH 17/20] update snarkvm dep --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8c41b5421b..15d1038f27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ members = [ [workspace.dependencies.snarkvm] #version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "8a05317" +rev = "d170a9f" [lib] path = "leo/lib.rs" From 3659d1f54c385a58c31569bf288bbb66efd81d53 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Mon, 1 Jul 2024 15:45:00 -0700 Subject: [PATCH 18/20] usability enhancements --- leo/cli/commands/execute.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/leo/cli/commands/execute.rs b/leo/cli/commands/execute.rs index ce07e70153..cee8dc6e84 100644 --- a/leo/cli/commands/execute.rs +++ b/leo/cli/commands/execute.rs @@ -67,6 +67,8 @@ pub struct Execute { compiler_options: BuildOptions, #[arg(short, long, help = "The inputs to the program, from a file. Overrides the INPUTS argument.")] file: Option, + #[clap(long, help = "Disables building of the project before execution.", default_value = "false")] + pub(crate) no_build: bool, } impl Command for Execute { @@ -79,7 +81,7 @@ impl Command for Execute { fn prelude(&self, context: Context) -> Result { // No need to build if we are executing an external program. - if self.program.is_some() { + if self.program.is_some() || self.no_build { return Ok(()); } (Build { options: self.compiler_options.clone() }).execute(context) @@ -148,7 +150,7 @@ fn handle_execute( // Get the program name. let program_name = match (command.program.clone(), command.local) { (Some(name), true) => { - let local = context.open_manifest::()?.program_id().to_string(); + let local = context.open_manifest::()?.program_id().name().to_string(); // Throw error if local name doesn't match the specified name. if name == local { local @@ -157,7 +159,7 @@ fn handle_execute( } } (Some(name), false) => name.clone(), - (None, true) => context.open_manifest::()?.program_id().to_string(), + (None, true) => context.open_manifest::()?.program_id().name().to_string(), (None, false) => return Err(PackageError::missing_on_chain_program_name().into()), }; From e7ed2021df281c2999e3fb1b6d3befec9dd1ded8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:32:41 +0000 Subject: [PATCH 19/20] Bump self_update from 0.40.0 to 0.41.0 Bumps [self_update](https://github.com/jaemk/self_update) from 0.40.0 to 0.41.0. - [Release notes](https://github.com/jaemk/self_update/releases) - [Changelog](https://github.com/jaemk/self_update/blob/master/CHANGELOG.md) - [Commits](https://github.com/jaemk/self_update/commits) --- updated-dependencies: - dependency-name: self_update dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 167 +++++++++++++++++++++++++++++++++-------------------- Cargo.toml | 2 +- 2 files changed, 105 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 390ba99ce6..b9078f57e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,6 +196,15 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +dependencies = [ + "derive_arbitrary", +] + [[package]] name = "arrayref" version = "0.3.7" @@ -741,6 +750,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +dependencies = [ + "proc-macro2", + "quote 1.0.36", + "syn 2.0.66", +] + [[package]] name = "dialoguer" version = "0.11.0" @@ -812,6 +832,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote 1.0.36", + "syn 2.0.66", +] + [[package]] name = "doc-comment" version = "0.3.3" @@ -1612,7 +1643,7 @@ dependencies = [ "reqwest 0.12.5", "rpassword", "rusty-hook", - "self_update 0.40.0", + "self_update 0.41.0", "serde", "serde_json", "serial_test", @@ -2664,9 +2695,9 @@ dependencies = [ [[package]] name = "self_update" -version = "0.40.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4997484b55df069a4773d822715695b2cc27b23829eca2a4b41690e948bdeb" +checksum = "469a3970061380c19852269f393e74c0fe607a4e23d85267382cf25486aa8de5" dependencies = [ "hyper 1.3.1", "indicatif", @@ -2875,7 +2906,7 @@ dependencies = [ [[package]] name = "snarkvm" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "anstyle", "anyhow", @@ -2904,7 +2935,7 @@ dependencies = [ [[package]] name = "snarkvm-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -2934,7 +2965,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-account", "snarkvm-circuit-algorithms", @@ -2948,7 +2979,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-account" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-network", @@ -2959,7 +2990,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-types", "snarkvm-console-algorithms", @@ -2969,7 +3000,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-collections" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-types", @@ -2979,7 +3010,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap 2.2.6", "itertools 0.11.0", @@ -2997,12 +3028,12 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment-witness" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" [[package]] name = "snarkvm-circuit-network" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-collections", @@ -3013,7 +3044,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "paste", "snarkvm-circuit-account", @@ -3028,7 +3059,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-address", @@ -3043,7 +3074,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-address" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3056,7 +3087,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-boolean" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-console-types-boolean", @@ -3065,7 +3096,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-field" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3075,7 +3106,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-group" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3087,7 +3118,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-integers" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3099,7 +3130,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-scalar" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3110,7 +3141,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-string" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -3122,7 +3153,7 @@ dependencies = [ [[package]] name = "snarkvm-console" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-account", "snarkvm-console-algorithms", @@ -3135,7 +3166,7 @@ dependencies = [ [[package]] name = "snarkvm-console-account" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "bs58", "snarkvm-console-network", @@ -3146,7 +3177,7 @@ dependencies = [ [[package]] name = "snarkvm-console-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "blake2s_simd", "smallvec", @@ -3159,7 +3190,7 @@ dependencies = [ [[package]] name = "snarkvm-console-collections" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "rayon", @@ -3170,7 +3201,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "anyhow", "indexmap 2.2.6", @@ -3193,7 +3224,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network-environment" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "anyhow", "bech32", @@ -3211,7 +3242,7 @@ dependencies = [ [[package]] name = "snarkvm-console-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "enum-iterator", "enum_index", @@ -3233,7 +3264,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-address", @@ -3248,7 +3279,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-address" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3259,7 +3290,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-boolean" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", ] @@ -3267,7 +3298,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-field" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3277,7 +3308,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-group" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3288,7 +3319,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-integers" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3299,7 +3330,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-scalar" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3310,7 +3341,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-string" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -3321,7 +3352,7 @@ dependencies = [ [[package]] name = "snarkvm-curves" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "rand", "rayon", @@ -3335,7 +3366,7 @@ dependencies = [ [[package]] name = "snarkvm-fields" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -3352,7 +3383,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -3376,7 +3407,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-authority" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "anyhow", "rand", @@ -3388,7 +3419,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-block" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3407,7 +3438,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-committee" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3419,7 +3450,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-ledger-narwhal-batch-certificate", "snarkvm-ledger-narwhal-batch-header", @@ -3432,7 +3463,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-certificate" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3445,7 +3476,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-header" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3457,7 +3488,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-data" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "bytes", "serde_json", @@ -3468,7 +3499,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-subdag" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap 2.2.6", "rayon", @@ -3483,7 +3514,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-transmission" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "bytes", "serde_json", @@ -3496,7 +3527,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-transmission-id" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "snarkvm-console", "snarkvm-ledger-puzzle", @@ -3505,7 +3536,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-puzzle" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -3525,22 +3556,28 @@ dependencies = [ [[package]] name = "snarkvm-ledger-puzzle-epoch" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ + "aleo-std", "anyhow", "colored", "indexmap 2.2.6", + "lru", + "parking_lot", "rand", "rand_chacha", "rayon", + "snarkvm-circuit", "snarkvm-console", "snarkvm-ledger-puzzle", + "snarkvm-synthesizer-process", + "snarkvm-synthesizer-program", ] [[package]] name = "snarkvm-ledger-query" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "async-trait", "reqwest 0.11.27", @@ -3553,7 +3590,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-store" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std-storage", "anyhow", @@ -3576,7 +3613,7 @@ dependencies = [ [[package]] name = "snarkvm-parameters" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -3601,7 +3638,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -3631,7 +3668,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-process" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "colored", @@ -3654,7 +3691,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "indexmap 2.2.6", "paste", @@ -3668,7 +3705,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-snark" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "bincode", "once_cell", @@ -3681,7 +3718,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "aleo-std", "anyhow", @@ -3702,7 +3739,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities-derives" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=8a05317#8a053177f46dc4383d5a8adcc6b14e4c73f34c82" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=d170a9f#d170a9f7c5ef980f9392301dc899dee355599ca6" dependencies = [ "proc-macro2", "quote 1.0.36", @@ -4622,13 +4659,17 @@ dependencies = [ [[package]] name = "zip" -version = "0.6.6" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +checksum = "775a2b471036342aa69bc5a602bc889cb0a06cda00477d0c69566757d5553d39" dependencies = [ - "byteorder", + "arbitrary", "crc32fast", "crossbeam-utils", + "displaydoc", + "indexmap 2.2.6", + "memchr", + "thiserror", "time", ] diff --git a/Cargo.toml b/Cargo.toml index 9f9c1c7d6f..facd11cdf6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -142,7 +142,7 @@ version = "0.12.5" features = [ "blocking", "json", "multipart" ] [dependencies.self_update] -version = "0.40.0" +version = "0.41.0" features = [ "archive-zip" ] [dependencies.serde] From 5c2ba3e1073e1953ab3f3ce6ce8f65b448be28ea Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Wed, 3 Jul 2024 09:02:14 -0700 Subject: [PATCH 20/20] Fix and improve some doc. --- compiler/parser/src/parser/context.rs | 6 ++--- compiler/parser/src/parser/file.rs | 9 +++---- compiler/parser/src/parser/mod.rs | 6 ++--- compiler/parser/src/tokenizer/lexer.rs | 33 ++++++++++++++++---------- compiler/parser/src/tokenizer/token.rs | 14 +++++++---- errors/src/common/mod.rs | 2 +- errors/src/errors/mod.rs | 18 +++++++------- errors/src/lib.rs | 4 ++-- 8 files changed, 52 insertions(+), 40 deletions(-) diff --git a/compiler/parser/src/parser/context.rs b/compiler/parser/src/parser/context.rs index 8639412447..da9ade6085 100644 --- a/compiler/parser/src/parser/context.rs +++ b/compiler/parser/src/parser/context.rs @@ -39,7 +39,7 @@ pub(crate) struct ParserContext<'a, N: Network> { /// The previous token, i.e., if `p.tokens = ['3', *, '4']`, /// then after two `p.bump()`s, we'll have `p.token = '*'` and `p.prev_token = '3'`. pub(crate) prev_token: SpannedToken, - /// true if parsing an expression for if and loop statements -- means struct inits are not legal + /// True if parsing an expression for if and loop statements -- means struct inits are not legal. pub(crate) disallow_struct_construction: bool, /// The name of the program being parsed. pub(crate) program_name: Option, @@ -95,7 +95,7 @@ impl<'a, N: Network> ParserContext<'a, N> { &self.token.token == tok } - /// Checks whether the current token is a `Token::Int(_)`. + /// Checks whether the current token is a `Token::Integer(_)`. pub(super) fn check_int(&self) -> bool { matches!(&self.token.token, Token::Integer(_)) } @@ -142,7 +142,7 @@ impl<'a, N: Network> ParserContext<'a, N> { Identifier { name, span, id: self.node_builder.next_id() } } - /// Eats the next token if its an identifier and returns it. + /// Eats the next token if it is an identifier and returns it. pub(super) fn eat_identifier(&mut self) -> Option { if let Token::Identifier(name) = self.token.token { self.bump(); diff --git a/compiler/parser/src/parser/file.rs b/compiler/parser/src/parser/file.rs index 06d844a987..3cd50e1809 100644 --- a/compiler/parser/src/parser/file.rs +++ b/compiler/parser/src/parser/file.rs @@ -75,11 +75,12 @@ impl ParserContext<'_, N> { // Parse `foo`. let import_name = self.expect_identifier()?; - // Parse `.aleo`. + // Parse `.`. self.expect(&Token::Dot)?; + // Parse network, which currently must be `aleo`. if !self.eat(&Token::Aleo) { - // Throw error for non-aleo files. + // Throw error for non-aleo networks. return Err(ParserError::invalid_network(self.token.span).into()); } @@ -100,10 +101,10 @@ impl ParserContext<'_, N> { // Set the program name in the context. self.program_name = Some(name.name); - // Parse the program network. + // Parse the `.`. self.expect(&Token::Dot)?; - // Otherwise throw parser error + // Parse the program network, which must be `aleo`, otherwise throw parser error. self.expect(&Token::Aleo).map_err(|_| ParserError::invalid_network(self.token.span))?; // Construct the program id. diff --git a/compiler/parser/src/parser/mod.rs b/compiler/parser/src/parser/mod.rs index 7a6ee0d571..33e350a893 100644 --- a/compiler/parser/src/parser/mod.rs +++ b/compiler/parser/src/parser/mod.rs @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -//! The parser to convert Leo code text into an [`Program`] AST type. +//! The parser to convert Leo code text into a [`Program`] AST type. //! -//! This module contains the [`parse()`] method which calls the underlying [`tokenize()`] -//! method to create a new program ast. +//! This module contains the [`parse()`] function which calls the underlying [`tokenize()`] +//! method to create a new program AST. use crate::{tokenizer::*, Token}; diff --git a/compiler/parser/src/tokenizer/lexer.rs b/compiler/parser/src/tokenizer/lexer.rs index fbe5bb7864..a7c33af1e7 100644 --- a/compiler/parser/src/tokenizer/lexer.rs +++ b/compiler/parser/src/tokenizer/lexer.rs @@ -154,8 +154,15 @@ impl Token { // } // } - /// Returns a tuple: [(integer length, integer token)] if an integer can be eaten, otherwise returns [`None`]. - /// An integer can be eaten if its bytes are at the front of the given `input` string. + /// Returns a tuple: [(integer length, integer token)] if an integer can be eaten. + /// An integer can be eaten if its characters are at the front of the given `input` string. + /// If there is no input, this function returns an error. + /// If there is input but no integer, this function returns the tuple consisting of + /// length 0 and a dummy integer token that contains an empty string. + /// However, this function is always called when the next character is a digit. + /// This function eats a sequence of one or more digits and underscores + /// (starting from a digit, as explained above, given when it is called), + /// which corresponds to a numeral in the ABNF grammar. fn eat_integer(input: &mut Peekable>) -> Result<(usize, Token)> { if input.peek().is_none() { return Err(ParserError::lexer_empty_input().into()); @@ -178,7 +185,7 @@ impl Token { } /// Returns a tuple: [(token length, token)] if the next token can be eaten, otherwise returns an error. - /// The next token can be eaten if the bytes at the front of the given `input` string can be scanned into a token. + /// The next token can be eaten if the characters at the front of the given `input` string can be scanned into a token. pub(crate) fn eat(input: &str) -> Result<(usize, Token)> { if input.is_empty() { return Err(ParserError::lexer_empty_input().into()); @@ -221,13 +228,13 @@ impl Token { // See the example with the different combinations for Mul, MulAssign, Pow, PowAssign below. let match_four = | input: &mut Peekable<_>, - first_token, // Mul '*' - second_char, // '=' - second_token, // MulAssign '*=' - third_char, // '*' - third_token, // Pow '**' - fourth_char, // '=' - fourth_token // PowAssign '**=' + first_token, // e.e. Mul '*' + second_char, // e.g. '=' + second_token, // e.g. MulAssign '*=' + third_char, // e.g. '*' + third_token, // e.g. Pow '**' + fourth_char, // e.g. '=' + fourth_token // e.g. PowAssign '**=' | { input.next(); Ok(if input.next_if_eq(&second_char).is_some() { @@ -252,7 +259,7 @@ impl Token { // Find end string quotation mark. // Instead of checking each `char` and pushing, we can avoid reallocations. // This works because the code 34 of double quote cannot appear as a byte - // in middle of a multi-byte UTF-8 encoding of a character, + // in the middle of a multi-byte UTF-8 encoding of a character, // because those bytes all have the high bit set to 1; // in UTF-8, the byte 34 can only appear as the single-byte encoding of double quote. let rest = &input_str[1..]; @@ -306,7 +313,7 @@ impl Token { if input.next_if_eq(&'/').is_some() { // Find the end of the comment line. // This works because the code 10 of line feed cannot appear as a byte - // in middle of a multi-byte UTF-8 encoding of a character, + // in the middle of a multi-byte UTF-8 encoding of a character, // because those bytes all have the high bit set to 1; // in UTF-8, the byte 10 can only appear as the single-byte encoding of line feed. let comment = match input_str.as_bytes().iter().position(|c| *c == b'\n') { @@ -416,8 +423,8 @@ impl Token { "record" => Token::Record, "return" => Token::Return, "scalar" => Token::Scalar, - "signature" => Token::Signature, "self" => Token::SelfLower, + "signature" => Token::Signature, "string" => Token::String, "struct" => Token::Struct, "transition" => Token::Transition, diff --git a/compiler/parser/src/tokenizer/token.rs b/compiler/parser/src/tokenizer/token.rs index ce76068b84..f810cea96c 100644 --- a/compiler/parser/src/tokenizer/token.rs +++ b/compiler/parser/src/tokenizer/token.rs @@ -29,20 +29,24 @@ use leo_span::{sym, Symbol}; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum Token { // Comments - CommentLine(String), - CommentBlock(String), + CommentLine(String), // the string includes the starting '//' and the ending line feed + CommentBlock(String), // the string includes the starting '/*' and the ending '*/' // Whitespace (we do not distinguish among different kinds here) WhiteSpace, // Literals (= atomic literals and numerals in the ABNF grammar) - // The string in Integer(String) consists of digits optionally followed by a type - // The string in AddressLit(String) has the form `aleo1...` + // The string in Integer(String) consists of digits + // The string in AddressLit(String) has the form `aleo1...`. True, False, - Integer(String), // = numeric literal or numeral in the ABNF grammar + Integer(String), // = numeral (including tuple index) in the ABNF grammar AddressLit(String), StaticString(String), + // The numeric literals in the ABNF grammar, which consist of numerals followed by types, + // are represented not as single tokens here, + // but as two separate tokens (one for the numeral and one for the type), + // enforcing, during parsing, the absence of whitespace or comments between those two tokens. // Identifiers Identifier(Symbol), diff --git a/errors/src/common/mod.rs b/errors/src/common/mod.rs index 3a580f97f4..41c10ce326 100644 --- a/errors/src/common/mod.rs +++ b/errors/src/common/mod.rs @@ -32,7 +32,7 @@ pub use self::traits::*; // Right now for cleanliness of calling error functions we say each argument implements one of the follow types rather than giving a specific type. // This allows us to just pass many types rather doing conversions cleaning up the code. -// The args can be made cleaneronce https://github.com/rust-lang/rust/issues/41517 or https://github.com/rust-lang/rust/issues/63063 hits stable. +// The args can be made cleaner once https://github.com/rust-lang/rust/issues/41517 or https://github.com/rust-lang/rust/issues/63063 hits stable. // Either of why would allows to generate a type alias for these trait implementing types. // pub(crate) type DisplayArg = impl std::fmt::Display; // pub(crate) type DebugArg = impl std::fmt::Debug; diff --git a/errors/src/errors/mod.rs b/errors/src/errors/mod.rs index f52f608696..c99242d405 100644 --- a/errors/src/errors/mod.rs +++ b/errors/src/errors/mod.rs @@ -60,16 +60,16 @@ pub enum LeoError { /// Represents an AST Error in a Leo Error. #[error(transparent)] AstError(#[from] AstError), - /// Represents an CLI Error in a Leo Error. + /// Represents a CLI Error in a Leo Error. #[error(transparent)] CliError(#[from] CliError), - /// Represents an Compiler Error in a Leo Error. + /// Represents a Compiler Error in a Leo Error. #[error(transparent)] CompilerError(#[from] CompilerError), - /// Represents an Package Error in a Leo Error. + /// Represents a Package Error in a Leo Error. #[error(transparent)] PackageError(#[from] PackageError), - /// Represents an Parser Error in a Leo Error. + /// Represents a Parser Error in a Leo Error. #[error(transparent)] ParserError(#[from] ParserError), /// Represents a Type Checker Error in a Leo Error. @@ -85,7 +85,7 @@ pub enum LeoError { /// not re-displaying an error. #[error("")] LastErrorCode(i32), - /// Represents a Utils Error in a Leo Error + /// Represents a Utils Error in a Leo Error. #[error(transparent)] UtilError(#[from] UtilError), /// Anyhow errors. @@ -133,14 +133,14 @@ impl LeoError { } } -/// The LeoWarning type that contains all sub error types. -/// This allows a unified error type throughout the Leo crates. +/// The LeoWarning type that contains all sub warning types. +/// This allows a unified warning type throughout the Leo crates. #[derive(Debug, Error)] pub enum LeoWarning { - /// Represents an Parser Error in a Leo Error. + /// Represents an Parser Warning in a Leo Warning. #[error(transparent)] ParserWarning(#[from] ParserWarning), - /// Represents a Type Checker Error in a Leo Error. + /// Represents a Type Checker Warning in a Leo Warning. #[error(transparent)] TypeCheckerWarning(#[from] TypeCheckerWarning), } diff --git a/errors/src/lib.rs b/errors/src/lib.rs index eac73c9d90..55bfc9f5b7 100644 --- a/errors/src/lib.rs +++ b/errors/src/lib.rs @@ -21,7 +21,7 @@ #[macro_use] extern crate thiserror; -/// Contains the common functionalities for defining errors.. +/// Contains the common functionalities for defining errors. #[macro_use] pub mod common; pub use self::common::*; @@ -29,6 +29,6 @@ pub use self::common::*; /// Contains traits and types for channels through which errors go. pub mod emitter; -/// Contains the errors and warnings for the Leo lang. +/// Contains the errors and warnings for the Leo language. pub mod errors; pub use self::errors::*;