Skip to content

Commit ff723b1

Browse files
ascjonesMichael Müllertash-2sRobin FreylerTriplEight
authored
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 <michi@parity.io> * Update crates/metadata/src/lib.rs Co-authored-by: Michael 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: Robin Freyler <robbepop@web.de> * cargo fmt Co-authored-by: Robin 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](rust-pretty-assertions/rust-pretty-assertions@v0.7.1...v1.0.0) --- updated-dependencies: - dependency-name: pretty_assertions dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add 'versioning' to spellcheck dict Co-authored-by: Michael Müller <michi@parity.io> Co-authored-by: tash-2s <81064017+tash-2s@users.noreply.github.com> Co-authored-by: Robin Freyler <robbepop@web.de> Co-authored-by: Denis Pisarev <denis.pisarev@parity.io> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 93d22fb commit ff723b1

File tree

31 files changed

+72
-40
lines changed

31 files changed

+72
-40
lines changed

.config/cargo_spellcheck.dic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ v3
6363
validator
6464
variadic
6565
versa
66+
versioning
6667
Verbatim
6768
metadata
6869
timestamp

RELEASES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This is the 6th release candidate for ink! 3.0.
44

55
## Changed
66

7+
- Update to `scale-info` 1.0 - [#845](https://github.com/paritytech/ink/pull/845).
78
- Message and constructor selectors no longer take their inputs as string but as `u32` decodable integer. For example:
89

910
- It is no longer possible to specify a selector as `#[ink(selector = "0xC0DECAFE")]`.

crates/env/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ blake2 = { version = "0.9", optional = true }
4040
# Sadly couldn't be marked as dev-dependency.
4141
# Never use this crate outside the off-chain environment!
4242
rand = { version = "0.8", default-features = false, features = ["alloc"], optional = true }
43-
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
43+
scale-info = { version = "1.0", default-features = false, features = ["derive"], optional = true }
4444

4545
[features]
4646
default = ["std"]

crates/lang/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static_assertions = "1.1"
2828

2929
[dev-dependencies]
3030
# required for the doctest of `env_access::EnvAccess::instantiate_contract`
31-
scale-info = { version = "0.6", default-features = false, features = ["derive"] }
31+
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
3232

3333
[features]
3434
default = ["std"]

crates/lang/codegen/src/generator/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ impl GenerateCode for Metadata<'_> {
4949
#no_cross_calling_cfg
5050
const _: () = {
5151
#[no_mangle]
52-
pub fn __ink_generate_metadata() -> ::ink_metadata::InkProject {
52+
pub fn __ink_generate_metadata() -> ::ink_metadata::MetadataVersioned {
5353
let contract: ::ink_metadata::ContractSpec = {
5454
#contract
5555
};
5656
let layout: ::ink_metadata::layout::Layout = {
5757
#layout
5858
};
59-
::ink_metadata::InkProject::new(layout, contract)
59+
::ink_metadata::InkProject::new(layout, contract).into()
6060
}
6161
};
6262
}

crates/lang/macro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ink_lang = { version = "3.0.0-rc5", path = ".." }
3131
ink_prelude = { version = "3.0.0-rc5", path = "../../prelude/" }
3232

3333
trybuild = "1.0.24"
34-
scale-info = { version = "0.6", default-features = false, features = ["derive"] }
34+
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
3535

3636
[lib]
3737
name = "ink_lang_macro"

crates/metadata/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ink_primitives = { version = "3.0.0-rc5", path = "../primitives/", default-featu
2121
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
2222
impl-serde = "0.3.1"
2323
derive_more = { version = "0.99", default-features = false, features = ["from"] }
24-
scale-info = { version = "0.6", default-features = false, features = ["derive", "serde"] }
24+
scale-info = { version = "1.0", default-features = false, features = ["derive", "serde", "decode"] }
2525

2626
[dev-dependencies]
2727
pretty_assertions = "1.0.0"

crates/metadata/src/layout/tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn named_fields_work() {
5858
0000000000000000\
5959
0000000000000000\
6060
0000000000000000",
61-
"ty": 1,
61+
"ty": 0,
6262
}
6363
},
6464
"name": "a",
@@ -71,7 +71,7 @@ fn named_fields_work() {
7171
0000000000000000\
7272
0000000000000000\
7373
0000000000000000",
74-
"ty": 2,
74+
"ty": 1,
7575
}
7676
},
7777
"name": "b",
@@ -115,7 +115,7 @@ fn tuple_struct_work() {
115115
0000000000000000\
116116
0000000000000000\
117117
0000000000000000",
118-
"ty": 1,
118+
"ty": 0,
119119
}
120120
},
121121
"name": null,
@@ -128,7 +128,7 @@ fn tuple_struct_work() {
128128
0000000000000000\
129129
0000000000000000\
130130
0000000000000000",
131-
"ty": 2,
131+
"ty": 1,
132132
}
133133
},
134134
"name": null,
@@ -261,7 +261,7 @@ fn mixed_enum_work() {
261261
0000000000000000\
262262
0000000000000000\
263263
0000000000000000",
264-
"ty": 1,
264+
"ty": 0,
265265
}
266266
},
267267
"name": null,
@@ -274,7 +274,7 @@ fn mixed_enum_work() {
274274
0000000000000000\
275275
0000000000000000\
276276
0000000000000000",
277-
"ty": 2,
277+
"ty": 1,
278278
}
279279
},
280280
"name": null,
@@ -291,7 +291,7 @@ fn mixed_enum_work() {
291291
0000000000000000\
292292
0000000000000000\
293293
0000000000000000",
294-
"ty": 1,
294+
"ty": 0,
295295
}
296296
},
297297
"name": "a",
@@ -304,7 +304,7 @@ fn mixed_enum_work() {
304304
0000000000000000\
305305
0000000000000000\
306306
0000000000000000",
307-
"ty": 2,
307+
"ty": 1,
308308
}
309309
},
310310
"name": "b",
@@ -348,7 +348,7 @@ fn unbounded_layout_works() {
348348
0000000000000000\
349349
0000000000000000\
350350
0000000000000000",
351-
"ty": 1
351+
"ty": 0
352352
}
353353
},
354354
"offset": "0x\

