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

feat(blockscout): add blockscout resource creation #96

Merged
merged 6 commits into from
Jun 17, 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
4 changes: 2 additions & 2 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))]
BlockscoutUrl {
/// 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://{}: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;
Expand All @@ -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),
}
}
27 changes: 27 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,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()),
]);
servalD marked this conversation as resolved.
Show resolved Hide resolved
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<console::api_models::GetAllProjectResources200ResponseInner>,
project: console::api_models::Project,
Expand Down Expand Up @@ -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())
}
},
]);
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" }
rcgen = "0.11.3"

[dev-dependencies]
Expand Down
Loading