diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 17a12bb5602..d424c03d067 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; 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) } }; } diff --git a/crates/metadata/src/lib.rs b/crates/metadata/src/lib.rs index 86bc9e285ca..13008efe9c7 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. +/// 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(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), +pub enum MetadataVersion { + #[serde(rename = "4")] + V4, } -impl From for MetadataVersioned { - fn from(ink_project: InkProject) -> Self { - MetadataVersioned::V3(ink_project) +impl Default for MetadataVersion { + fn default() -> Self { + Self::V4 } } -/// 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