Skip to content

Commit

Permalink
Improvements for production deployment check (#1562)
Browse files Browse the repository at this point in the history
* Improve comments

* Default to `n`

* Use correct capitalization

* Improve comments

* Use spelling consistent with rest of codebase

* Adapt to conventions of surrounding codebase

* Use `N`
  • Loading branch information
cmichi authored Mar 25, 2024
1 parent 4be398f commit 0f93fed
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion crates/cargo-contract/src/cmd/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct InfoCommand {
default_value = "ws://localhost:9944"
)]
url: url::Url,
/// A name of a production chain to upload or instantiate the contract on.
/// Name of a production chain to upload or instantiate the contract on.
#[clap(name = "chain", long, conflicts_with = "url")]
chain: Option<ProductionChain>,
/// Export the instantiate output in JSON format.
Expand Down
10 changes: 5 additions & 5 deletions crates/cargo-contract/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub struct CLIExtrinsicOpts {
/// Before submitting a transaction, do not ask the user for confirmation.
#[clap(short('y'), long)]
skip_confirm: bool,
/// A name of a production chain to upload or instantiate the contract on.
/// Name of a production chain to upload or instantiate the contract on.
#[clap(name = "chain", long, conflicts_with = "url")]
chain: Option<ProductionChain>,
}
Expand Down Expand Up @@ -330,16 +330,16 @@ pub fn prompt_confirm_unverifiable_upload(chain: &str) -> Result<()> {
println!(
"{} ({}): ",
"\nContinue?".bright_white().bold(),
"Y/n".bright_white().bold()
"y/N".bright_white().bold()
);

let mut buf = String::new();
io::stdout().flush()?;
io::stdin().read_line(&mut buf)?;
match buf.trim().to_lowercase().as_str() {
// default is 'y'
"y" | "" => Ok(()),
"n" => Err(anyhow!("Upload canceled!")),
// default is 'n'
"y" => Ok(()),
"n" | "" => Err(anyhow!("Upload cancelled!")),
c => Err(anyhow!("Expected either 'y' or 'n', got '{}'", c)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-contract/src/cmd/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct RpcCommand {
default_value = "ws://localhost:9944"
)]
url: url::Url,
/// A name of a production chain to upload or instantiate the contract on.
/// Name of a production chain to upload or instantiate the contract on.
#[clap(name = "chain", long, conflicts_with = "url")]
chain: Option<ProductionChain>,
/// Export the call output in JSON format.
Expand Down
5 changes: 3 additions & 2 deletions crates/extrinsics/src/contract_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ impl ContractArtifacts {
.context("Failed to deserialize ink project metadata from contract metadata")
}

/// Return true if the image is verifiable.
/// If the metadata can not be extracted then we assume that it can't be verified.
/// Returns `true` if the image is verifiable.
///
/// If the metadata cannot be extracted we assume that it can't be verified.
pub fn is_verifiable(&self) -> bool {
match self.metadata() {
Ok(m) => m.image.is_some(),
Expand Down
11 changes: 7 additions & 4 deletions crates/extrinsics/src/extrinsic_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ where
url_to_string(&self.url)
}

/// Get the chain name and its URL endpoint.
/// If the user specify the endpoint manually,
/// but it still appears to be the production chain,
/// we still convert it.
/// Returns the chain name and its URL endpoint.
///
/// If the user specified the endpoint URL manually we'll attempt to
/// convert it into one of the pre-defined production chains.
pub fn chain_and_endpoint(&self) -> (Chain, String) {
if let Some(chain) = &self.chain {
(
Expand All @@ -181,6 +181,9 @@ where
}
}

/// Returns `true` if the image is verifiable.
///
/// If the metadata cannot be extracted we assume that it can't be verified.
pub fn is_verifiable(&self) -> Result<bool> {
Ok(self.contract_artifacts()?.is_verifiable())
}
Expand Down
8 changes: 5 additions & 3 deletions crates/extrinsics/src/prod_chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

use std::str::FromStr;

/// Macro to generate enums with production chains and their respective endpoints
/// and generate required trait implementation
/// This macro generates enums with the pre-defined production chains and their respective
/// endpoints.
///
/// It also generates the required trait implementations.
macro_rules! define_chains {
(
$(#[$($attrs:tt)*])*
Expand Down Expand Up @@ -76,7 +78,7 @@ macro_rules! define_chains {
}

define_chains! {
/// A list of all production chains where the contract can be deployed to.
/// List of production chains where the contract can be deployed to.
pub enum ProductionChain {
AlephZero = "wss://ws.azero.dev:443",
Astar = "wss://rpc.astar.network:443",
Expand Down

0 comments on commit 0f93fed

Please sign in to comment.