Skip to content

Commit

Permalink
Add version field to ink! metadata (#1313)
Browse files Browse the repository at this point in the history
* Add `version` field to `InkProject`

* Use `InkProject` directly in metadata codegen

* 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.

* Manually implement `Default`

We should change to using the derive macros once
our CI's nightly compiler version gets updated.

* Add metadata `V4` version option

* Use my branch of `cargo-contract` in CI

* 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.
  • Loading branch information
HCastano authored and xermicus committed Sep 8, 2022
1 parent 93179e8 commit 690feeb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
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
35 changes: 15 additions & 20 deletions crates/metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 @@ -107,6 +101,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 Down

0 comments on commit 690feeb

Please sign in to comment.