crates/metadata/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ use serde::{
5757
Serialize,
5858
};
5959

60+
/// Versioned ink! project metadata.
61+
///
62+
/// # Note
63+
///
64+
/// Represents the version of the serialized metadata *format*, which is distinct from the version
65+
/// of this crate for Rust semantic versioning compatibility.
66+
#[derive(Debug, Serialize, Deserialize)]
67+
#[allow(clippy::large_enum_variant)]
68+
pub enum MetadataVersioned {
69+
/// Version 0 placeholder. Represents the original non-versioned metadata format.
70+
V0(MetadataVersionDeprecated),
71+
/// Version 1 of the contract metadata.
72+
V1(InkProject),
73+
}
74+
75+
impl From<InkProject> for MetadataVersioned {
76+
fn from(ink_project: InkProject) -> Self {
77+
MetadataVersioned::V1(ink_project)
78+
}
79+
}
80+
81+
/// Enum to represent a deprecated metadata version that cannot be instantiated.
82+
#[derive(Debug, Serialize, Deserialize)]
83+
pub enum MetadataVersionDeprecated {}
84+
6085
/// An entire ink! project for metadata file generation purposes.
6186
#[derive(Debug, Serialize, Deserialize)]
6287
pub struct InkProject {

crates/metadata/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn spec_contract_json() {
114114
"displayName": [
115115
"i32"
116116
],
117-
"type": 1
117+
"type": 0
118118
}
119119
}
120120
],
@@ -140,7 +140,7 @@ fn spec_contract_json() {
140140
"displayName": [
141141
"i32"
142142
],
143-
"type": 1
143+
"type": 0
144144
}
145145
}
146146
],
@@ -161,7 +161,7 @@ fn spec_contract_json() {
161161
"displayName": [
162162
"i32"
163163
],
164-
"type": 1
164+
"type": 0
165165
},
166166
"selector": "0x25444afe"
167167
}

0 commit comments

Comments
 (0)