diff --git a/CHANGELOG.md b/CHANGELOG.md index 024873ad2..9a7f8776b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `rpc` command - [#1458](https://github.com/paritytech/cargo-contract/pull/1458) ### Changed +- Print type comparison warning only on `--verbose` - [#1483](https://github.com/paritytech/cargo-contract/pull/1483) - Mandatory dylint-based lints - [#1412](https://github.com/paritytech/cargo-contract/pull/1412) - Add a new tabular layout for the contract storage data - [#1485](https://github.com/paritytech/cargo-contract/pull/1485) diff --git a/crates/build/src/args.rs b/crates/build/src/args.rs index d41641bc5..0bc828573 100644 --- a/crates/build/src/args.rs +++ b/crates/build/src/args.rs @@ -45,7 +45,9 @@ impl TryFrom<&VerbosityFlags> for Verbosity { } /// Denotes if output should be printed to stdout. -#[derive(Clone, Copy, Default, serde::Serialize, serde::Deserialize, Eq, PartialEq)] +#[derive( + Clone, Copy, Default, serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug, +)] pub enum Verbosity { /// Use default output #[default] diff --git a/crates/cargo-contract/src/cmd/call.rs b/crates/cargo-contract/src/cmd/call.rs index 255069a50..37e234d6c 100644 --- a/crates/cargo-contract/src/cmd/call.rs +++ b/crates/cargo-contract/src/cmd/call.rs @@ -93,6 +93,7 @@ impl CallCommand { .url(self.extrinsic_cli_opts.url.clone()) .suri(self.extrinsic_cli_opts.suri.clone()) .storage_deposit_limit(self.extrinsic_cli_opts.storage_deposit_limit.clone()) + .verbosity(self.extrinsic_cli_opts.verbosity()?) .done(); let call_exec = CallCommandBuilder::default() .contract(self.contract.clone()) diff --git a/crates/extrinsics/src/call.rs b/crates/extrinsics/src/call.rs index cadec398d..cc5e8a36d 100644 --- a/crates/extrinsics/src/call.rs +++ b/crates/extrinsics/src/call.rs @@ -189,7 +189,7 @@ impl CallCommandBuilder { let rpc = RpcClient::from_url(&url).await?; let client = OnlineClient::from_rpc_client(rpc.clone()).await?; let rpc = LegacyRpcMethods::new(rpc); - check_env_types(&client, &transcoder)?; + check_env_types(&client, &transcoder, self.opts.extrinsic_opts.verbosity())?; let token_metadata = TokenMetadata::query(&rpc).await?; diff --git a/crates/extrinsics/src/env_check.rs b/crates/extrinsics/src/env_check.rs index 6714fc4af..5b82e9a09 100644 --- a/crates/extrinsics/src/env_check.rs +++ b/crates/extrinsics/src/env_check.rs @@ -1,3 +1,8 @@ +use colored::Colorize; +use contract_build::{ + verbose_eprintln, + Verbosity, +}; use ink_metadata::InkProject; use scale_info::{ form::PortableForm, @@ -13,6 +18,7 @@ use anyhow::{ fn get_node_env_fields( registry: &PortableRegistry, + verbosity: &Verbosity, ) -> Result>>> { let Some(env_type) = registry.types.iter().find(|t| { let len = t.ty.path.segments.len(); @@ -20,9 +26,12 @@ fn get_node_env_fields( t.ty.path.segments[bound..] == ["pallet_contracts", "Environment"] }) else { // if we can't find the type, then we use the old contract version. - eprintln!( - "The targeted version of `pallet-contracts` does not contain the `Environment` type. \ - Therefore the check for compatible types cannot be performed, and your types may not match those of the target node" + verbose_eprintln!( + verbosity, + "{} {}", + "Warning:".yellow().bold(), + "This chain does not yet support checking for compatibility of your contract types (https://use.ink/faq#type-comparison)." + .yellow() ); return Ok(None) }; @@ -76,8 +85,9 @@ pub(crate) fn resolve_type_definition( pub fn compare_node_env_with_contract( node_registry: &PortableRegistry, contract_metadata: &InkProject, + verbosity: &Verbosity, ) -> Result<()> { - let Some(env_fields) = get_node_env_fields(node_registry)? else { + let Some(env_fields) = get_node_env_fields(node_registry, verbosity)? else { return Ok(()) }; for field in env_fields { @@ -136,6 +146,7 @@ fn compare_type( #[cfg(test)] mod tests { + use contract_build::Verbosity; use ink_metadata::{ layout::{ Layout, @@ -362,7 +373,8 @@ mod tests { Timestamp, >(); - let valid = compare_node_env_with_contract(&portable, &ink_project); + let valid = + compare_node_env_with_contract(&portable, &ink_project, &Verbosity::Default); assert!(valid.is_ok(), "{}", valid.err().unwrap()) } @@ -376,7 +388,8 @@ mod tests { let ink_project = generate_contract_ink_project::(); - let result = compare_node_env_with_contract(&portable, &ink_project); + let result = + compare_node_env_with_contract(&portable, &ink_project, &Verbosity::Default); assert_eq!( result.err().unwrap().to_string(), "Failed to validate the field: timestamp" diff --git a/crates/extrinsics/src/extrinsic_opts.rs b/crates/extrinsics/src/extrinsic_opts.rs index 188286105..672313d66 100644 --- a/crates/extrinsics/src/extrinsic_opts.rs +++ b/crates/extrinsics/src/extrinsic_opts.rs @@ -16,6 +16,7 @@ use core::marker::PhantomData; +use contract_build::Verbosity; use subxt_signer::{ sr25519::Keypair, SecretUri, @@ -47,6 +48,7 @@ pub struct ExtrinsicOpts { url: url::Url, suri: String, storage_deposit_limit: Option, + verbosity: Verbosity, } /// Type state for the extrinsics' commands to tell that some mandatory state has not yet @@ -130,6 +132,13 @@ impl ExtrinsicOptsBuilder { this.opts.storage_deposit_limit = storage_deposit_limit; this } + + /// Set the verbosity level. + pub fn verbosity(self, verbosity: Verbosity) -> Self { + let mut this = self; + this.opts.verbosity = verbosity; + this + } } impl ExtrinsicOptsBuilder { @@ -150,6 +159,7 @@ impl ExtrinsicOpts { url: url::Url::parse("ws://localhost:9944").unwrap(), suri: String::new(), storage_deposit_limit: None, + verbosity: Verbosity::Default, }, marker: PhantomData, } @@ -206,6 +216,11 @@ impl ExtrinsicOpts { .map(|bv| bv.denominate_balance(token_metadata)) .transpose()?) } + + /// Verbosity for message reporting. + pub fn verbosity(&self) -> &Verbosity { + &self.verbosity + } } impl Default for ExtrinsicOpts { diff --git a/crates/extrinsics/src/instantiate.rs b/crates/extrinsics/src/instantiate.rs index 3f8a9d59a..f08646e21 100644 --- a/crates/extrinsics/src/instantiate.rs +++ b/crates/extrinsics/src/instantiate.rs @@ -191,7 +191,7 @@ impl InstantiateCommandBuilder { let rpc_cli = RpcClient::from_url(&url).await?; let client = OnlineClient::from_rpc_client(rpc_cli.clone()).await?; - check_env_types(&client, &transcoder)?; + check_env_types(&client, &transcoder, self.opts.extrinsic_opts.verbosity())?; let rpc = LegacyRpcMethods::new(rpc_cli); let token_metadata = TokenMetadata::query(&rpc).await?; diff --git a/crates/extrinsics/src/lib.rs b/crates/extrinsics/src/lib.rs index a1d91dd19..3ad0a14ea 100644 --- a/crates/extrinsics/src/lib.rs +++ b/crates/extrinsics/src/lib.rs @@ -42,6 +42,7 @@ use env_check::compare_node_env_with_contract; use anyhow::Result; use contract_build::{ CrateMetadata, + Verbosity, DEFAULT_KEY_COL_WIDTH, }; use scale::{ @@ -260,11 +261,16 @@ async fn get_best_block( fn check_env_types( client: &OnlineClient, transcoder: &ContractMessageTranscoder, + verbosity: &Verbosity, ) -> Result<()> where T: Config, { - compare_node_env_with_contract(client.metadata().types(), transcoder.metadata()) + compare_node_env_with_contract( + client.metadata().types(), + transcoder.metadata(), + verbosity, + ) } // Converts a Url into a String representation without excluding the default port. diff --git a/crates/extrinsics/src/upload.rs b/crates/extrinsics/src/upload.rs index 766a31fe1..fb0b3fbc2 100644 --- a/crates/extrinsics/src/upload.rs +++ b/crates/extrinsics/src/upload.rs @@ -118,7 +118,7 @@ impl UploadCommandBuilder { let url = self.opts.extrinsic_opts.url(); let rpc_cli = RpcClient::from_url(&url).await?; let client = OnlineClient::from_rpc_client(rpc_cli.clone()).await?; - check_env_types(&client, &transcoder)?; + check_env_types(&client, &transcoder, self.opts.extrinsic_opts.verbosity())?; let rpc = LegacyRpcMethods::new(rpc_cli); let token_metadata = TokenMetadata::query(&rpc).await?;