From 345aba668fbc121d38d8931728f3162368f60c44 Mon Sep 17 00:00:00 2001 From: gaetan cabaret Date: Mon, 3 Jun 2024 11:36:01 +0200 Subject: [PATCH 1/6] feat(blockscout): add blockscout resource creation --- Cargo.lock | 4 +-- crates/ash_cli/src/console/helper.rs | 50 ++++++++++++++++++++++++++ crates/ash_cli/src/utils/templating.rs | 30 ++++++++++++++++ crates/ash_sdk/Cargo.toml | 2 +- 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56a39c2..23e7175 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,9 +161,7 @@ dependencies = [ [[package]] name = "ash_api" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128e8c7a21a6d998c954ff1ff987121ade10b92ef514b9bf2d1635d2ba51a2f0" +version = "0.1.6" dependencies = [ "reqwest", "serde", diff --git a/crates/ash_cli/src/console/helper.rs b/crates/ash_cli/src/console/helper.rs index 0ea5cdf..4a983c9 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))] + Blockscout { + /// 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://{}:3000/", + 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::Blockscout { + 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..60d2f73 100644 --- a/crates/ash_cli/src/utils/templating.rs +++ b/crates/ash_cli/src/utils/templating.rs @@ -1156,6 +1156,33 @@ 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 + .node_status + .clone() + .unwrap() + .running + .unwrap_or_default() + ), + ]); + + // TODO: Add the rest of the Subnet properties + + props_table +} + pub(crate) fn template_resources_table( resources: Vec, project: console::api_models::Project, @@ -1225,6 +1252,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..ec7f33c 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", path= "/home/gaetan/Documents/hai/ash-api-rs"} rcgen = "0.11.3" [dev-dependencies] From 393875d66ac7e00ae084f428dbe3051dfa774d15 Mon Sep 17 00:00:00 2001 From: gaetan cabaret Date: Wed, 5 Jun 2024 10:08:28 +0200 Subject: [PATCH 2/6] fix(sdk): fix blockscout templating --- crates/ash_cli/src/utils/templating.rs | 2 +- crates/ash_sdk/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ash_cli/src/utils/templating.rs b/crates/ash_cli/src/utils/templating.rs index 60d2f73..f987165 100644 --- a/crates/ash_cli/src/utils/templating.rs +++ b/crates/ash_cli/src/utils/templating.rs @@ -1170,7 +1170,7 @@ pub(crate) fn template_blockscout_props_table( "Running".bold(), type_colorize( &blockscout - .node_status + .blockscout_status .clone() .unwrap() .running diff --git a/crates/ash_sdk/Cargo.toml b/crates/ash_sdk/Cargo.toml index ec7f33c..c0d7ab5 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.6", path= "/home/gaetan/Documents/hai/ash-api-rs"} +ash_api = { version = "0.1.6" , path = "/home/gaetan/Documents/hai/ash-api-rs"} rcgen = "0.11.3" [dev-dependencies] From 00836d21bc3d222e712c536708c9a3e403b25f52 Mon Sep 17 00:00:00 2001 From: gaetan cabaret Date: Wed, 5 Jun 2024 15:06:59 +0200 Subject: [PATCH 3/6] fix(sdk): update to online ash-api v0.1.6 --- Cargo.lock | 2 ++ crates/ash_sdk/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 23e7175..d378339 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,6 +162,8 @@ dependencies = [ [[package]] name = "ash_api" version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d3101f4b0b3df96d918026e9fa223ba5fe310ee1c805dd8f2eea5579f4bfa5d" dependencies = [ "reqwest", "serde", diff --git a/crates/ash_sdk/Cargo.toml b/crates/ash_sdk/Cargo.toml index c0d7ab5..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.6" , path = "/home/gaetan/Documents/hai/ash-api-rs"} +ash_api = { version = "0.1.6" } rcgen = "0.11.3" [dev-dependencies] From 0eaa45e2327a1a44860ee923c609e0dcce9b6378 Mon Sep 17 00:00:00 2001 From: gaetan cabaret Date: Wed, 5 Jun 2024 15:13:07 +0200 Subject: [PATCH 4/6] fix(cli): apply @leopaul36 suggestion --- crates/ash_cli/src/utils/templating.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/ash_cli/src/utils/templating.rs b/crates/ash_cli/src/utils/templating.rs index f987165..16eae32 100644 --- a/crates/ash_cli/src/utils/templating.rs +++ b/crates/ash_cli/src/utils/templating.rs @@ -1177,9 +1177,6 @@ pub(crate) fn template_blockscout_props_table( .unwrap_or_default() ), ]); - - // TODO: Add the rest of the Subnet properties - props_table } From 30de3a3cc1abb085237cbff5abf1c6f0345a19b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Cabaret?= <57412868+servalD@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:49:46 +0200 Subject: [PATCH 5/6] Update crates/ash_cli/src/console/helper.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Léo Schoukroun --- crates/ash_cli/src/console/helper.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ash_cli/src/console/helper.rs b/crates/ash_cli/src/console/helper.rs index 4a983c9..069dec3 100644 --- a/crates/ash_cli/src/console/helper.rs +++ b/crates/ash_cli/src/console/helper.rs @@ -245,7 +245,7 @@ fn blockscout_helper( println!( "Blockscout URL:\n {}", type_colorize(&format!( - "http://{}:3000/", + "http://{}:80", blockscout_response.blockscout_ip.clone().unwrap_or_default() )) ); From dbf00d6ea92959a1424cbd0cb73ab0348abd6860 Mon Sep 17 00:00:00 2001 From: gaetan cabaret Date: Mon, 17 Jun 2024 15:46:52 +0200 Subject: [PATCH 6/6] fix(helper): add url to blockscout cmd --- crates/ash_cli/src/console/helper.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ash_cli/src/console/helper.rs b/crates/ash_cli/src/console/helper.rs index 069dec3..91e62df 100644 --- a/crates/ash_cli/src/console/helper.rs +++ b/crates/ash_cli/src/console/helper.rs @@ -65,7 +65,7 @@ enum HelperSubcommands { }, /// Show helpful information about the URL of a Blockscout #[command(version = version_tx_cmd(false))] - Blockscout { + BlockscoutUrl { /// Blockscout resource ID or name blockscout_id_or_name: String, }, @@ -275,7 +275,7 @@ pub(crate) fn parse(operation: HelperCommand, config: Option<&str>) -> Result<() &subnet_resource_id_or_name, config, ), - HelperSubcommands::Blockscout { + HelperSubcommands::BlockscoutUrl { blockscout_id_or_name, } => blockscout_helper(&project_id_or_name, &blockscout_id_or_name, config), }