Unverified Commit ff723b17 authored by Andrew Jones's avatar Andrew Jones Committed by GitHub
Browse files

Update to scale-info `1.0`, introduce metadata format versioning (#845)



* Bump scale-info requirement to 0.9

* Update manual TypeInfo impls

* Use decode feature of scale-info

* scale-info 1.0

* Fix tests, 0 indexing on type registry

* Update some missing examples

* TMP: use ink rc5 for compat with cargo-contract

* Update RELEASES.md

* Bump versions back to 1.0

* Introduce versioning of ink metadata format

* Update RELEASES.md
Co-authored-by: Michael Müller's avatarMichael Müller <michi@parity.io>

* Update crates/metadata/src/lib.rs
Co-authored-by: Michael Müller's avatarMichael Müller <michi@parity.io>

* Clippy: allow large enum variant

* [storage] Allow one variant enum to derive SpreadLayout (#942)

* [storage] Allow one variant enum to derive SpreadLayout

I have an enum that has only one variant, and I want to store the enum value in the storage. I might add new variants later in development, so the enum is not useless.

The current implementation doesn't allow to derive the `SpreadLayout` trait for one variant enums, and I fixed it on this PR.

# Sample code

```rust
#![cfg_attr(not(feature = "std"), no_std)]

use ink_lang as ink;

#[derive(
    Copy,
    Clone,
    scale::Encode,
    scale::Decode,
    ink_storage::traits::SpreadLayout,
    ink_storage::traits::PackedLayout,
)]
#[cfg_attr(
    feature = "std",
    derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout)
)]
pub enum MyEnum {
    A,
}

#[ink::contract]
mod enum_test {
    use super::MyEnum;

    #[ink(storage)]
    pub struct EnumTest {
        value: MyEnum,
    }

    impl EnumTest {
        #[ink(constructor)]
        pub fn new() -> Self {
            Self { value: MyEnum::A }
        }

        #[ink(message)]
        pub fn get(&self) -> MyEnum {
            self.value
        }
    }
}
```

Without this change, I get this error.

```
$ cargo +nightly contract build
 [1/5] Building cargo project
    Updating crates.io index
   Compiling enum_test v0.1.0 (/private/var/folders/zn/l2f569z56vnghtt524x1mv6w0000gn/T/cargo-contract_FM50JF)
error: proc-macro derive panicked
  --> /snip/enum_test/lib.rs:10:5
   |
10 |     ink_storage::traits::SpreadLayout,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: can only operate on enums
```

* Update crates/storage/derive/src/spread_layout.rs
Co-authored-by: Hero Bird's avatarRobin Freyler <robbepop@web.de>

* cargo fmt
Co-authored-by: Hero Bird's avatarRobin Freyler <robbepop@web.de>

* CI: remove gcda files from cache (#943)

* Update pretty_assertions requirement from 0.7.1 to 1.0.0 (#944)

Updates the requirements on [pretty_assertions](https://github.com/colin-kiegel/rust-pretty-assertions) to permit the latest version.
- [Release notes](https://github.com/colin-kiegel/rust-pretty-assertions/releases)
- [Changelog](https://github.com/colin-kiegel/rust-pretty-assertions/blob/main/CHANGELOG.md)
- [Commits](https://github.com/colin-kiegel/rust-pretty-assertions/compare/v0.7.1...v1.0.0

)

---
updated-dependencies:
- dependency-name: pretty_assertions
  dependency-type: direct:production
...
Signed-off-by: default avatardependabot[bot] <support@github.com>
Co-authored-by: default avatardependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add 'versioning' to spellcheck dict
Co-authored-by: Michael Müller's avatarMichael Müller <michi@parity.io>
Co-authored-by: default avatartash-2s <81064017+tash-2s@users.noreply.github.com>
Co-authored-by: Hero Bird's avatarRobin Freyler <robbepop@web.de>
Co-authored-by: Denis_P's avatarDenis Pisarev <denis.pisarev@parity.io>
Co-authored-by: default avatardependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
parent 93d22fb3
Pipeline #162015 passed with stages
in 49 minutes and 51 seconds
......@@ -63,6 +63,7 @@ v3
validator
variadic
versa
versioning
Verbatim
metadata
timestamp
......
......@@ -4,6 +4,7 @@ This is the 6th release candidate for ink! 3.0.
## Changed
- Update to `scale-info` 1.0 - [#845](https://github.com/paritytech/ink/pull/845).
- Message and constructor selectors no longer take their inputs as string but as `u32` decodable integer. For example:
- It is no longer possible to specify a selector as `#[ink(selector = "0xC0DECAFE")]`.
......
......@@ -40,7 +40,7 @@ blake2 = { version = "0.9", optional = true }
# Sadly couldn't be marked as dev-dependency.
# Never use this crate outside the off-chain environment!
rand = { version = "0.8", default-features = false, features = ["alloc"], optional = true }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
[features]
default = ["std"]
......
......@@ -28,7 +28,7 @@ static_assertions = "1.1"
[dev-dependencies]
# required for the doctest of `env_access::EnvAccess::instantiate_contract`
scale-info = { version = "0.6", default-features = false, features = ["derive"] }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
[features]
default = ["std"]
......
......@@ -49,14 +49,14 @@ impl GenerateCode for Metadata<'_> {
#no_cross_calling_cfg
const _: () = {
#[no_mangle]
pub fn __ink_generate_metadata() -> ::ink_metadata::InkProject {
pub fn __ink_generate_metadata() -> ::ink_metadata::MetadataVersioned {
let contract: ::ink_metadata::ContractSpec = {
#contract
};
let layout: ::ink_metadata::layout::Layout = {
#layout
};
::ink_metadata::InkProject::new(layout, contract)
::ink_metadata::InkProject::new(layout, contract).into()
}
};
}
......
......@@ -31,7 +31,7 @@ ink_lang = { version = "3.0.0-rc5", path = ".." }
ink_prelude = { version = "3.0.0-rc5", path = "../../prelude/" }
trybuild = "1.0.24"
scale-info = { version = "0.6", default-features = false, features = ["derive"] }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
[lib]
name = "ink_lang_macro"
......
......@@ -21,7 +21,7 @@ ink_primitives = { version = "3.0.0-rc5", path = "../primitives/", default-featu
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
impl-serde = "0.3.1"
derive_more = { version = "0.99", default-features = false, features = ["from"] }
scale-info = { version = "0.6", default-features = false, features = ["derive", "serde"] }
scale-info = { version = "1.0", default-features = false, features = ["derive", "serde", "decode"] }
[dev-dependencies]
pretty_assertions = "1.0.0"
......
......@@ -58,7 +58,7 @@ fn named_fields_work() {
0000000000000000\
0000000000000000\
0000000000000000",
"ty": 1,
"ty": 0,
}
},
"name": "a",
......@@ -71,7 +71,7 @@ fn named_fields_work() {
0000000000000000\
0000000000000000\
0000000000000000",
"ty": 2,
"ty": 1,
}
},
"name": "b",
......@@ -115,7 +115,7 @@ fn tuple_struct_work() {
0000000000000000\
0000000000000000\
0000000000000000",
"ty": 1,
"ty": 0,
}
},
"name": null,
......@@ -128,7 +128,7 @@ fn tuple_struct_work() {
0000000000000000\
0000000000000000\
0000000000000000",
"ty": 2,
"ty": 1,
}
},
"name": null,
......@@ -261,7 +261,7 @@ fn mixed_enum_work() {
0000000000000000\
0000000000000000\
0000000000000000",
"ty": 1,
"ty": 0,
}
},
"name": null,
......@@ -274,7 +274,7 @@ fn mixed_enum_work() {
0000000000000000\
0000000000000000\
0000000000000000",
"ty": 2,
"ty": 1,
}
},
"name": null,
......@@ -291,7 +291,7 @@ fn mixed_enum_work() {
0000000000000000\
0000000000000000\
0000000000000000",
"ty": 1,
"ty": 0,
}
},
"name": "a",
......@@ -304,7 +304,7 @@ fn mixed_enum_work() {
0000000000000000\
0000000000000000\
0000000000000000",
"ty": 2,
"ty": 1,
}
},
"name": "b",
......@@ -348,7 +348,7 @@ fn unbounded_layout_works() {
0000000000000000\
0000000000000000\
0000000000000000",
"ty": 1
"ty": 0
}
},
"offset": "0x\
......
......@@ -57,6 +57,31 @@ use serde::{
Serialize,
};
/// Versioned ink! project metadata.
///
/// # 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(InkProject),
}
impl From<InkProject> for MetadataVersioned {
fn from(ink_project: InkProject) -> Self {
MetadataVersioned::V1(ink_project)
}
}
/// 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 {
......
......@@ -114,7 +114,7 @@ fn spec_contract_json() {
"displayName": [
"i32"
],
"type": 1
"type": 0
}
}
],
......@@ -140,7 +140,7 @@ fn spec_contract_json() {
"displayName": [
"i32"
],
"type": 1
"type": 0
}
}
],
......@@ -161,7 +161,7 @@ fn spec_contract_json() {
"displayName": [
"i32"
],
"type": 1
"type": 0
},
"selector": "0x25444afe"
}
......
......@@ -17,7 +17,7 @@ include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"]
[dependencies]
ink_prelude = { version = "3.0.0-rc5", path = "../prelude/", default-features = false }
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive", "full"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
[dev-dependencies]
criterion = "0.3.1"
......
......@@ -241,7 +241,9 @@ const _: () = {
fn type_info() -> Type {
Type::builder()
.path(Path::new("Key", "ink_primitives"))
.composite(Fields::unnamed().field_of::<[u8; 32]>("[u8; 32]"))
.composite(
Fields::unnamed().field(|f| f.ty::<[u8; 32]>().type_name("[u8; 32]")),
)
}
}
};
......
......@@ -23,7 +23,7 @@ ink_prelude = { version = "3.0.0-rc5", path = "../prelude/", default-features =
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
cfg-if = "1.0"
array-init = { version = "2.0", default-features = false }
......
......@@ -68,8 +68,11 @@ const _: () = {
// .type_params(vec![scale_info::MetaType::new::<T>()])
.composite(
scale_info::build::Fields::named()
.field_of::<DynamicAllocation>("allocation", "DynamicAllocation"),
)
.field(|f| f
.name("allocation")
.ty::<DynamicAllocation>()
.type_name("DynamicAllocation"),
))
}
}
};
......
......@@ -12,7 +12,7 @@ ink_storage = { version = "3.0.0-rc5", path = "../../crates/storage", default-fe
ink_lang = { version = "3.0.0-rc5", path = "../../crates/lang", default-features = false }
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
[lib]
name = "contract_terminate"
......
......@@ -13,7 +13,7 @@ ink_lang = { version = "3.0.0-rc5", path = "../../crates/lang", default-features
ink_prelude = { version = "3.0.0-rc5", path = "../../crates/prelude", default-features = false }
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
[lib]
name = "contract_transfer"
......
......@@ -16,7 +16,7 @@ scale = { package = "parity-scale-codec", version = "2", default-features = fals
adder = { version = "3.0.0-rc5", path = "adder", default-features = false, features = ["ink-as-dependency"] }
subber = { version = "3.0.0-rc5", path = "subber", default-features = false, features = ["ink-as-dependency"] }
accumulator = { version = "3.0.0-rc5", path = "accumulator", default-features = false, features = ["ink-as-dependency"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
[lib]
name = "delegator"
......
......@@ -12,7 +12,7 @@ ink_storage = { version = "3.0.0-rc5", path = "../../../crates/storage", default
ink_lang = { version = "3.0.0-rc5", path = "../../../crates/lang", default-features = false }
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
[lib]
name = "accumulator"
......
......@@ -14,7 +14,7 @@ ink_lang = { version = "3.0.0-rc5", path = "../../../crates/lang", default-featu
accumulator = { version = "3.0.0-rc5", path = "../accumulator", default-features = false, features = ["ink-as-dependency"] }
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
[lib]
name = "adder"
......
......@@ -14,7 +14,7 @@ ink_lang = { version = "3.0.0-rc5", path = "../../../crates/lang", default-featu
accumulator = { version = "3.0.0-rc5", path = "../accumulator", default-features = false, features = ["ink-as-dependency"] }
scale = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
[lib]
name = "subber"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment