diff --git a/Cargo.lock b/Cargo.lock index 56a39c2..d378339 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "ash_api" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128e8c7a21a6d998c954ff1ff987121ade10b92ef514b9bf2d1635d2ba51a2f0" +checksum = "2d3101f4b0b3df96d918026e9fa223ba5fe310ee1c805dd8f2eea5579f4bfa5d" dependencies = [ "reqwest", "serde", diff --git a/crates/ash_cli/src/console/helper.rs b/crates/ash_cli/src/console/helper.rs index 0ea5cdf..91e62df 100644 --- a/crates/ash_cli/src/console/helper.rs +++ b/crates/ash_cli/src/console/helper.rs @@ -63,6 +63,12 @@ enum HelperSubcommands { /// Subnet resource ID or name subnet_resource_id_or_name: String, }, + /// Show helpful information about the URL of a Blockscout + #[command(version = version_tx_cmd(false))] + BlockscoutUrl { + /// Blockscout resource ID or name + blockscout_id_or_name: String, + }, } // Show helpful information to stake on an Avalanche node @@ -206,6 +212,47 @@ fn rpc_helper( Ok(()) } +/// Show helpful information about the URL of a Blockscout +fn blockscout_helper( + project_id_or_name: &str, + blockscout_id_or_name: &str, + config: Option<&str>, +) -> Result<(), CliError> { + let mut console = load_console(config)?; + + let api_config = create_api_config_with_access_token(&mut console)?; + + let spinner = spinner_with_message("Fetching blockscout information...".to_string()); + + let blockscout_response = task::block_on(async { + console::api::get_project_resource_by_id_or_name( + &api_config, + project_id_or_name, + blockscout_id_or_name, + ) + .await + .map_err(|e| CliError::dataerr(format!("Error getting blockscout resource: {e}"))) + })?; + + if *blockscout_response.resource_type.unwrap() != console::api_models::ResourceType::Blockscout { + return Err(CliError::dataerr( + "Resource is not a `blockscout`!".to_string(), + )); + }; + + spinner.finish_and_clear(); + + println!( + "Blockscout URL:\n {}", + type_colorize(&format!( + "http://{}:80", + blockscout_response.blockscout_ip.clone().unwrap_or_default() + )) + ); + + Ok(()) +} + // Parse helper subcommand pub(crate) fn parse(operation: HelperCommand, config: Option<&str>) -> Result<(), CliError> { let mut project_id_or_name = operation.project_id_or_name; @@ -228,5 +275,8 @@ pub(crate) fn parse(operation: HelperCommand, config: Option<&str>) -> Result<() &subnet_resource_id_or_name, config, ), + HelperSubcommands::BlockscoutUrl { + blockscout_id_or_name, + } => blockscout_helper(&project_id_or_name, &blockscout_id_or_name, config), } } diff --git a/crates/ash_cli/src/utils/templating.rs b/crates/ash_cli/src/utils/templating.rs index a772370..16eae32 100644 --- a/crates/ash_cli/src/utils/templating.rs +++ b/crates/ash_cli/src/utils/templating.rs @@ -1156,6 +1156,30 @@ pub(crate) fn template_avalanche_subnet_props_table( props_table } +pub(crate) fn template_blockscout_props_table( + blockscout: &console::api_models::GetAllProjectResources200ResponseInner, +) -> Table { + let mut props_table = Table::new(); + props_table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR); + + props_table.add_row(row![ + "IP address".bold(), + type_colorize(&blockscout.blockscout_ip.clone().unwrap_or_default()), + ]); + props_table.add_row(row![ + "Running".bold(), + type_colorize( + &blockscout + .blockscout_status + .clone() + .unwrap() + .running + .unwrap_or_default() + ), + ]); + props_table +} + pub(crate) fn template_resources_table( resources: Vec, project: console::api_models::Project, @@ -1225,6 +1249,9 @@ pub(crate) fn template_resources_table( } console::api_models::ResourceType::AvalancheSubnet => { template_avalanche_subnet_props_table(&resource.clone()) + }, + console::api_models::ResourceType::Blockscout => { + template_blockscout_props_table(&resource.clone()) } }, ]); diff --git a/crates/ash_sdk/Cargo.toml b/crates/ash_sdk/Cargo.toml index 18a9275..5f5b27b 100644 --- a/crates/ash_sdk/Cargo.toml +++ b/crates/ash_sdk/Cargo.toml @@ -42,7 +42,7 @@ rustls-pemfile = "1.0.3" sha2 = "0.10.7" oauth2 = "4.4.2" url = "2.4.1" -ash_api = { version = "0.1.5" } +ash_api = { version = "0.1.6" } rcgen = "0.11.3" [dev-dependencies]