From 46774633f6966eec7182749dea33b21c3b93ac77 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Mon, 6 May 2024 14:46:13 -0700 Subject: [PATCH 1/7] rebase --- Cargo.lock | 1 + Cargo.toml | 3 + errors/src/errors/package/package_errors.rs | 14 +++ errors/src/errors/utils/util_errors.rs | 46 ++++++++- leo/cli/cli.rs | 8 +- leo/cli/commands/mod.rs | 3 + leo/cli/commands/query.rs | 102 ++++++++++++++++++++ leo/cli/mod.rs | 3 + leo/cli/query_commands/block.rs | 93 ++++++++++++++++++ leo/cli/query_commands/committee.rs | 40 ++++++++ leo/cli/query_commands/mod.rs | 99 +++++++++++++++++++ leo/cli/query_commands/program.rs | 64 ++++++++++++ leo/cli/query_commands/state_root.rs | 40 ++++++++ leo/cli/query_commands/transaction.rs | 68 +++++++++++++ utils/retriever/src/retriever/mod.rs | 2 +- 15 files changed, 582 insertions(+), 4 deletions(-) create mode 100644 leo/cli/commands/query.rs create mode 100644 leo/cli/query_commands/block.rs create mode 100644 leo/cli/query_commands/committee.rs create mode 100644 leo/cli/query_commands/mod.rs create mode 100644 leo/cli/query_commands/program.rs create mode 100644 leo/cli/query_commands/state_root.rs create mode 100644 leo/cli/query_commands/transaction.rs diff --git a/Cargo.lock b/Cargo.lock index aaa1f87a48..a4224833e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1972,6 +1972,7 @@ dependencies = [ "toml 0.8.12", "tracing", "tracing-subscriber", + "ureq", "walkdir", "zip", ] diff --git a/Cargo.toml b/Cargo.toml index 59ac10119d..670c706ded 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,9 @@ default = [ ] ci_skip = [ "leo-compiler/ci_skip" ] noconfig = [ ] +[dependencies] +ureq = "2.9.7" + [dependencies.leo-ast] path = "./compiler/ast" version = "=1.11.0" diff --git a/errors/src/errors/package/package_errors.rs b/errors/src/errors/package/package_errors.rs index b1d044cd17..f328648a9c 100644 --- a/errors/src/errors/package/package_errors.rs +++ b/errors/src/errors/package/package_errors.rs @@ -383,4 +383,18 @@ create_messages!( msg: format!("The dependency program `{name}` was not found among the manifest's dependencies."), help: None, } + + @backtraced + conflicting_on_chain_program_name { + args: (first: impl Display, second: impl Display), + msg: format!("Conflicting program names given to execute on chain: `{first}` and `{second}`."), + help: Some("Either set `--local` to execute the local program on chain, or set `--program `.".to_string()), + } + + @backtraced + missing_on_chain_program_name { + args: (), + 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 `.".to_string()), + } ); diff --git a/errors/src/errors/utils/util_errors.rs b/errors/src/errors/utils/util_errors.rs index 903a721945..b5dacb4286 100644 --- a/errors/src/errors/utils/util_errors.rs +++ b/errors/src/errors/utils/util_errors.rs @@ -140,8 +140,8 @@ create_messages!( @formatted failed_to_retrieve_from_endpoint { - args: (endpoint: impl Display, error: impl ErrorArg), - msg: format!("Failed to retrieve from endpoint `{endpoint}`. Error: {error}"), + args: (error: impl ErrorArg), + msg: format!("{error}"), help: None, } @@ -151,4 +151,46 @@ create_messages!( msg: format!("Compiled file at `{path}` does not exist, cannot compile parent."), help: Some("If you were using the `--non-recursive` flag, remove it and try again.".to_string()), } + + @backtraced + invalid_input_id_len { + args: (input: impl Display, expected_type: impl Display), + msg: format!("Invalid input: {input}."), + help: Some(format!("Type `{expected_type}` must contain exactly 61 lowercase characters or numbers.")), + } + + @backtraced + invalid_input_id { + args: (input: impl Display, expected_type: impl Display, expected_preface: impl Display), + msg: format!("Invalid input: {input}."), + help: Some(format!("Type `{expected_type}` must start with \"{expected_preface}\".")), + } + + @backtraced + invalid_numerical_input { + args: (input: impl Display), + msg: format!("Invalid numerical input: {input}."), + help: Some("Input must be a valid u32.".to_string()), + } + + @backtraced + invalid_range { + args: (), + msg: "The range must be less than or equal to 50 blocks.".to_string(), + help: None, + } + + @backtraced + invalid_height_or_hash { + args: (input: impl Display), + msg: format!("Invalid input: {input}."), + help: Some("Input must be a valid height or hash. Valid hashes are 61 characters long, composed of only numbers and lower case letters, and be prefaced with \"ab1\".".to_string()), + } + + @backtraced + invalid_field { + args: (field: impl Display), + msg: format!("Invalid field: {field}."), + help: Some("Field element must be numerical string with optional \"field\" suffix.".to_string()), + } ); diff --git a/leo/cli/cli.rs b/leo/cli/cli.rs index c6dc0d9f82..631ee5063e 100644 --- a/leo/cli/cli.rs +++ b/leo/cli/cli.rs @@ -36,7 +36,7 @@ pub struct CLI { #[clap(long, global = true, help = "Path to Leo program root folder")] path: Option, - #[clap(long, global = true, help = "Path to aleo program registry.")] + #[clap(long, global = true, help = "Path to aleo program registry")] pub home: Option, } @@ -73,6 +73,11 @@ enum Commands { #[clap(flatten)] command: Deploy, }, + #[clap(about = "Query live data from the Aleo network")] + Query { + #[clap(flatten)] + command: Query, + }, #[clap(about = "Compile the current package as a program")] Build { #[clap(flatten)] @@ -144,6 +149,7 @@ pub fn run_with_args(cli: CLI) -> Result<()> { command.try_execute(context) } + Commands::Query { command } => command.try_execute(context), Commands::Clean { command } => command.try_execute(context), Commands::Deploy { command } => command.try_execute(context), Commands::Example { command } => command.try_execute(context), diff --git a/leo/cli/commands/mod.rs b/leo/cli/commands/mod.rs index 26c963d121..b4d7dc92c4 100644 --- a/leo/cli/commands/mod.rs +++ b/leo/cli/commands/mod.rs @@ -35,6 +35,9 @@ pub use example::Example; pub mod execute; pub use execute::Execute; +pub mod query; +pub use query::Query; + pub mod new; pub use new::New; diff --git a/leo/cli/commands/query.rs b/leo/cli/commands/query.rs new file mode 100644 index 0000000000..10be77850b --- /dev/null +++ b/leo/cli/commands/query.rs @@ -0,0 +1,102 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use super::*; + +use leo_errors::UtilError; + +/// 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 http://api.explorer.aleo.org/v1.", + default_value = "http://api.explorer.aleo.org/v1" + )] + pub endpoint: String, + #[clap(short, long, global = true, help = "Network to use. Defaults to testnet3.", default_value = "testnet3")] + pub(crate) network: String, + #[clap(subcommand)] + command: QueryCommands, +} + +impl Command for Query { + type Input = (); + type Output = (); + + fn log_span(&self) -> Span { + tracing::span!(tracing::Level::INFO, "Leo") + } + + fn prelude(&self, _context: Context) -> Result { + Ok(()) + } + + fn apply(self, context: Context, _: Self::Input) -> Result { + let output = match self.command { + QueryCommands::Block { command } => command.apply(context, ())?, + QueryCommands::Transaction { command } => command.apply(context, ())?, + QueryCommands::Program { command } => command.apply(context, ())?, + QueryCommands::Stateroot { command } => command.apply(context, ())?, + QueryCommands::Committee { command } => command.apply(context, ())?, + }; + + // Make GET request to retrieve on-chain state. + let url = format!("{}/{}/{}", self.endpoint, self.network, output); + let response = ureq::get(&url.clone()) + .call() + .map_err(|err| UtilError::failed_to_retrieve_from_endpoint(err, Default::default()))?; + if response.status() == 200 { + tracing::info!("✅ Successfully retrieved data from '{url}'."); + // Unescape the newlines. + println!("{}", response.into_string().unwrap().replace("\\n", "\n")); + Ok(()) + } else { + Err(UtilError::network_error(url, response.status(), Default::default()).into()) + } + } +} + +#[derive(Parser, Debug)] +enum QueryCommands { + #[clap(about = "Query block information")] + Block { + #[clap(flatten)] + command: Block, + }, + #[clap(about = "Query transaction information")] + Transaction { + #[clap(flatten)] + command: Transaction, + }, + #[clap(about = "Query program source code and live mapping values")] + Program { + #[clap(flatten)] + command: Program, + }, + #[clap(about = "Query the latest stateroot")] + Stateroot { + #[clap(flatten)] + command: StateRoot, + }, + #[clap(about = "Query the current committee")] + Committee { + #[clap(flatten)] + command: Committee, + }, +} diff --git a/leo/cli/mod.rs b/leo/cli/mod.rs index 4dcfa0a3d7..19e10b6a91 100644 --- a/leo/cli/mod.rs +++ b/leo/cli/mod.rs @@ -23,6 +23,9 @@ pub use commands::*; mod helpers; pub use helpers::*; +mod query_commands; +pub use query_commands::*; + pub(crate) type CurrentNetwork = snarkvm::prelude::MainnetV0; pub(crate) const SNARKVM_COMMAND: &str = "snarkvm"; diff --git a/leo/cli/query_commands/block.rs b/leo/cli/query_commands/block.rs new file mode 100644 index 0000000000..84ef81f9e8 --- /dev/null +++ b/leo/cli/query_commands/block.rs @@ -0,0 +1,93 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use super::*; + +use crate::cli::context::Context; +use clap::Parser; + +// Query on-chain information related to blocks. +#[derive(Parser, Debug)] +pub struct Block { + #[clap(help = "Fetch a block by specifying its height or hash", required_unless_present_any = &["latest", "latest_hash", "latest_height", "range"])] + pub(crate) id: Option, + #[arg(short, long, help = "Get the latest block", default_value = "false", conflicts_with_all(["latest_hash", "latest_height", "range", "transactions", "to_height"]))] + pub(crate) latest: bool, + #[arg(short, long, help = "Get the latest block hash", default_value = "false", conflicts_with_all(["latest", "latest_height", "range", "transactions", "to_height"]))] + pub(crate) latest_hash: bool, + #[arg(short, long, help = "Get the latest block height", default_value = "false", conflicts_with_all(["latest", "latest_hash", "range", "transactions", "to_height"]))] + pub(crate) latest_height: bool, + #[arg(short, long, help = "Get up to 50 consecutive blocks", number_of_values = 2, value_names = &["START_HEIGHT", "END_HEIGHT"], conflicts_with_all(["latest", "latest_hash", "latest_height", "transactions", "to_height"]))] + pub(crate) range: Option>, + #[arg( + short, + long, + help = "Get all transactions at the specified block height", + conflicts_with("to_height"), + default_value = "false" + )] + pub(crate) transactions: bool, + #[arg(short, long, help = "Lookup the block height corresponding to a hash value", default_value = "false")] + pub(crate) to_height: bool, +} + +impl Command for Block { + type Input = (); + type Output = String; + + fn log_span(&self) -> Span { + tracing::span!(tracing::Level::INFO, "Leo") + } + + fn prelude(&self, _context: Context) -> Result { + Ok(()) + } + + fn apply(self, _context: Context, _input: Self::Input) -> Result { + // Build custom url to fetch from based on the flags and user's input. + let url = if self.latest_height { + "block/height/latest".to_string() + } else if self.latest_hash { + "block/hash/latest".to_string() + } else if self.latest { + "block/latest".to_string() + } else if let Some(range) = self.range { + // Make sure the range is composed of valid numbers. + is_valid_numerical_input(&range[0])?; + is_valid_numerical_input(&range[1])?; + + // Make sure the range is not too large. + if range[1].parse::().unwrap() - range[0].parse::().unwrap() > 50 { + return Err(UtilError::invalid_range().into()); + } + format!("blocks?start={}&end={}", range[0], range[1]) + } else if self.transactions { + is_valid_numerical_input(&self.id.clone().unwrap())?; + format!("block/{}/transactions", self.id.unwrap()).to_string() + } else if self.to_height { + let id = self.id.unwrap(); + is_valid_hash(&id)?; + format!("height/{}", id).to_string() + } else if let Some(id) = self.id { + is_valid_height_or_hash(&id)?; + format!("block/{}", id) + } else { + unreachable!("All cases are covered") + }; + + Ok(url) + } +} diff --git a/leo/cli/query_commands/committee.rs b/leo/cli/query_commands/committee.rs new file mode 100644 index 0000000000..86bf67b74f --- /dev/null +++ b/leo/cli/query_commands/committee.rs @@ -0,0 +1,40 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use super::*; + +use clap::Parser; + +/// Query the committee. +#[derive(Parser, Debug)] +pub struct Committee {} + +impl Command for Committee { + type Input = (); + type Output = String; + + fn log_span(&self) -> Span { + tracing::span!(tracing::Level::INFO, "Leo") + } + + fn prelude(&self, _context: Context) -> Result { + Ok(()) + } + + fn apply(self, _context: Context, _: Self::Input) -> Result { + Ok("/committee/latest".to_string()) + } +} diff --git a/leo/cli/query_commands/mod.rs b/leo/cli/query_commands/mod.rs new file mode 100644 index 0000000000..2ce9097f06 --- /dev/null +++ b/leo/cli/query_commands/mod.rs @@ -0,0 +1,99 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +pub use super::*; + +pub mod block; +pub use block::Block; + +pub mod program; +pub use program::Program; + +pub mod state_root; +pub use state_root::StateRoot; + +pub mod committee; +pub mod transaction; +pub use committee::Committee; + +pub use transaction::Transaction; + +use crate::cli::helpers::context::*; +use leo_errors::{LeoError, Result, UtilError}; + +use tracing::span::Span; + +// A valid hash is 61 characters long, with preface "ab1" and all characters lowercase or numbers. +pub fn is_valid_hash(hash: &str) -> Result<(), LeoError> { + if hash.len() != 61 { + Err(UtilError::invalid_input_id_len(hash, "hash").into()) + } else if !hash.starts_with("ab1") && hash.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit()) { + Err(UtilError::invalid_input_id(hash, "hash", "ab1").into()) + } else { + Ok(()) + } +} + +// A valid transaction id is 61 characters long, with preface "at1" and all characters lowercase or numbers. +pub fn is_valid_transaction_id(transaction: &str) -> Result<(), LeoError> { + if transaction.len() != 61 { + Err(UtilError::invalid_input_id_len(transaction, "transaction").into()) + } else if !transaction.starts_with("at1") + && transaction.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit()) + { + Err(UtilError::invalid_input_id(transaction, "transaction", "at1").into()) + } else { + Ok(()) + } +} + +// A valid transition id is 61 characters long, with preface "au1" and all characters lowercase or numbers. +pub fn is_valid_transition_id(transition: &str) -> Result<(), LeoError> { + if transition.len() != 61 { + Err(UtilError::invalid_input_id_len(transition, "transition").into()) + } else if !transition.starts_with("au1") && transition.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit()) + { + Err(UtilError::invalid_input_id(transition, "transition", "au1").into()) + } else { + Ok(()) + } +} + +// A valid numerical input is a u32. +pub fn is_valid_numerical_input(num: &str) -> Result<(), LeoError> { + if num.parse::().is_err() { Err(UtilError::invalid_numerical_input(num).into()) } else { Ok(()) } +} + +// A valid height or hash. +pub fn is_valid_height_or_hash(input: &str) -> Result<(), LeoError> { + match (is_valid_hash(input), is_valid_numerical_input(input)) { + (Ok(_), _) | (_, Ok(_)) => Ok(()), + _ => Err(UtilError::invalid_height_or_hash(input).into()), + } +} + +// Checks if the string is a valid field, allowing for optional `field` suffix. +pub fn is_valid_field(field: &str) -> Result { + let split = field.split("field").collect::>(); + + if split.len() == 1 && split[0].chars().all(|c| c.is_numeric()) { + Ok(format!("{}field", field)) + } else if split.len() == 2 && split[0].chars().all(|c| c.is_numeric()) && split[1].is_empty() { + Ok(field.to_string()) + } else { + Err(UtilError::invalid_field(field).into()) + } +} diff --git a/leo/cli/query_commands/program.rs b/leo/cli/query_commands/program.rs new file mode 100644 index 0000000000..9c3f4378fd --- /dev/null +++ b/leo/cli/query_commands/program.rs @@ -0,0 +1,64 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use super::*; + +use clap::Parser; + +/// Query program source code and live mapping values. +#[derive(Parser, Debug)] +pub struct Program { + #[clap(name = "NAME", help = "The name of the program to fetch")] + pub(crate) name: String, + #[arg( + short, + long, + help = "Get all mappings defined in the program", + default_value = "false", + conflicts_with = "mapping_value" + )] + pub(crate) mappings: bool, + #[arg(short, long, help = "Get the value corresponding to the specified mapping and key.", number_of_values = 2, value_names = &["MAPPING", "KEY"], conflicts_with = "mappings")] + pub(crate) mapping_value: Option>, +} + +impl Command for Program { + type Input = (); + type Output = String; + + fn log_span(&self) -> Span { + tracing::span!(tracing::Level::INFO, "Leo") + } + + fn prelude(&self, _context: Context) -> Result { + Ok(()) + } + + fn apply(self, _context: Context, _: Self::Input) -> Result { + // TODO: Validate program name. + // Build custom url to fetch from based on the flags and user's input. + let url = if let Some(mapping_info) = self.mapping_value { + // TODO: Validate mapping name. + format!("program/{}/mapping/{}/{}", self.name, mapping_info[0], mapping_info[1]) + } else if self.mappings { + format!("program/{}/mappings", self.name) + } else { + format!("program/{}", self.name) + }; + + Ok(url) + } +} diff --git a/leo/cli/query_commands/state_root.rs b/leo/cli/query_commands/state_root.rs new file mode 100644 index 0000000000..b53a9e6e27 --- /dev/null +++ b/leo/cli/query_commands/state_root.rs @@ -0,0 +1,40 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use super::*; + +use clap::Parser; + +/// Query the latest stateroot. +#[derive(Parser, Debug)] +pub struct StateRoot {} + +impl Command for StateRoot { + type Input = (); + type Output = String; + + fn log_span(&self) -> Span { + tracing::span!(tracing::Level::INFO, "Leo") + } + + fn prelude(&self, _context: Context) -> Result { + Ok(()) + } + + fn apply(self, _context: Context, _: Self::Input) -> Result { + Ok("/stateRoot/latest".to_string()) + } +} diff --git a/leo/cli/query_commands/transaction.rs b/leo/cli/query_commands/transaction.rs new file mode 100644 index 0000000000..9a8ae9589b --- /dev/null +++ b/leo/cli/query_commands/transaction.rs @@ -0,0 +1,68 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use super::*; + +use clap::Parser; + +/// Query transaction information. +#[derive(Parser, Debug)] +pub struct Transaction { + #[clap(name = "ID", help = "The id of the transaction to fetch", required_unless_present_any = &["from_program", "from_transition", "from_io", "range"])] + pub(crate) id: Option, + #[arg(short, long, help = "Get the transaction only if it has been confirmed", default_value = "false", conflicts_with_all(["from_io", "from_transition", "from_program"]))] + pub(crate) confirmed: bool, + #[arg(value_name = "INPUT_OR_OUTPUT_ID", short, long, help = "Get the transition id that an input or output id occurred in", conflicts_with_all(["from_program", "from_transition", "confirmed", "id"]))] + pub(crate) from_io: Option, + #[arg(value_name = "TRANSITION_ID", short, long, help = "Get the id of the transaction containing the specified transition", conflicts_with_all(["from_io", "from_program", "confirmed", "id"]))] + pub(crate) from_transition: Option, + #[arg(value_name = "PROGRAM", short, long, help = "Get the id of the transaction id that the specified program was deployed in", conflicts_with_all(["from_io", "from_transition", "confirmed", "id"]))] + pub(crate) from_program: Option, +} + +impl Command for Transaction { + type Input = (); + type Output = String; + + fn log_span(&self) -> Span { + tracing::span!(tracing::Level::INFO, "Leo") + } + + fn prelude(&self, _context: Context) -> Result { + Ok(()) + } + + fn apply(self, _context: Context, _: Self::Input) -> Result { + // Build custom url to fetch from based on the flags and user's input. + let url = if let Some(io_id) = self.from_io { + let field = is_valid_field(&io_id)?; + format!("find/transitionID/{field}") + } else if let Some(transition) = self.from_transition { + is_valid_transition_id(&transition)?; + format!("find/transactionID/{transition}") + } else if let Some(program) = self.from_program { + // TODO: Validate program name. + format!("find/transactionID/deployment/{program}") + } else if let Some(id) = self.id { + is_valid_transaction_id(&id)?; + if self.confirmed { format!("transaction/confirmed/{}", id) } else { format!("transaction/{}", id) } + } else { + unreachable!("All command paths covered.") + }; + + Ok(url) + } +} diff --git a/utils/retriever/src/retriever/mod.rs b/utils/retriever/src/retriever/mod.rs index f67444d1b5..28ecc0639f 100644 --- a/utils/retriever/src/retriever/mod.rs +++ b/utils/retriever/src/retriever/mod.rs @@ -508,7 +508,7 @@ fn fetch_from_network(endpoint: &String, program: &String, network: Network) -> let url = format!("{}/{}/program/{}", endpoint, network.clone(), program); let response = ureq::get(&url.clone()) .call() - .map_err(|err| UtilError::failed_to_retrieve_from_endpoint(url.clone(), err, Default::default()))?; + .map_err(|err| UtilError::failed_to_retrieve_from_endpoint(err, Default::default()))?; if response.status() == 200 { Ok(response.into_string().unwrap()) } else { From 33fcb1e7ebef1c653cb3f2464680a174b76c2d56 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Mon, 6 May 2024 15:02:07 -0700 Subject: [PATCH 2/7] check aleo names are valid --- leo/cli/commands/add.rs | 4 +- leo/cli/commands/remove.rs | 4 +- leo/cli/query_commands/program.rs | 5 +- leo/cli/query_commands/transaction.rs | 3 +- leo/package/src/package.rs | 70 +++++++++++++-------------- 5 files changed, 44 insertions(+), 42 deletions(-) diff --git a/leo/cli/commands/add.rs b/leo/cli/commands/add.rs index 0783f0fc7c..46618b7cee 100755 --- a/leo/cli/commands/add.rs +++ b/leo/cli/commands/add.rs @@ -60,11 +60,11 @@ impl Command for Add { // Allow both `credits.aleo` and `credits` syntax. let name: String = match &self.name { name if name.ends_with(".aleo") - && Package::::is_program_name_valid(&name[0..self.name.len() - 5]) => + && Package::::is_aleo_name_valid(&name[0..self.name.len() - 5]) => { name.clone() } - name if Package::::is_program_name_valid(name) => format!("{name}.aleo"), + name if Package::::is_aleo_name_valid(name) => format!("{name}.aleo"), name => return Err(PackageError::invalid_file_name_dependency(name).into()), }; diff --git a/leo/cli/commands/remove.rs b/leo/cli/commands/remove.rs index a3df3c0d6c..07170fc119 100644 --- a/leo/cli/commands/remove.rs +++ b/leo/cli/commands/remove.rs @@ -67,11 +67,11 @@ impl Command for Remove { let name: String = match &self.name { Some(name) if name.ends_with(".aleo") - && Package::::is_program_name_valid(&name[0..name.len() - 5]) => + && Package::::is_aleo_name_valid(&name[0..name.len() - 5]) => { name.clone() } - Some(name) if Package::::is_program_name_valid(name) => format!("{name}.aleo"), + Some(name) if Package::::is_aleo_name_valid(name) => format!("{name}.aleo"), name => return Err(PackageError::invalid_file_name_dependency(name.clone().unwrap()).into()), }; diff --git a/leo/cli/query_commands/program.rs b/leo/cli/query_commands/program.rs index 9c3f4378fd..0a2976b238 100644 --- a/leo/cli/query_commands/program.rs +++ b/leo/cli/query_commands/program.rs @@ -17,6 +17,7 @@ use super::*; use clap::Parser; +use leo_package::package::Package; /// Query program source code and live mapping values. #[derive(Parser, Debug)] @@ -48,10 +49,10 @@ impl Command for Program { } fn apply(self, _context: Context, _: Self::Input) -> Result { - // TODO: Validate program name. + Package::::is_aleo_name_valid(&self.name); // Build custom url to fetch from based on the flags and user's input. let url = if let Some(mapping_info) = self.mapping_value { - // TODO: Validate mapping name. + Package::::is_aleo_name_valid(&mapping_info[0]); format!("program/{}/mapping/{}/{}", self.name, mapping_info[0], mapping_info[1]) } else if self.mappings { format!("program/{}/mappings", self.name) diff --git a/leo/cli/query_commands/transaction.rs b/leo/cli/query_commands/transaction.rs index 9a8ae9589b..60362b88d1 100644 --- a/leo/cli/query_commands/transaction.rs +++ b/leo/cli/query_commands/transaction.rs @@ -17,6 +17,7 @@ use super::*; use clap::Parser; +use leo_package::package::Package; /// Query transaction information. #[derive(Parser, Debug)] @@ -54,7 +55,7 @@ impl Command for Transaction { is_valid_transition_id(&transition)?; format!("find/transactionID/{transition}") } else if let Some(program) = self.from_program { - // TODO: Validate program name. + Package::::is_aleo_name_valid(&program); format!("find/transactionID/deployment/{program}") } else if let Some(id) = self.id { is_valid_transaction_id(&id)?; diff --git a/leo/package/src/package.rs b/leo/package/src/package.rs index c8bdbe4b5d..1260ead748 100644 --- a/leo/package/src/package.rs +++ b/leo/package/src/package.rs @@ -38,7 +38,7 @@ pub struct Package { impl Package { pub fn new(package_name: &str) -> Result { // Check that the package name is a valid Aleo program name. - if !Self::is_program_name_valid(package_name) { + if !Self::is_aleo_name_valid(package_name) { return Err(PackageError::invalid_package_name(package_name).into()); } @@ -51,35 +51,35 @@ impl Package { }) } - /// Returns `true` if the program name is valid. + /// Returns `true` if it is a valid Aleo name. /// - /// Program names can only contain ASCII alphanumeric characters and underscores. - pub fn is_program_name_valid(program_name: &str) -> bool { - // Check that the program name is nonempty. - if program_name.is_empty() { - tracing::error!("Program names must be nonempty"); + /// Ale names can only contain ASCII alphanumeric characters and underscores. + pub fn is_aleo_name_valid(name: &str) -> bool { + // Check that the name is nonempty. + if name.is_empty() { + tracing::error!("Aleo names must be nonempty"); return false; } - let first = program_name.chars().next().unwrap(); + let first = name.chars().next().unwrap(); // Check that the first character is not an underscore. if first == '_' { - tracing::error!("Program names cannot begin with an underscore"); + tracing::error!("Aleo names cannot begin with an underscore"); return false; } // Check that the first character is not a number. if first.is_numeric() { - tracing::error!("Program names cannot begin with a number"); + tracing::error!("Aleo names cannot begin with a number"); return false; } - // Iterate and check that the program name is valid. - for current in program_name.chars() { + // Iterate and check that the name is valid. + for current in name.chars() { // Check that the program name contains only ASCII alphanumeric or underscores. if !current.is_ascii_alphanumeric() && current != '_' { - tracing::error!("Program names must can only contain ASCII alphanumeric characters and underscores."); + tracing::error!("Aleo names must can only contain ASCII alphanumeric characters and underscores."); return false; } } @@ -90,7 +90,7 @@ impl Package { /// Returns `true` if a package is can be initialized at a given path. pub fn can_initialize(package_name: &str, path: &Path) -> bool { // Check that the package name is a valid Aleo program name. - if !Self::is_program_name_valid(package_name) { + if !Self::is_aleo_name_valid(package_name) { return false; } @@ -113,7 +113,7 @@ impl Package { /// Returns `true` if a package is initialized at the given path pub fn is_initialized(package_name: &str, path: &Path) -> bool { // Check that the package name is a valid Aleo program name. - if !Self::is_program_name_valid(package_name) { + if !Self::is_aleo_name_valid(package_name) { return false; } @@ -173,25 +173,25 @@ mod tests { #[test] fn test_is_package_name_valid() { - assert!(Package::::is_program_name_valid("foo")); - assert!(Package::::is_program_name_valid("foo_bar")); - assert!(Package::::is_program_name_valid("foo1")); - assert!(Package::::is_program_name_valid("foo_bar___baz_")); - - assert!(!Package::::is_program_name_valid("foo-bar")); - assert!(!Package::::is_program_name_valid("foo-bar-baz")); - assert!(!Package::::is_program_name_valid("foo-1")); - assert!(!Package::::is_program_name_valid("")); - assert!(!Package::::is_program_name_valid("-")); - assert!(!Package::::is_program_name_valid("-foo")); - assert!(!Package::::is_program_name_valid("-foo-")); - assert!(!Package::::is_program_name_valid("_foo")); - assert!(!Package::::is_program_name_valid("foo--bar")); - assert!(!Package::::is_program_name_valid("foo---bar")); - assert!(!Package::::is_program_name_valid("foo--bar--baz")); - assert!(!Package::::is_program_name_valid("foo---bar---baz")); - assert!(!Package::::is_program_name_valid("foo*bar")); - assert!(!Package::::is_program_name_valid("foo,bar")); - assert!(!Package::::is_program_name_valid("1-foo")); + assert!(Package::::is_aleo_name_valid("foo")); + assert!(Package::::is_aleo_name_valid("foo_bar")); + assert!(Package::::is_aleo_name_valid("foo1")); + assert!(Package::::is_aleo_name_valid("foo_bar___baz_")); + + assert!(!Package::::is_aleo_name_valid("foo-bar")); + assert!(!Package::::is_aleo_name_valid("foo-bar-baz")); + assert!(!Package::::is_aleo_name_valid("foo-1")); + assert!(!Package::::is_aleo_name_valid("")); + assert!(!Package::::is_aleo_name_valid("-")); + assert!(!Package::::is_aleo_name_valid("-foo")); + assert!(!Package::::is_aleo_name_valid("-foo-")); + assert!(!Package::::is_aleo_name_valid("_foo")); + assert!(!Package::::is_aleo_name_valid("foo--bar")); + assert!(!Package::::is_aleo_name_valid("foo---bar")); + assert!(!Package::::is_aleo_name_valid("foo--bar--baz")); + assert!(!Package::::is_aleo_name_valid("foo---bar---baz")); + assert!(!Package::::is_aleo_name_valid("foo*bar")); + assert!(!Package::::is_aleo_name_valid("foo,bar")); + assert!(!Package::::is_aleo_name_valid("1-foo")); } } From 7aba7259e14409c6d6e0878036ea051117485eff Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Tue, 7 May 2024 15:14:33 -0700 Subject: [PATCH 3/7] `leo query mempool` and `leo query peers` --- leo/cli/commands/query.rs | 26 ++++++++++++ leo/cli/query_commands/mempool.rs | 69 +++++++++++++++++++++++++++++++ leo/cli/query_commands/mod.rs | 8 +++- leo/cli/query_commands/peers.rs | 61 +++++++++++++++++++++++++++ 4 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 leo/cli/query_commands/mempool.rs create mode 100644 leo/cli/query_commands/peers.rs diff --git a/leo/cli/commands/query.rs b/leo/cli/commands/query.rs index 10be77850b..63a61eaebf 100644 --- a/leo/cli/commands/query.rs +++ b/leo/cli/commands/query.rs @@ -54,6 +54,22 @@ impl Command for Query { QueryCommands::Program { command } => command.apply(context, ())?, QueryCommands::Stateroot { command } => command.apply(context, ())?, QueryCommands::Committee { command } => command.apply(context, ())?, + QueryCommands::Mempool { command } => { + if self.endpoint == "http://api.explorer.aleo.org/v1" { + tracing::warn!( + "⚠️ `leo query mempool` is only valid when using a custom endpoint. Specify one using `--endpoint`." + ); + } + command.apply(context, ())? + } + QueryCommands::Peers { command } => { + if self.endpoint == "http://api.explorer.aleo.org/v1" { + tracing::warn!( + "⚠️ `leo query peers` is only valid when using a custom endpoint. Specify one using `--endpoint`." + ); + } + command.apply(context, ())? + } }; // Make GET request to retrieve on-chain state. @@ -99,4 +115,14 @@ enum QueryCommands { #[clap(flatten)] command: Committee, }, + #[clap(about = "Query transactions and transmissions from the memory pool")] + Mempool { + #[clap(flatten)] + command: Mempool, + }, + #[clap(about = "Query peer information")] + Peers { + #[clap(flatten)] + command: Peers, + }, } diff --git a/leo/cli/query_commands/mempool.rs b/leo/cli/query_commands/mempool.rs new file mode 100644 index 0000000000..cd461d6f7d --- /dev/null +++ b/leo/cli/query_commands/mempool.rs @@ -0,0 +1,69 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use super::*; + +use crate::cli::context::Context; +use clap::Parser; + +// Query transactions and transmissions from the memory pool. +#[derive(Parser, Debug)] +pub struct Mempool { + #[arg( + short, + long, + help = "Get the memory pool transactions", + default_value = "false", + required_unless_present = "transmissions", + conflicts_with("transmissions") + )] + pub(crate) transactions: bool, + #[arg( + short, + long, + help = "Get the memory pool transmissions", + default_value = "false", + required_unless_present = "transactions", + conflicts_with("transactions") + )] + pub(crate) transmissions: bool, +} + +impl Command for Mempool { + type Input = (); + type Output = String; + + fn log_span(&self) -> Span { + tracing::span!(tracing::Level::INFO, "Leo") + } + + fn prelude(&self, _context: Context) -> Result { + Ok(()) + } + + fn apply(self, _context: Context, _input: Self::Input) -> Result { + // Build custom url to fetch from based on the flags and user's input. + let url = if self.transactions { + "memoryPool/transactions".to_string() + } else if self.transmissions { + "memoryPool/transmissions".to_string() + } else { + unreachable!("All cases are covered") + }; + + Ok(url) + } +} diff --git a/leo/cli/query_commands/mod.rs b/leo/cli/query_commands/mod.rs index 2ce9097f06..f002971c45 100644 --- a/leo/cli/query_commands/mod.rs +++ b/leo/cli/query_commands/mod.rs @@ -26,9 +26,15 @@ pub mod state_root; pub use state_root::StateRoot; pub mod committee; -pub mod transaction; pub use committee::Committee; +mod mempool; +pub use mempool::Mempool; + +pub mod peers; +pub use peers::Peers; + +pub mod transaction; pub use transaction::Transaction; use crate::cli::helpers::context::*; diff --git a/leo/cli/query_commands/peers.rs b/leo/cli/query_commands/peers.rs new file mode 100644 index 0000000000..9ed4e0fdd7 --- /dev/null +++ b/leo/cli/query_commands/peers.rs @@ -0,0 +1,61 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use super::*; + +use crate::cli::context::Context; +use clap::Parser; + +// Query information about network peers. +#[derive(Parser, Debug)] +pub struct Peers { + #[arg(short, long, help = "Get all peer metrics", default_value = "false", conflicts_with("count"))] + pub(crate) metrics: bool, + #[arg( + short, + long, + help = "Get the count of all participating peers", + default_value = "false", + conflicts_with("metrics") + )] + pub(crate) count: bool, +} + +impl Command for Peers { + type Input = (); + type Output = String; + + fn log_span(&self) -> Span { + tracing::span!(tracing::Level::INFO, "Leo") + } + + fn prelude(&self, _context: Context) -> Result { + Ok(()) + } + + fn apply(self, _context: Context, _input: Self::Input) -> Result { + // Build custom url to fetch from based on the flags and user's input. + let url = if self.metrics { + "peers/all/metrics".to_string() + } else if self.count { + "peers/count".to_string() + } else { + "peers/all".to_string() + }; + + Ok(url) + } +} From ddcfe3971b500d79f19c30bf2f1b10d1c73daad5 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Tue, 7 May 2024 16:59:58 -0700 Subject: [PATCH 4/7] allow `credits.aleo` or `credits` syntax for program --- leo/cli/commands/query.rs | 4 ++-- leo/cli/query_commands/mod.rs | 12 ++++++++++++ leo/cli/query_commands/program.rs | 10 ++++++---- leo/cli/query_commands/transaction.rs | 5 ++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/leo/cli/commands/query.rs b/leo/cli/commands/query.rs index 63a61eaebf..eb0affe640 100644 --- a/leo/cli/commands/query.rs +++ b/leo/cli/commands/query.rs @@ -78,9 +78,9 @@ impl Command for Query { .call() .map_err(|err| UtilError::failed_to_retrieve_from_endpoint(err, Default::default()))?; if response.status() == 200 { - tracing::info!("✅ Successfully retrieved data from '{url}'."); + tracing::info!("✅ Successfully retrieved data from '{url}'.\n"); // Unescape the newlines. - println!("{}", response.into_string().unwrap().replace("\\n", "\n")); + println!("{}\n", response.into_string().unwrap().replace("\\n", "\n")); Ok(()) } else { Err(UtilError::network_error(url, response.status(), Default::default()).into()) diff --git a/leo/cli/query_commands/mod.rs b/leo/cli/query_commands/mod.rs index f002971c45..68fdf8b4d2 100644 --- a/leo/cli/query_commands/mod.rs +++ b/leo/cli/query_commands/mod.rs @@ -40,6 +40,7 @@ pub use transaction::Transaction; use crate::cli::helpers::context::*; use leo_errors::{LeoError, Result, UtilError}; +use leo_package::package::Package; use tracing::span::Span; // A valid hash is 61 characters long, with preface "ab1" and all characters lowercase or numbers. @@ -103,3 +104,14 @@ pub fn is_valid_field(field: &str) -> Result { Err(UtilError::invalid_field(field).into()) } } + +// Checks if the string is a valid program name in Aleo. +pub fn check_valid_program_name(name: String) -> String { + if name.ends_with(".aleo") { + Package::::is_aleo_name_valid(&name[0..name.len() - 5]); + name + } else { + Package::::is_aleo_name_valid(&name); + format!("{}.aleo", name) + } +} diff --git a/leo/cli/query_commands/program.rs b/leo/cli/query_commands/program.rs index 0a2976b238..2eee0e8225 100644 --- a/leo/cli/query_commands/program.rs +++ b/leo/cli/query_commands/program.rs @@ -49,15 +49,17 @@ impl Command for Program { } fn apply(self, _context: Context, _: Self::Input) -> Result { - Package::::is_aleo_name_valid(&self.name); + // Check that the program name is valid. + let program = check_valid_program_name(self.name); // Build custom url to fetch from based on the flags and user's input. let url = if let Some(mapping_info) = self.mapping_value { + // Check that the mapping name is valid. Package::::is_aleo_name_valid(&mapping_info[0]); - format!("program/{}/mapping/{}/{}", self.name, mapping_info[0], mapping_info[1]) + format!("program/{}/mapping/{}/{}", program, mapping_info[0], mapping_info[1]) } else if self.mappings { - format!("program/{}/mappings", self.name) + format!("program/{}/mappings", program) } else { - format!("program/{}", self.name) + format!("program/{}", program) }; Ok(url) diff --git a/leo/cli/query_commands/transaction.rs b/leo/cli/query_commands/transaction.rs index 60362b88d1..5913f3662c 100644 --- a/leo/cli/query_commands/transaction.rs +++ b/leo/cli/query_commands/transaction.rs @@ -17,7 +17,6 @@ use super::*; use clap::Parser; -use leo_package::package::Package; /// Query transaction information. #[derive(Parser, Debug)] @@ -55,8 +54,8 @@ impl Command for Transaction { is_valid_transition_id(&transition)?; format!("find/transactionID/{transition}") } else if let Some(program) = self.from_program { - Package::::is_aleo_name_valid(&program); - format!("find/transactionID/deployment/{program}") + // Check that the program name is valid. + format!("find/transactionID/deployment/{}", check_valid_program_name(program)) } else if let Some(id) = self.id { is_valid_transaction_id(&id)?; if self.confirmed { format!("transaction/confirmed/{}", id) } else { format!("transaction/{}", id) } From 7037e8dfd1f53356e22c853ea20bc4dbfafff239 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Wed, 8 May 2024 21:40:10 -0700 Subject: [PATCH 5/7] Add `X-Aleo-Leo-` header to GET request for `leo query` --- leo/cli/commands/query.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/leo/cli/commands/query.rs b/leo/cli/commands/query.rs index eb0affe640..4caa70d913 100644 --- a/leo/cli/commands/query.rs +++ b/leo/cli/commands/query.rs @@ -75,6 +75,7 @@ impl Command for Query { // Make GET request to retrieve on-chain state. let url = format!("{}/{}/{}", self.endpoint, self.network, output); let response = ureq::get(&url.clone()) + .set(&format!("X-Aleo-Leo-{}", env!("CARGO_PKG_VERSION")), "true") .call() .map_err(|err| UtilError::failed_to_retrieve_from_endpoint(err, Default::default()))?; if response.status() == 200 { From e45c666909c7f8bac7b4a9f0beb694babc53477f Mon Sep 17 00:00:00 2001 From: d0cd <23022326+d0cd@users.noreply.github.com> Date: Mon, 13 May 2024 08:27:55 -0700 Subject: [PATCH 6/7] Update leo/package/src/package.rs Signed-off-by: d0cd <23022326+d0cd@users.noreply.github.com> --- leo/package/src/package.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leo/package/src/package.rs b/leo/package/src/package.rs index 1260ead748..5c95d6465c 100644 --- a/leo/package/src/package.rs +++ b/leo/package/src/package.rs @@ -53,7 +53,7 @@ impl Package { /// Returns `true` if it is a valid Aleo name. /// - /// Ale names can only contain ASCII alphanumeric characters and underscores. + /// Aleo names can only contain ASCII alphanumeric characters and underscores. pub fn is_aleo_name_valid(name: &str) -> bool { // Check that the name is nonempty. if name.is_empty() { From 9c1e5c678a57c02ece4b12842214b499ce15fbaa Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 13 May 2024 08:48:59 -0700 Subject: [PATCH 7/7] Reorganize --- .../query}/block.rs | 0 .../query}/committee.rs | 0 .../query}/mempool.rs | 0 leo/cli/commands/{query.rs => query/mod.rs} | 24 ++++++++++++++++++ .../query}/peers.rs | 0 .../query}/program.rs | 0 .../query}/state_root.rs | 0 .../query}/transaction.rs | 0 .../mod.rs => commands/query/utils.rs} | 25 +------------------ leo/cli/mod.rs | 3 --- 10 files changed, 25 insertions(+), 27 deletions(-) rename leo/cli/{query_commands => commands/query}/block.rs (100%) rename leo/cli/{query_commands => commands/query}/committee.rs (100%) rename leo/cli/{query_commands => commands/query}/mempool.rs (100%) rename leo/cli/commands/{query.rs => query/mod.rs} (94%) rename leo/cli/{query_commands => commands/query}/peers.rs (100%) rename leo/cli/{query_commands => commands/query}/program.rs (100%) rename leo/cli/{query_commands => commands/query}/state_root.rs (100%) rename leo/cli/{query_commands => commands/query}/transaction.rs (100%) rename leo/cli/{query_commands/mod.rs => commands/query/utils.rs} (90%) diff --git a/leo/cli/query_commands/block.rs b/leo/cli/commands/query/block.rs similarity index 100% rename from leo/cli/query_commands/block.rs rename to leo/cli/commands/query/block.rs diff --git a/leo/cli/query_commands/committee.rs b/leo/cli/commands/query/committee.rs similarity index 100% rename from leo/cli/query_commands/committee.rs rename to leo/cli/commands/query/committee.rs diff --git a/leo/cli/query_commands/mempool.rs b/leo/cli/commands/query/mempool.rs similarity index 100% rename from leo/cli/query_commands/mempool.rs rename to leo/cli/commands/query/mempool.rs diff --git a/leo/cli/commands/query.rs b/leo/cli/commands/query/mod.rs similarity index 94% rename from leo/cli/commands/query.rs rename to leo/cli/commands/query/mod.rs index 4caa70d913..f5030f378f 100644 --- a/leo/cli/commands/query.rs +++ b/leo/cli/commands/query/mod.rs @@ -16,6 +16,30 @@ use super::*; +mod block; +use block::Block; + +mod program; +use program::Program; + +mod state_root; +use state_root::StateRoot; + +mod committee; +use committee::Committee; + +mod mempool; +use mempool::Mempool; + +mod peers; +use peers::Peers; + +mod transaction; +use transaction::Transaction; + +mod utils; +use utils::*; + use leo_errors::UtilError; /// Query live data from the Aleo network. diff --git a/leo/cli/query_commands/peers.rs b/leo/cli/commands/query/peers.rs similarity index 100% rename from leo/cli/query_commands/peers.rs rename to leo/cli/commands/query/peers.rs diff --git a/leo/cli/query_commands/program.rs b/leo/cli/commands/query/program.rs similarity index 100% rename from leo/cli/query_commands/program.rs rename to leo/cli/commands/query/program.rs diff --git a/leo/cli/query_commands/state_root.rs b/leo/cli/commands/query/state_root.rs similarity index 100% rename from leo/cli/query_commands/state_root.rs rename to leo/cli/commands/query/state_root.rs diff --git a/leo/cli/query_commands/transaction.rs b/leo/cli/commands/query/transaction.rs similarity index 100% rename from leo/cli/query_commands/transaction.rs rename to leo/cli/commands/query/transaction.rs diff --git a/leo/cli/query_commands/mod.rs b/leo/cli/commands/query/utils.rs similarity index 90% rename from leo/cli/query_commands/mod.rs rename to leo/cli/commands/query/utils.rs index 68fdf8b4d2..c038c14356 100644 --- a/leo/cli/query_commands/mod.rs +++ b/leo/cli/commands/query/utils.rs @@ -14,34 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -pub use super::*; +use super::*; -pub mod block; -pub use block::Block; - -pub mod program; -pub use program::Program; - -pub mod state_root; -pub use state_root::StateRoot; - -pub mod committee; -pub use committee::Committee; - -mod mempool; -pub use mempool::Mempool; - -pub mod peers; -pub use peers::Peers; - -pub mod transaction; -pub use transaction::Transaction; - -use crate::cli::helpers::context::*; use leo_errors::{LeoError, Result, UtilError}; use leo_package::package::Package; -use tracing::span::Span; // A valid hash is 61 characters long, with preface "ab1" and all characters lowercase or numbers. pub fn is_valid_hash(hash: &str) -> Result<(), LeoError> { diff --git a/leo/cli/mod.rs b/leo/cli/mod.rs index 19e10b6a91..4dcfa0a3d7 100644 --- a/leo/cli/mod.rs +++ b/leo/cli/mod.rs @@ -23,9 +23,6 @@ pub use commands::*; mod helpers; pub use helpers::*; -mod query_commands; -pub use query_commands::*; - pub(crate) type CurrentNetwork = snarkvm::prelude::MainnetV0; pub(crate) const SNARKVM_COMMAND: &str = "snarkvm";