diff --git a/metadata/lib.rs b/metadata/lib.rs index 1c1e606d707c836cc839445ebac03f9537496bf7..4f7fa75446178b80daf9c14ef3b04fac5ca33ebd 100644 --- a/metadata/lib.rs +++ b/metadata/lib.rs @@ -28,7 +28,7 @@ //! let language = SourceLanguage::new(Language::Ink, Version::new(2, 1, 0)); //! let compiler = SourceCompiler::new(Compiler::RustC, Version::parse("1.46.0-nightly").unwrap()); //! let wasm = SourceWasm::new(vec![0u8]); -//! let source = Source::new(Some(wasm), Some(CodeHash([0u8; 32])), language, compiler); +//! let source = Source::new(Some(wasm), CodeHash([0u8; 32]), language, compiler); //! let contract = Contract::builder() //! .name("incrementer".to_string()) //! .version(Version::new(2, 1, 0)) @@ -114,8 +114,7 @@ impl Serialize for CodeHash { #[derive(Clone, Debug, Serialize)] pub struct Source { - #[serde(skip_serializing_if = "Option::is_none")] - hash: Option, + hash: CodeHash, language: SourceLanguage, compiler: SourceCompiler, #[serde(skip_serializing_if = "Option::is_none")] @@ -126,7 +125,7 @@ impl Source { /// Constructs a new InkProjectSource. pub fn new( wasm: Option, - hash: Option, + hash: CodeHash, language: SourceLanguage, compiler: SourceCompiler, ) -> Self { @@ -522,7 +521,7 @@ mod tests { let compiler = SourceCompiler::new(Compiler::RustC, Version::parse("1.46.0-nightly").unwrap()); let wasm = SourceWasm::new(vec![0u8, 1u8, 2u8]); - let source = Source::new(Some(wasm), Some(CodeHash([0u8; 32])), language, compiler); + let source = Source::new(Some(wasm), CodeHash([0u8; 32]), language, compiler); let contract = Contract::builder() .name("incrementer".to_string()) .version(Version::new(2, 1, 0)) @@ -604,7 +603,7 @@ mod tests { let language = SourceLanguage::new(Language::Ink, Version::new(2, 1, 0)); let compiler = SourceCompiler::new(Compiler::RustC, Version::parse("1.46.0-nightly").unwrap()); - let source = Source::new(None, Some(CodeHash([0u8; 32])), language, compiler); + let source = Source::new(None, CodeHash([0u8; 32]), language, compiler); let contract = Contract::builder() .name("incrementer".to_string()) .version(Version::new(2, 1, 0)) diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index e80c01e4065988dc0c0018fbad433a2c2fdaa129..2d4180ed970816b95110c1e62650102c93261988 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -74,13 +74,9 @@ impl GenerateMetadataCommand { let generate_metadata = |manifest_path: &ManifestPath| -> Result<()> { let mut current_progress = 4; - let curr_step = match self.build_artifact { - GenerateArtifacts::MetadataOnly => 1, - _ => current_progress, - }; println!( " {} {}", - format!("[{}/{}]", curr_step, self.build_artifact.steps()).bold(), + format!("[{}/{}]", current_progress, self.build_artifact.steps()).bold(), "Generating metadata".bright_green().bold() ); let target_dir_arg = format!("--target-dir={}", target_directory.to_string_lossy()); @@ -167,13 +163,7 @@ impl GenerateMetadataCommand { .transpose()?; let homepage = self.crate_metadata.homepage.clone(); let license = contract_package.license.clone(); - let (dest_wasm, hash, optimization_result) = - if self.build_artifact != GenerateArtifacts::MetadataOnly { - let (wasm, hash, optimization) = self.wasm_hash()?; - (Some(wasm), Some(hash), Some(optimization)) - } else { - (None, None, None) - }; + let (dest_wasm, hash, optimization_result) = self.wasm_hash()?; let source = { let lang = SourceLanguage::new(Language::Ink, ink_version.clone()); let compiler = SourceCompiler::new(Compiler::RustC, rust_version); @@ -182,7 +172,7 @@ impl GenerateMetadataCommand { // The Wasm which we read must have the same hash as `source.hash` debug_assert!({ let expected = blake2_hash(wasm.as_slice()); - Some(expected) == hash + expected == hash }); Some(SourceWasm::new(wasm)) } else { @@ -226,11 +216,11 @@ impl GenerateMetadataCommand { let user = self.crate_metadata.user.clone().map(User::new); Ok(ExtendedMetadataResult { - dest_wasm, + dest_wasm: Some(dest_wasm), source, contract, user, - optimization_result, + optimization_result: Some(optimization_result), }) } diff --git a/src/main.rs b/src/main.rs index 124cf4c7d69fadbd072ee4ca6ac727a010eee492..41f70bb4ff3daeea181eaae84fff86312673b195 100644 --- a/src/main.rs +++ b/src/main.rs @@ -161,9 +161,6 @@ pub enum GenerateArtifacts { /// Only the Wasm is created, generation of metadata and a bundled `.contract` file is skipped #[structopt(name = "code-only")] CodeOnly, - /// Only the Wasm and the metadata are generated, no bundled `.contract` file is created - #[structopt(name = "metadata-only")] - MetadataOnly, } impl GenerateArtifacts { @@ -173,24 +170,10 @@ impl GenerateArtifacts { match self { GenerateArtifacts::All => 5, GenerateArtifacts::CodeOnly => 3, - GenerateArtifacts::MetadataOnly => 1, } } pub fn display(&self, result: &GenerationResult) -> String { - if self == &GenerateArtifacts::MetadataOnly { - return format!( - "\nYour contract's metadata is ready. You can find it here:\n{}", - result - .dest_metadata - .as_ref() - .expect("metadata path must exist") - .display() - .to_string() - .bold() - ); - } - let optimization = GenerationResult::display_optimization(result); let size_diff = format!( "\nOriginal wasm size: {}, Optimized: {}\n\n", @@ -249,7 +232,6 @@ impl std::str::FromStr for GenerateArtifacts { match artifact { "all" => Ok(GenerateArtifacts::All), "code-only" => Ok(GenerateArtifacts::CodeOnly), - "metadata-only" => Ok(GenerateArtifacts::MetadataOnly), _ => Err("Could not parse build artifact".to_string()), } } @@ -318,18 +300,13 @@ enum Command { /// Which build artifacts to generate. /// /// - `all`: Generate the Wasm, the metadata and a bundled `.contract` file. - /// The metadata file includes the Wasm hash. /// /// - `code-only`: Only the Wasm is created, generation of metadata and a bundled /// `.contract` file is skipped. - /// - /// - `metadata-only`: Only the metadata iis generated, neither the bundled - /// `.contract`, nor the Wasm file are created. The resulting metadata - /// does not contain the Wasm hash. #[structopt( long = "generate", default_value = "all", - value_name = "all | code-only | metadata-only", + value_name = "all | code-only", verbatim_doc_comment )] build_artifact: GenerateArtifacts, @@ -421,22 +398,13 @@ fn exec(cmd: Command) -> Result { unstable_options, } => { let manifest_path = ManifestPath::try_from(manifest_path.as_ref())?; - let result = if build_artifact == &GenerateArtifacts::MetadataOnly { - cmd::metadata::execute( - &manifest_path, - verbosity.try_into()?, - *build_artifact, - unstable_options.try_into()?, - )? - } else { - cmd::build::execute( - &manifest_path, - verbosity.try_into()?, - true, - *build_artifact, - unstable_options.try_into()?, - )? - }; + let result = cmd::build::execute( + &manifest_path, + verbosity.try_into()?, + true, + *build_artifact, + unstable_options.try_into()?, + )?; Ok(build_artifact.display(&result)) }