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

Update to new scale-info and codec releases (#663)

* Update to scale-info 0.5

* Update TypeInfo manual impls

* Update parity-scale-code to 2.0

* Add Encode ?Sized bounds

* Change type display name for Key custom TypeInfo impl

* Add missing ?Sized constraint

* Fmt

* Missing ?Sized bound in example
parent 2d10a700
Pipeline #122650 failed with stages
in 10 minutes and 21 seconds
...@@ -20,7 +20,7 @@ ink_allocator = { version = "3.0.0-rc2", path = "../allocator/", default-feature ...@@ -20,7 +20,7 @@ ink_allocator = { version = "3.0.0-rc2", path = "../allocator/", default-feature
ink_primitives = { version = "3.0.0-rc2", path = "../primitives/", default-features = false } ink_primitives = { version = "3.0.0-rc2", path = "../primitives/", default-features = false }
ink_prelude = { version = "3.0.0-rc2", path = "../prelude/", default-features = false } ink_prelude = { version = "3.0.0-rc2", path = "../prelude/", default-features = false }
scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive", "full"] } scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from", "display"] } derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }
num-traits = { version = "0.2", default-features = false, features = ["i128"] } num-traits = { version = "0.2", default-features = false, features = ["i128"] }
cfg-if = "1.0" cfg-if = "1.0"
...@@ -38,7 +38,7 @@ blake2 = { version = "0.9", optional = true } ...@@ -38,7 +38,7 @@ blake2 = { version = "0.9", optional = true }
# Sadly couldn't be marked as dev-dependency. # Sadly couldn't be marked as dev-dependency.
# Never use this crate outside of the off-chain environment! # Never use this crate outside of the off-chain environment!
rand = { version = "0.8", default-features = false, features = ["alloc"], optional = true } rand = { version = "0.8", default-features = false, features = ["alloc"], optional = true }
scale-info = { version = "0.4", default-features = false, features = ["derive"], optional = true } scale-info = { version = "0.5", default-features = false, features = ["derive"], optional = true }
[features] [features]
default = ["std"] default = ["std"]
......
...@@ -152,7 +152,7 @@ where ...@@ -152,7 +152,7 @@ where
} }
#[inline] #[inline]
fn encode_to<O: scale::Output>(&self, output: &mut O) { fn encode_to<O: scale::Output + ?Sized>(&self, output: &mut O) {
<T as scale::Encode>::encode_to(&self.arg, output) <T as scale::Encode>::encode_to(&self.arg, output)
} }
} }
...@@ -164,7 +164,7 @@ impl scale::Encode for EmptyArgumentList { ...@@ -164,7 +164,7 @@ impl scale::Encode for EmptyArgumentList {
} }
#[inline] #[inline]
fn encode_to<O: scale::Output>(&self, _output: &mut O) {} fn encode_to<O: scale::Output + ?Sized>(&self, _output: &mut O) {}
} }
impl<'a, Head, Rest> scale::Encode for ArgumentList<Argument<Head>, Rest> impl<'a, Head, Rest> scale::Encode for ArgumentList<Argument<Head>, Rest>
...@@ -178,7 +178,7 @@ where ...@@ -178,7 +178,7 @@ where
} }
#[inline] #[inline]
fn encode_to<O: scale::Output>(&self, output: &mut O) { fn encode_to<O: scale::Output + ?Sized>(&self, output: &mut O) {
// We reverse the order of encoding because we build up the list of // We reverse the order of encoding because we build up the list of
// arguments in reverse order, too. This way we encode the arguments // arguments in reverse order, too. This way we encode the arguments
// in the same order in which they have been pushed to the argument list // in the same order in which they have been pushed to the argument list
...@@ -198,7 +198,7 @@ where ...@@ -198,7 +198,7 @@ where
} }
#[inline] #[inline]
fn encode_to<O: scale::Output>(&self, output: &mut O) { fn encode_to<O: scale::Output + ?Sized>(&self, output: &mut O) {
scale::Encode::encode_to(&self.selector, output); scale::Encode::encode_to(&self.selector, output);
scale::Encode::encode_to(&self.args, output); scale::Encode::encode_to(&self.args, output);
} }
......
...@@ -74,7 +74,7 @@ impl scale::Encode for CallData { ...@@ -74,7 +74,7 @@ impl scale::Encode for CallData {
self.bytes.len() self.bytes.len()
} }
fn encode_to<T: scale::Output>(&self, dest: &mut T) { fn encode_to<T: scale::Output + ?Sized>(&self, dest: &mut T) {
dest.write(self.bytes.as_slice()); dest.write(self.bytes.as_slice());
} }
} }
......
...@@ -229,7 +229,7 @@ where ...@@ -229,7 +229,7 @@ where
} }
#[inline] #[inline]
fn encode_to<T: scale::Output>(&self, dest: &mut T) { fn encode_to<T: scale::Output + ?Sized>(&self, dest: &mut T) {
self.prefix.encode_to(dest); self.prefix.encode_to(dest);
self.value.encode_to(dest); self.value.encode_to(dest);
} }
......
...@@ -22,7 +22,7 @@ ink_metadata = { version = "3.0.0-rc2", path = "../metadata", default-features = ...@@ -22,7 +22,7 @@ ink_metadata = { version = "3.0.0-rc2", path = "../metadata", default-features =
ink_prelude = { version = "3.0.0-rc2", path = "../prelude/", default-features = false } ink_prelude = { version = "3.0.0-rc2", path = "../prelude/", default-features = false }
ink_lang_macro = { version = "3.0.0-rc2", path = "macro", default-features = false } ink_lang_macro = { version = "3.0.0-rc2", path = "macro", default-features = false }
scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive", "full"] } scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from"] } derive_more = { version = "0.99", default-features = false, features = ["from"] }
static_assertions = "1.1" static_assertions = "1.1"
......
...@@ -19,7 +19,7 @@ ink_lang_ir = { version = "3.0.0-rc2", path = "../ir", default-features = false ...@@ -19,7 +19,7 @@ ink_lang_ir = { version = "3.0.0-rc2", path = "../ir", default-features = false
ink_lang_codegen = { version = "3.0.0-rc2", path = "../codegen", default-features = false } ink_lang_codegen = { version = "3.0.0-rc2", path = "../codegen", default-features = false }
ink_primitives = { version = "3.0.0-rc2", path = "../../primitives/", default-features = false } ink_primitives = { version = "3.0.0-rc2", path = "../../primitives/", default-features = false }
scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
syn = "1" syn = "1"
proc-macro2 = "1" proc-macro2 = "1"
...@@ -30,7 +30,7 @@ ink_storage = { version = "3.0.0-rc2", path = "../../storage/" } ...@@ -30,7 +30,7 @@ ink_storage = { version = "3.0.0-rc2", path = "../../storage/" }
ink_lang = { version = "3.0.0-rc2", path = ".." } ink_lang = { version = "3.0.0-rc2", path = ".." }
trybuild = "1.0.24" trybuild = "1.0.24"
scale-info = { version = "0.4", default-features = false, features = ["derive"] } scale-info = { version = "0.5", default-features = false, features = ["derive"] }
[lib] [lib]
name = "ink_lang_macro" name = "ink_lang_macro"
......
...@@ -21,7 +21,7 @@ ink_primitives = { version = "3.0.0-rc2", path = "../primitives/", default-featu ...@@ -21,7 +21,7 @@ ink_primitives = { version = "3.0.0-rc2", path = "../primitives/", default-featu
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] } serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
impl-serde = "0.3.1" impl-serde = "0.3.1"
derive_more = { version = "0.99", default-features = false, features = ["from"] } derive_more = { version = "0.99", default-features = false, features = ["from"] }
scale-info = { version = "0.4", default-features = false, features = ["derive"] } scale-info = { version = "0.5", default-features = false, features = ["derive", "serde"] }
[dev-dependencies] [dev-dependencies]
pretty_assertions = "0.6.1" pretty_assertions = "0.6.1"
......
...@@ -27,12 +27,12 @@ use ink_prelude::collections::btree_map::BTreeMap; ...@@ -27,12 +27,12 @@ use ink_prelude::collections::btree_map::BTreeMap;
use ink_primitives::Key; use ink_primitives::Key;
use scale_info::{ use scale_info::{
form::{ form::{
CompactForm,
Form, Form,
MetaForm, MetaForm,
PortableForm,
}, },
meta_type, meta_type,
IntoCompact, IntoPortable,
Registry, Registry,
TypeInfo, TypeInfo,
}; };
...@@ -146,10 +146,10 @@ impl CellLayout { ...@@ -146,10 +146,10 @@ impl CellLayout {
} }
} }
impl IntoCompact for CellLayout { impl IntoPortable for CellLayout {
type Output = CellLayout<CompactForm>; type Output = CellLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output { fn into_portable(self, registry: &mut Registry) -> Self::Output {
CellLayout { CellLayout {
key: self.key, key: self.key,
ty: registry.register_type(&self.ty), ty: registry.register_type(&self.ty),
...@@ -157,22 +157,26 @@ impl IntoCompact for CellLayout { ...@@ -157,22 +157,26 @@ impl IntoCompact for CellLayout {
} }
} }
impl IntoCompact for Layout { impl IntoPortable for Layout {
type Output = Layout<CompactForm>; type Output = Layout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output { fn into_portable(self, registry: &mut Registry) -> Self::Output {
match self { match self {
Layout::Cell(encoded_cell) => { Layout::Cell(encoded_cell) => {
Layout::Cell(encoded_cell.into_compact(registry)) Layout::Cell(encoded_cell.into_portable(registry))
}
Layout::Hash(hash_layout) => {
Layout::Hash(hash_layout.into_portable(registry))
} }
Layout::Hash(hash_layout) => Layout::Hash(hash_layout.into_compact(registry)),
Layout::Array(array_layout) => { Layout::Array(array_layout) => {
Layout::Array(array_layout.into_compact(registry)) Layout::Array(array_layout.into_portable(registry))
} }
Layout::Struct(struct_layout) => { Layout::Struct(struct_layout) => {
Layout::Struct(struct_layout.into_compact(registry)) Layout::Struct(struct_layout.into_portable(registry))
}
Layout::Enum(enum_layout) => {
Layout::Enum(enum_layout.into_portable(registry))
} }
Layout::Enum(enum_layout) => Layout::Enum(enum_layout.into_compact(registry)),
} }
} }
} }
...@@ -209,14 +213,14 @@ pub struct HashLayout<F: Form = MetaForm> { ...@@ -209,14 +213,14 @@ pub struct HashLayout<F: Form = MetaForm> {
layout: Box<Layout<F>>, layout: Box<Layout<F>>,
} }
impl IntoCompact for HashLayout { impl IntoPortable for HashLayout {
type Output = HashLayout<CompactForm>; type Output = HashLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output { fn into_portable(self, registry: &mut Registry) -> Self::Output {
HashLayout { HashLayout {
offset: self.offset, offset: self.offset,
strategy: self.strategy, strategy: self.strategy,
layout: Box::new(self.layout.into_compact(registry)), layout: Box::new(self.layout.into_portable(registry)),
} }
} }
} }
...@@ -380,15 +384,15 @@ where ...@@ -380,15 +384,15 @@ where
} }
} }
impl IntoCompact for ArrayLayout { impl IntoPortable for ArrayLayout {
type Output = ArrayLayout<CompactForm>; type Output = ArrayLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output { fn into_portable(self, registry: &mut Registry) -> Self::Output {
ArrayLayout { ArrayLayout {
offset: self.offset, offset: self.offset,
len: self.len, len: self.len,
cells_per_elem: self.cells_per_elem, cells_per_elem: self.cells_per_elem,
layout: Box::new(self.layout.into_compact(registry)), layout: Box::new(self.layout.into_portable(registry)),
} }
} }
} }
...@@ -426,15 +430,15 @@ where ...@@ -426,15 +430,15 @@ where
} }
} }
impl IntoCompact for StructLayout { impl IntoPortable for StructLayout {
type Output = StructLayout<CompactForm>; type Output = StructLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output { fn into_portable(self, registry: &mut Registry) -> Self::Output {
StructLayout { StructLayout {
fields: self fields: self
.fields .fields
.into_iter() .into_iter()
.map(|field| field.into_compact(registry)) .map(|field| field.into_portable(registry))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
} }
} }
...@@ -492,13 +496,13 @@ where ...@@ -492,13 +496,13 @@ where
} }
} }
impl IntoCompact for FieldLayout { impl IntoPortable for FieldLayout {
type Output = FieldLayout<CompactForm>; type Output = FieldLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output { fn into_portable(self, registry: &mut Registry) -> Self::Output {
FieldLayout { FieldLayout {
name: self.name.map(|name| name.into_compact(registry)), name: self.name.map(|name| name.into_portable(registry)),
layout: self.layout.into_compact(registry), layout: self.layout.into_portable(registry),
} }
} }
} }
...@@ -563,17 +567,17 @@ where ...@@ -563,17 +567,17 @@ where
} }
} }
impl IntoCompact for EnumLayout { impl IntoPortable for EnumLayout {
type Output = EnumLayout<CompactForm>; type Output = EnumLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output { fn into_portable(self, registry: &mut Registry) -> Self::Output {
EnumLayout { EnumLayout {
dispatch_key: self.dispatch_key, dispatch_key: self.dispatch_key,
variants: self variants: self
.variants .variants
.into_iter() .into_iter()
.map(|(discriminant, layout)| { .map(|(discriminant, layout)| {
(discriminant, layout.into_compact(registry)) (discriminant, layout.into_portable(registry))
}) })
.collect(), .collect(),
} }
......
...@@ -44,7 +44,7 @@ fn named_fields_struct_layout(key_ptr: &mut KeyPtr) -> Layout { ...@@ -44,7 +44,7 @@ fn named_fields_struct_layout(key_ptr: &mut KeyPtr) -> Layout {
fn named_fields_work() { fn named_fields_work() {
let layout = named_fields_struct_layout(&mut KeyPtr::from(Key::from([0x00; 32]))); let layout = named_fields_struct_layout(&mut KeyPtr::from(Key::from([0x00; 32])));
let mut registry = Registry::new(); let mut registry = Registry::new();
let compacted = layout.into_compact(&mut registry); let compacted = layout.into_portable(&mut registry);
let json = serde_json::to_value(&compacted).unwrap(); let json = serde_json::to_value(&compacted).unwrap();
let expected = serde_json::json! { let expected = serde_json::json! {
{ {
...@@ -101,7 +101,7 @@ fn tuple_struct_layout(key_ptr: &mut KeyPtr) -> Layout { ...@@ -101,7 +101,7 @@ fn tuple_struct_layout(key_ptr: &mut KeyPtr) -> Layout {
fn tuple_struct_work() { fn tuple_struct_work() {
let layout = tuple_struct_layout(&mut KeyPtr::from(Key::from([0x00; 32]))); let layout = tuple_struct_layout(&mut KeyPtr::from(Key::from([0x00; 32])));
let mut registry = Registry::new(); let mut registry = Registry::new();
let compacted = layout.into_compact(&mut registry); let compacted = layout.into_portable(&mut registry);
let json = serde_json::to_value(&compacted).unwrap(); let json = serde_json::to_value(&compacted).unwrap();
let expected = serde_json::json! { let expected = serde_json::json! {
{ {
...@@ -156,7 +156,7 @@ fn clike_enum_layout(key_ptr: &mut KeyPtr) -> Layout { ...@@ -156,7 +156,7 @@ fn clike_enum_layout(key_ptr: &mut KeyPtr) -> Layout {
fn clike_enum_work() { fn clike_enum_work() {
let layout = clike_enum_layout(&mut KeyPtr::from(Key::from([0x00; 32]))); let layout = clike_enum_layout(&mut KeyPtr::from(Key::from([0x00; 32])));
let mut registry = Registry::new(); let mut registry = Registry::new();
let compacted = layout.into_compact(&mut registry); let compacted = layout.into_portable(&mut registry);
let json = serde_json::to_value(&compacted).unwrap(); let json = serde_json::to_value(&compacted).unwrap();
let expected = serde_json::json! { let expected = serde_json::json! {
{ {
...@@ -237,7 +237,7 @@ fn mixed_enum_layout(key_ptr: &mut KeyPtr) -> Layout { ...@@ -237,7 +237,7 @@ fn mixed_enum_layout(key_ptr: &mut KeyPtr) -> Layout {
fn mixed_enum_work() { fn mixed_enum_work() {
let layout = mixed_enum_layout(&mut KeyPtr::from(Key::from([0x00; 32]))); let layout = mixed_enum_layout(&mut KeyPtr::from(Key::from([0x00; 32])));
let mut registry = Registry::new(); let mut registry = Registry::new();
let compacted = layout.into_compact(&mut registry); let compacted = layout.into_portable(&mut registry);
let json = serde_json::to_value(&compacted).unwrap(); let json = serde_json::to_value(&compacted).unwrap();
let expected = serde_json::json! { let expected = serde_json::json! {
{ {
...@@ -336,7 +336,7 @@ fn unbounded_hashing_layout(key_ptr: &mut KeyPtr) -> Layout { ...@@ -336,7 +336,7 @@ fn unbounded_hashing_layout(key_ptr: &mut KeyPtr) -> Layout {
fn unbounded_layout_works() { fn unbounded_layout_works() {
let layout = unbounded_hashing_layout(&mut KeyPtr::from(Key::from([0x00; 32]))); let layout = unbounded_hashing_layout(&mut KeyPtr::from(Key::from([0x00; 32])));
let mut registry = Registry::new(); let mut registry = Registry::new();
let compacted = layout.into_compact(&mut registry); let compacted = layout.into_portable(&mut registry);
let json = serde_json::to_value(&compacted).unwrap(); let json = serde_json::to_value(&compacted).unwrap();
let expected = serde_json::json! { let expected = serde_json::json! {
{ {
......
...@@ -47,25 +47,30 @@ use impl_serde::serialize as serde_hex; ...@@ -47,25 +47,30 @@ use impl_serde::serialize as serde_hex;
#[cfg(feature = "derive")] #[cfg(feature = "derive")]
use scale_info::{ use scale_info::{
form::CompactForm, form::{
IntoCompact as _, FormString,
PortableForm,
},
IntoPortable as _,
PortableRegistry,
Registry, Registry,
RegistryReadOnly,
}; };
use serde::{ use serde::{
de::DeserializeOwned,
Deserialize, Deserialize,
Serialize, Serialize,
}; };
/// An entire ink! project for metadata file generation purposes. /// An entire ink! project for metadata file generation purposes.
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct InkProject { #[serde(bound(deserialize = "S: DeserializeOwned"))]
pub struct InkProject<S: FormString = &'static str> {
#[serde(flatten)] #[serde(flatten)]
registry: RegistryReadOnly, registry: PortableRegistry<S>,
#[serde(rename = "storage")] #[serde(rename = "storage")]
/// The layout of the storage data structure /// The layout of the storage data structure
layout: layout::Layout<CompactForm>, layout: layout::Layout<PortableForm<S>>,
spec: ContractSpec<CompactForm>, spec: ContractSpec<PortableForm<S>>,
} }
impl InkProject { impl InkProject {
...@@ -77,26 +82,29 @@ impl InkProject { ...@@ -77,26 +82,29 @@ impl InkProject {
let mut registry = Registry::new(); let mut registry = Registry::new();
Self { Self {
layout: layout.into().into_compact(&mut registry), layout: layout.into().into_portable(&mut registry),
spec: spec.into().into_compact(&mut registry), spec: spec.into().into_portable(&mut registry),
registry: registry.into(), registry: registry.into(),
} }
} }
} }
impl InkProject { impl<S> InkProject<S>
where
S: FormString,
{
/// Returns a read-only registry of types in the contract. /// Returns a read-only registry of types in the contract.
pub fn registry(&self) -> &RegistryReadOnly { pub fn registry(&self) -> &PortableRegistry<S> {
&self.registry &self.registry
} }
/// Returns the storage layout of the contract. /// Returns the storage layout of the contract.
pub fn layout(&self) -> &layout::Layout<CompactForm> { pub fn layout(&self) -> &layout::Layout<PortableForm<S>> {
&self.layout &self.layout
} }
/// Returns the specification of the contract. /// Returns the specification of the contract.
pub fn spec(&self) -> &ContractSpec<CompactForm> { pub fn spec(&self) -> &ContractSpec<PortableForm<S>> {
&self.spec &self.spec
} }
} }
...@@ -24,12 +24,12 @@ use alloc::{ ...@@ -24,12 +24,12 @@ use alloc::{
use core::marker::PhantomData; use core::marker::PhantomData;
use scale_info::{ use scale_info::{
form::{ form::{
CompactForm,
Form, Form,
MetaForm, MetaForm,
PortableForm,
}, },
meta_type, meta_type,
IntoCompact, IntoPortable,
Registry, Registry,
TypeInfo, TypeInfo,
}; };
...@@ -56,27 +56,27 @@ pub struct ContractSpec<F: Form = MetaForm> { ...@@ -56,27 +56,27 @@ pub struct ContractSpec<F: Form = MetaForm> {
docs: Vec<F::String>, docs: Vec<F::String>,
} }
impl IntoCompact for ContractSpec { impl IntoPortable for ContractSpec {