Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support --network selection in CLI. #27967

Merged
merged 14 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
347 changes: 74 additions & 273 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ version = "0.1"
version = "0.3.18"
features = [ "fmt" ]

[dependencies.zip]
version = "^2.1"

[dependencies.crossterm]
version = "0.27.0"

Expand Down
9 changes: 6 additions & 3 deletions compiler/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ features = [ ]
[dev-dependencies.leo-disassembler]
path = "../../utils/disassembler"

[dev-dependencies.leo-test-framework]
path = "../../tests/test-framework"

[dev-dependencies.leo-package]
path = "../../leo/package"

[dev-dependencies.leo-retriever]
path = "../../utils/retriever"

[dev-dependencies.leo-test-framework]
path = "../../tests/test-framework"

[dev-dependencies.aleo-std-storage]
version = "0.1.7"
default-features = false
Expand Down
16 changes: 13 additions & 3 deletions compiler/parser/examples/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ use std::{
path::{Path, PathBuf},
};

type CurrentNetwork = snarkvm::prelude::MainnetV0;

#[derive(Debug, Parser)]
#[clap(name = "leo parser", about = "Parse Leo AST and store it as a JSON")]
struct Opt {
Expand All @@ -40,6 +38,10 @@ struct Opt {
/// Whether to print result to STDOUT.
#[clap(short, long)]
print_stdout: bool,

/// The network to use. Defaults to mainnet.
#[clap(long, default_value = "mainnet")]
pub(crate) network: String,
}

fn main() -> Result<(), String> {
Expand All @@ -50,7 +52,15 @@ fn main() -> Result<(), String> {

Handler::with(|h| {
let node_builder = NodeBuilder::default();
let ast = leo_parser::parse_ast::<CurrentNetwork>(h, &node_builder, &code.src, code.start_pos)?;
let ast = match opt.network.as_str() {
"mainnet" => {
leo_parser::parse_ast::<snarkvm::prelude::MainnetV0>(h, &node_builder, &code.src, code.start_pos)
}
"testnet" => {
leo_parser::parse_ast::<snarkvm::prelude::TestnetV0>(h, &node_builder, &code.src, code.start_pos)
}
_ => panic!("Invalid network"),
}?;
let json = Ast::to_json_string(&ast)?;
println!("{json}");
Ok(json)
Expand Down
51 changes: 36 additions & 15 deletions errors/src/errors/cli/cli_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ create_messages!(
@backtraced
failed_to_load_instructions {
args: (error: impl Display),
msg: format!("Failed to load compiled Aleo instructions into an Aleo file.\nSnarkVM Error: {error}"),
msg: format!("Failed to load compiled Aleo instructions into an Aleo file.\nError: {error}"),
help: Some("Generated Aleo instructions have been left in `main.aleo`".to_string()),
}

Expand All @@ -107,84 +107,84 @@ create_messages!(
@backtraced
failed_to_execute_build {
args: (error: impl Display),
msg: format!("Failed to execute the `build` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `build` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_execute_new {
args: (error: impl Display),
msg: format!("Failed to execute the `new` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `new` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_execute_run {
args: (error: impl Display),
msg: format!("Failed to execute the `run` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `run` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_execute_node {
args: (error: impl Display),
msg: format!("Failed to execute the `node` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `node` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_execute_deploy {
args: (error: impl Display),
msg: format!("Failed to execute the `deploy` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `deploy` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_parse_new {
args: (error: impl Display),
msg: format!("Failed to parse the `new` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the `new` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_parse_run {
args: (error: impl Display),
msg: format!("Failed to parse the `run` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the `run` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_parse_node {
args: (error: impl Display),
msg: format!("Failed to parse the `node` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the `node` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_parse_deploy {
args: (error: impl Display),
msg: format!("Failed to parse the `deploy` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the `deploy` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_parse_execute {
args: (error: impl Display),
msg: format!("Failed to parse the `execute` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the `execute` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_execute_execute {
args: (error: impl Display),
msg: format!("Failed to execute the `execute` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `execute` command.\nError: {error}"),
help: None,
}

@backtraced
failed_to_parse_seed {
args: (error: impl Display),
msg: format!("Failed to parse the seed string for account.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the seed string for account.\nError: {error}"),
help: None,
}

Expand All @@ -198,14 +198,14 @@ create_messages!(
@backtraced
failed_to_parse_private_key {
args: (error: impl Display),
msg: format!("Failed to parse private key.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse private key.\nError: {error}"),
help: None,
}

@backtraced
failed_to_execute_account {
args: (error: impl Display),
msg: format!("Failed to execute the `account` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `account` command.\nError: {error}"),
help: None,
}

Expand All @@ -222,4 +222,25 @@ create_messages!(
msg: "Cannot combine recursive deploy with private fee.".to_string(),
help: None,
}

@backtraced
invalid_network_name {
args: (network: impl Display),
msg: format!("Invalid network name: {network}"),
help: Some("Valid network names are `testnet` and `mainnet`.".to_string()),
}

@backtraced
invalid_example {
args: (example: impl Display),
msg: format!("Invalid Leo example: {example}"),
help: Some("Valid Leo examples are `lottery`, `tictactoe`, and `token`.".to_string()),
}

@backtraced
build_error {
args: (error: impl Display),
msg: format!("Failed to build program: {error}"),
help: None,
}
);
13 changes: 10 additions & 3 deletions errors/src/errors/package/package_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,16 @@ create_messages!(
/// For when the package failed to initialize.
@backtraced
failed_to_initialize_package {
args: (package: impl Display, path: impl Debug),
msg: format!("failed to initialize package {package} {path:?}"),
args: (package: impl Display, path: impl Debug, error: impl Display),
msg: format!("Failed to initialize package {package} at {path:?}. Error: {error}"),
help: None,
}

/// For when the package has an invalid name.
@backtraced
invalid_package_name {
args: (package: impl Display),
msg: format!("invalid project name {package}"),
msg: format!("Invalid project name {package}"),
help: None,
}

Expand Down Expand Up @@ -397,4 +397,11 @@ create_messages!(
msg: "The name of the program to execute on-chain is missing.".to_string(),
help: Some("Either set `--local` to execute the local program on chain, or set `--program <PROGRAM>`.".to_string()),
}

@backtraced
failed_to_read_manifest_file {
args: (path: impl Display, error: impl ErrorArg),
msg: format!("Failed to read manifest file from the provided file path {path} - {error}"),
help: None,
}
);
2 changes: 1 addition & 1 deletion examples/battleship/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
outputs/
*.avm
*.prover
*.verifier
*.verifier
20 changes: 0 additions & 20 deletions examples/battleship/leo.lock

This file was deleted.

Loading
Loading