Skip to content
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions crates/lang/codegen/src/generator/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
};
}
Expand Down
42 changes: 22 additions & 20 deletions crates/metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,34 @@ 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 = "3")]
V3,
#[serde(rename = "4")]
V4,
}

impl From<InkProject> 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")]
Expand All @@ -106,6 +102,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(),
Expand All @@ -114,6 +111,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
Expand Down