Skip to content

Commit

Permalink
feat(blockscout): add blockscout resource creation
Browse files Browse the repository at this point in the history
  • Loading branch information
servalD committed Jun 3, 2024
1 parent ab66166 commit 345aba6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions crates/ash_cli/src/console/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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),
}
}
30 changes: 30 additions & 0 deletions crates/ash_cli/src/utils/templating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<console::api_models::GetAllProjectResources200ResponseInner>,
project: console::api_models::Project,
Expand Down Expand Up @@ -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())
}
},
]);
Expand Down
2 changes: 1 addition & 1 deletion crates/ash_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 345aba6

Please sign in to comment.