From 2a954771f4ae52d758e48f7cfef27c659806e286 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 11 Jul 2022 15:02:17 -0400 Subject: [PATCH 1/7] Add `version` field to `InkProject` --- crates/metadata/src/lib.rs | 48 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/crates/metadata/src/lib.rs b/crates/metadata/src/lib.rs index 86bc9e285ca..96ac78a6a78 100644 --- a/crates/metadata/src/lib.rs +++ b/crates/metadata/src/lib.rs @@ -57,38 +57,32 @@ use serde::{ Serialize, }; -/// Versioned ink! project metadata. +/// The metadata version of the generated ink! contract. +/// +/// The serialized metadata format (which this represents) is different from the +/// version of this crate or the contract for Rust semantic versioning purposes. /// /// # Note /// -/// Represents the version of the serialized metadata *format*, which is distinct from the version -/// of this crate for Rust semantic versioning compatibility. -#[derive(Debug, Serialize, Deserialize)] -#[allow(clippy::large_enum_variant)] -pub enum MetadataVersioned { - /// Version 0 placeholder. Represents the original non-versioned metadata format. - V0(MetadataVersionDeprecated), - /// Version 1 of the contract metadata. - V1(MetadataVersionDeprecated), - /// Version 2 of the contract metadata. - V2(MetadataVersionDeprecated), - /// Version 3 of the contract metadata. - V3(InkProject), -} - -impl From for MetadataVersioned { - fn from(ink_project: InkProject) -> Self { - MetadataVersioned::V3(ink_project) - } +/// Versions other than the `Default` are considered deprecated. +#[derive(Default, Debug, Serialize, Deserialize)] +pub enum MetadataVersion { + /// Represents the original non-versioned metadata format. + #[serde(rename = "0")] + V0, + #[serde(rename = "1")] + V1, + #[serde(rename = "2")] + V2, + #[default] + #[serde(rename = "3")] + V3, } -/// Enum to represent a deprecated metadata version that cannot be instantiated. -#[derive(Debug, Serialize, Deserialize)] -pub enum MetadataVersionDeprecated {} - /// An entire ink! project for metadata file generation purposes. #[derive(Debug, Serialize, Deserialize)] pub struct InkProject { + version: MetadataVersion, #[serde(flatten)] registry: PortableRegistry, #[serde(rename = "storage")] @@ -106,6 +100,7 @@ impl InkProject { let mut registry = Registry::new(); Self { + version: Default::default(), layout: layout.into().into_portable(&mut registry), spec: spec.into().into_portable(&mut registry), registry: registry.into(), @@ -114,6 +109,11 @@ impl InkProject { } impl InkProject { + /// Returns the metadata version used by the contract. + pub fn version(&self) -> &MetadataVersion { + &self.version + } + /// Returns a read-only registry of types in the contract. pub fn registry(&self) -> &PortableRegistry { &self.registry From 970b5d794289a120459e37aee468bb90c16468b5 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 11 Jul 2022 15:02:56 -0400 Subject: [PATCH 2/7] Use `InkProject` directly in metadata codegen --- crates/lang/codegen/src/generator/metadata.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/lang/codegen/src/generator/metadata.rs b/crates/lang/codegen/src/generator/metadata.rs index 0142643a755..2a36fa4496f 100644 --- a/crates/lang/codegen/src/generator/metadata.rs +++ b/crates/lang/codegen/src/generator/metadata.rs @@ -45,10 +45,8 @@ impl GenerateCode for Metadata<'_> { #[cfg(not(feature = "ink-as-dependency"))] const _: () = { #[no_mangle] - pub fn __ink_generate_metadata() -> ::ink_metadata::MetadataVersioned { - <::ink_metadata::InkProject as ::core::convert::Into<::ink_metadata::MetadataVersioned>>::into( - ::ink_metadata::InkProject::new(#layout, #contract) - ) + pub fn __ink_generate_metadata() -> ::ink_metadata::InkProject { + ::ink_metadata::InkProject::new(#layout, #contract) } }; } From 826605b14c90a91db8daaedaf26e984c9515e191 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Wed, 13 Jul 2022 12:59:19 -0400 Subject: [PATCH 3/7] Remove old metadata versions from version enum These versions can't be constructed using this version of the crate anyways, so it doesn't really make sense to keep them. --- crates/metadata/src/lib.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/metadata/src/lib.rs b/crates/metadata/src/lib.rs index 96ac78a6a78..a1c40c312b2 100644 --- a/crates/metadata/src/lib.rs +++ b/crates/metadata/src/lib.rs @@ -64,16 +64,11 @@ use serde::{ /// /// # Note /// -/// Versions other than the `Default` are considered deprecated. +/// Versions other than the `Default` are considered deprecated. If you want to +/// deserialize legacy metadata versions you will need to use an old version of +/// this crate. #[derive(Default, Debug, Serialize, Deserialize)] pub enum MetadataVersion { - /// Represents the original non-versioned metadata format. - #[serde(rename = "0")] - V0, - #[serde(rename = "1")] - V1, - #[serde(rename = "2")] - V2, #[default] #[serde(rename = "3")] V3, From 50041e1ab2a9a31fa9997662656bcf39d1a43d43 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 14 Jul 2022 11:14:15 -0400 Subject: [PATCH 4/7] Manually implement `Default` We should change to using the derive macros once our CI's nightly compiler version gets updated. --- crates/metadata/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/metadata/src/lib.rs b/crates/metadata/src/lib.rs index a1c40c312b2..bd96a702582 100644 --- a/crates/metadata/src/lib.rs +++ b/crates/metadata/src/lib.rs @@ -67,13 +67,18 @@ use serde::{ /// Versions other than the `Default` are considered deprecated. If you want to /// deserialize legacy metadata versions you will need to use an old version of /// this crate. -#[derive(Default, Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub enum MetadataVersion { - #[default] #[serde(rename = "3")] V3, } +impl Default for MetadataVersion { + fn default() -> Self { + Self::V3 + } +} + /// An entire ink! project for metadata file generation purposes. #[derive(Debug, Serialize, Deserialize)] pub struct InkProject { From f609741cbb942a7b2020fb99132e91f492753209 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 14 Jul 2022 17:08:46 -0400 Subject: [PATCH 5/7] Add metadata `V4` version option --- crates/metadata/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/metadata/src/lib.rs b/crates/metadata/src/lib.rs index bd96a702582..dd0f97574a4 100644 --- a/crates/metadata/src/lib.rs +++ b/crates/metadata/src/lib.rs @@ -71,11 +71,13 @@ use serde::{ pub enum MetadataVersion { #[serde(rename = "3")] V3, + #[serde(rename = "4")] + V4, } impl Default for MetadataVersion { fn default() -> Self { - Self::V3 + Self::V4 } } From 474d11101da750b4dc809c57d52ea1869d54f003 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 14 Jul 2022 17:13:28 -0400 Subject: [PATCH 6/7] Use my branch of `cargo-contract` in CI --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cf54b2d2204..6cf7848aac1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -339,6 +339,7 @@ examples-contract-build: <<: *docker-env <<: *test-refs script: + - cargo install --git /~https://github.com/paritytech/cargo-contract.git --branch hc-versioned-metadata --force - cargo contract -V - for example in examples/*/; do if [ "$example" = "examples/upgradeable-contracts/" ]; then continue; fi; From 5b456d70aa2455462e57ea20c7b37d6fc6327dc8 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 9 Aug 2022 16:01:38 -0400 Subject: [PATCH 7/7] Remove deprecated `V3` metadata We're never able to construct this variant with this crate anymore, so it doesn't make sense to keep it. --- crates/metadata/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/metadata/src/lib.rs b/crates/metadata/src/lib.rs index dd0f97574a4..13008efe9c7 100644 --- a/crates/metadata/src/lib.rs +++ b/crates/metadata/src/lib.rs @@ -69,8 +69,6 @@ use serde::{ /// this crate. #[derive(Debug, Serialize, Deserialize)] pub enum MetadataVersion { - #[serde(rename = "3")] - V3, #[serde(rename = "4")] V4, }