diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index acfff9a0d90..633c622b029 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -255,7 +255,7 @@ publish-docs: - git fetch origin gh-pages # Generating Docs - time cargo doc --no-deps --all-features - -p scale-info -p ink_metadata -p ink_metadata_derive -p ink_core -p ink_core_derive + -p scale-info -p ink_metadata -p ink_core -p ink_core_derive -p ink_primitives -p ink_prelude -p ink_lang -p ink_lang_macro # saving README and docs - mv target/doc/ /tmp/ diff --git a/core/Cargo.toml b/core/Cargo.toml index c33e4336538..9d9baf127fe 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -39,7 +39,7 @@ blake2 = { version = "0.9", optional = true } # Sadly couldn't be marked as dev-dependency. # Never use this crate outside of the off-chain environment! rand = { version = "0.7", default-features = false, features = ["alloc"], optional = true } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } # Workaround: we actually just need criterion as a dev-dependency, but # there is an issue with a doubly included std lib when executing diff --git a/examples/delegator/Cargo.toml b/examples/delegator/Cargo.toml index a8c0d7a700c..910e1828ea0 100644 --- a/examples/delegator/Cargo.toml +++ b/examples/delegator/Cargo.toml @@ -15,7 +15,7 @@ scale = { package = "parity-scale-codec", version = "1.3", default-features = fa adder = { version = "2.1.0", path = "adder", default-features = false, features = ["ink-as-dependency"] } subber = { version = "2.1.0", path = "subber", default-features = false, features = ["ink-as-dependency"] } accumulator = { version = "2.1.0", path = "accumulator", default-features = false, features = ["ink-as-dependency"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "delegator" diff --git a/examples/delegator/accumulator/Cargo.toml b/examples/delegator/accumulator/Cargo.toml index c73e3ca040b..22546b14a96 100644 --- a/examples/delegator/accumulator/Cargo.toml +++ b/examples/delegator/accumulator/Cargo.toml @@ -11,7 +11,7 @@ ink_core = { version = "2.1.0", path = "../../../core", default-features = false ink_lang = { version = "2.1.0", path = "../../../lang", default-features = false } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "accumulator" diff --git a/examples/delegator/adder/Cargo.toml b/examples/delegator/adder/Cargo.toml index 0927aabbced..4199434d73a 100644 --- a/examples/delegator/adder/Cargo.toml +++ b/examples/delegator/adder/Cargo.toml @@ -13,7 +13,7 @@ ink_lang = { version = "2.1.0", path = "../../../lang", default-features = false accumulator = { version = "2.1.0", path = "../accumulator", default-features = false, features = ["ink-as-dependency"] } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "adder" diff --git a/examples/delegator/subber/Cargo.toml b/examples/delegator/subber/Cargo.toml index fd871993eb1..ac1afb3b520 100644 --- a/examples/delegator/subber/Cargo.toml +++ b/examples/delegator/subber/Cargo.toml @@ -13,7 +13,7 @@ ink_lang = { version = "2.1.0", path = "../../../lang", default-features = false accumulator = { version = "2.1.0", path = "../accumulator", default-features = false, features = ["ink-as-dependency"] } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "subber" diff --git a/examples/dns/Cargo.toml b/examples/dns/Cargo.toml index e0b2251b733..ebfea57bb08 100644 --- a/examples/dns/Cargo.toml +++ b/examples/dns/Cargo.toml @@ -11,7 +11,7 @@ ink_core = { version = "2.1.0", path = "../../core", default-features = false } ink_lang = { version = "2.1.0", path = "../../lang", default-features = false } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "dns" diff --git a/examples/erc20/Cargo.toml b/examples/erc20/Cargo.toml index 278adafc2f1..e3faa083a4c 100644 --- a/examples/erc20/Cargo.toml +++ b/examples/erc20/Cargo.toml @@ -11,7 +11,7 @@ ink_core = { version = "2.1.0", path = "../../core", default-features = false } ink_lang = { version = "2.1.0", path = "../../lang", default-features = false } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "erc20" diff --git a/examples/erc721/Cargo.toml b/examples/erc721/Cargo.toml index 1ecbfc7b799..0be4ddcdf19 100644 --- a/examples/erc721/Cargo.toml +++ b/examples/erc721/Cargo.toml @@ -11,7 +11,7 @@ ink_core = { version = "2.1.0", path = "../../core", default-features = false } ink_lang = { version = "2.1.0", path = "../../lang", default-features = false } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "erc721" diff --git a/examples/flipper/Cargo.toml b/examples/flipper/Cargo.toml index bd9b30bd252..7b71ec0d6aa 100644 --- a/examples/flipper/Cargo.toml +++ b/examples/flipper/Cargo.toml @@ -11,7 +11,7 @@ ink_core = { version = "2.1.0", path = "../../core", default-features = false } ink_lang = { version = "2.1.0", path = "../../lang", default-features = false } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "flipper" diff --git a/examples/incrementer/Cargo.toml b/examples/incrementer/Cargo.toml index 6eae4916db6..4e430362190 100644 --- a/examples/incrementer/Cargo.toml +++ b/examples/incrementer/Cargo.toml @@ -11,7 +11,7 @@ ink_core = { version = "2.1.0", path = "../../core", default-features = false } ink_lang = { version = "2.1.0", path = "../../lang", default-features = false } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "incrementer" diff --git a/examples/multisig_plain/Cargo.toml b/examples/multisig_plain/Cargo.toml index d93ec43c2f2..3fa9aa649b6 100755 --- a/examples/multisig_plain/Cargo.toml +++ b/examples/multisig_plain/Cargo.toml @@ -12,7 +12,7 @@ ink_lang = { version = "2.1.0", path = "../../lang", default-features = false } ink_prelude = { version = "2.1.0", path = "../../prelude", default-features = false } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "multisig_plain" diff --git a/examples/runtime-storage/Cargo.toml b/examples/runtime-storage/Cargo.toml index 44db1bc621b..b95575d3e33 100755 --- a/examples/runtime-storage/Cargo.toml +++ b/examples/runtime-storage/Cargo.toml @@ -12,7 +12,7 @@ ink_core = { version = "2.1.0", path = "../../core", default-features = false } ink_lang = { version = "2.1.0", path = "../../lang", default-features = false } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [lib] name = "runtime_storage" diff --git a/lang/macro/Cargo.toml b/lang/macro/Cargo.toml index 91964f88023..5b1710f93bb 100644 --- a/lang/macro/Cargo.toml +++ b/lang/macro/Cargo.toml @@ -36,7 +36,7 @@ ink_lang = { version = "2.1.0", path = ".." } trybuild = "1.0.24" pretty_assertions = "0.6.1" -scale-info = { version = "0.2", default-features = false, features = ["derive"] } +scale-info = { version = "0.3", default-features = false, features = ["derive"] } [lib] name = "ink_lang_macro" diff --git a/lang/macro/src/codegen/metadata.rs b/lang/macro/src/codegen/metadata.rs index 0f67e3b89b1..3621ced43d1 100644 --- a/lang/macro/src/codegen/metadata.rs +++ b/lang/macro/src/codegen/metadata.rs @@ -242,15 +242,13 @@ impl GenerateMetadata<'_> { } fn generate_contract(&self) -> TokenStream2 { - let contract_ident_lit = self.contract.ident.to_string(); - let constructors = self.generate_constructors(); let messages = self.generate_messages(); let events = self.generate_events(); let docs = self.generate_docs(); quote! { - ::ink_metadata::ContractSpec::new(#contract_ident_lit) + ::ink_metadata::ContractSpec::new() .constructors(vec![ #(#constructors ,)* ]) diff --git a/metadata/Cargo.toml b/metadata/Cargo.toml index d609075a490..ac2fc01c23c 100644 --- a/metadata/Cargo.toml +++ b/metadata/Cargo.toml @@ -20,11 +20,11 @@ ink_primitives = { version = "2.1.0", path = "../primitives/", default-features serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] } derive_more = { version = "0.99", default-features = false, features = ["from"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"] } +scale-info = { version = "0.3", default-features = false, features = ["derive"] } [dev-dependencies] +pretty_assertions = "0.6.1" serde_json = "1.0" -assert-json-diff = "1.0.1" [features] default = [ diff --git a/metadata/src/layout2/mod.rs b/metadata/src/layout2/mod.rs index fe2cdfae8bb..b475a2528d4 100644 --- a/metadata/src/layout2/mod.rs +++ b/metadata/src/layout2/mod.rs @@ -300,7 +300,7 @@ pub struct FieldLayout { /// The name of the field. /// /// Can be missing, e.g. in case of an enum tuple struct variant. - name: Option, + name: Option<&'static str>, /// The kind of the field. /// /// This is either a direct layout bound @@ -312,7 +312,7 @@ impl FieldLayout { /// Creates a new field layout. pub fn new(name: N, layout: L) -> Self where - N: Into::String>>, + N: Into>, L: Into, { Self { @@ -327,7 +327,7 @@ impl IntoCompact for FieldLayout { fn into_compact(self, registry: &mut Registry) -> Self::Output { FieldLayout { - name: self.name.map(|name| registry.register_string(name)), + name: self.name, layout: self.layout.into_compact(registry), } } diff --git a/metadata/src/layout2/tests.rs b/metadata/src/layout2/tests.rs index de6b4e2fecc..d4604f8974e 100644 --- a/metadata/src/layout2/tests.rs +++ b/metadata/src/layout2/tests.rs @@ -14,6 +14,7 @@ use super::*; use ink_primitives::KeyPtr; +use pretty_assertions::assert_eq; #[test] fn layout_key_works() { @@ -60,7 +61,7 @@ fn named_fields_work() { "ty": 1, } }, - "name": 1, + "name": "a", }, { "layout": { @@ -73,7 +74,7 @@ fn named_fields_work() { "ty": 2, } }, - "name": 2, + "name": "b", } ] } @@ -293,7 +294,7 @@ fn mixed_enum_work() { "ty": 1, } }, - "name": 1, + "name": "a", }, { "layout": { @@ -306,7 +307,7 @@ fn mixed_enum_work() { "ty": 2, } }, - "name": 2, + "name": "b", } ], }, diff --git a/metadata/src/lib.rs b/metadata/src/lib.rs index d0b1e409688..4106a66b70c 100644 --- a/metadata/src/lib.rs +++ b/metadata/src/lib.rs @@ -41,6 +41,7 @@ pub use self::specs::{ ReturnTypeSpec, TypeSpec, }; + #[cfg(feature = "derive")] use scale_info::{ form::CompactForm, @@ -49,24 +50,25 @@ use scale_info::{ }; use serde::Serialize; -/// An entire ink! project for ABI file generation purposes. +/// An entire ink! project for metadata file generation purposes. #[derive(Debug, Serialize)] pub struct InkProject { + #[serde(flatten)] registry: Registry, #[serde(rename = "storage")] + /// The layout of the storage data structure layout: layout2::Layout, - #[serde(rename = "contract")] spec: ContractSpec, } impl InkProject { - /// Creates a new ink! project. pub fn new(layout: L, spec: S) -> Self where L: Into, S: Into, { let mut registry = Registry::new(); + Self { layout: layout.into().into_compact(&mut registry), spec: spec.into().into_compact(&mut registry), diff --git a/metadata/src/specs.rs b/metadata/src/specs.rs index cdd8cdb25cf..3b0c49037dd 100644 --- a/metadata/src/specs.rs +++ b/metadata/src/specs.rs @@ -39,8 +39,6 @@ use serde::Serialize; #[derive(Debug, PartialEq, Eq, Serialize)] #[serde(bound = "F::TypeId: Serialize")] pub struct ContractSpec { - /// The name of the contract. - name: F::String, /// The set of constructors of the contract. constructors: Vec>, /// The external messages of the contract. @@ -56,7 +54,6 @@ impl IntoCompact for ContractSpec { fn into_compact(self, registry: &mut Registry) -> Self::Output { ContractSpec { - name: registry.register_string(&self.name), constructors: self .constructors .into_iter() @@ -171,10 +168,9 @@ impl ContractSpecBuilder { impl ContractSpec { /// Creates a new contract specification. - pub fn new(name: ::String) -> ContractSpecBuilder { + pub fn new() -> ContractSpecBuilder { ContractSpecBuilder { spec: Self { - name, constructors: Vec::new(), messages: Vec::new(), events: Vec::new(), @@ -190,7 +186,7 @@ impl ContractSpec { #[serde(bound = "F::TypeId: Serialize")] pub struct ConstructorSpec { /// The name of the message. - name: F::String, + name: &'static str, /// The selector hash of the message. #[serde(serialize_with = "serialize_as_byte_str")] selector: [u8; 4], @@ -205,7 +201,7 @@ impl IntoCompact for ConstructorSpec { fn into_compact(self, registry: &mut Registry) -> Self::Output { ConstructorSpec { - name: registry.register_string(&self.name), + name: self.name, selector: self.selector, args: self .args @@ -231,9 +227,7 @@ pub struct ConstructorSpecBuilder { impl ConstructorSpec { /// Creates a new constructor spec builder. - pub fn new( - name: ::String, - ) -> ConstructorSpecBuilder> { + pub fn new(name: &'static str) -> ConstructorSpecBuilder> { ConstructorSpecBuilder { spec: Self { name, @@ -296,7 +290,7 @@ impl ConstructorSpecBuilder { #[serde(rename_all = "camelCase")] pub struct MessageSpec { /// The name of the message. - name: F::String, + name: &'static str, /// The selector hash of the message. #[serde(serialize_with = "serialize_as_byte_str")] selector: [u8; 4], @@ -329,7 +323,7 @@ mod state { impl MessageSpec { /// Creates a new message spec builder. pub fn new( - name: ::String, + name: &'static str, ) -> MessageSpecBuilder< Missing, Missing, @@ -443,7 +437,7 @@ impl IntoCompact for MessageSpec { fn into_compact(self, registry: &mut Registry) -> Self::Output { MessageSpec { - name: registry.register_string(&self.name), + name: self.name, selector: self.selector, mutates: self.mutates, args: self @@ -462,7 +456,7 @@ impl IntoCompact for MessageSpec { #[serde(bound = "F::TypeId: Serialize")] pub struct EventSpec { /// The name of the event. - name: F::String, + name: &'static str, /// The event arguments. args: Vec>, /// The event documentation. @@ -508,7 +502,7 @@ impl IntoCompact for EventSpec { fn into_compact(self, registry: &mut Registry) -> Self::Output { EventSpec { - name: registry.register_string(&self.name), + name: self.name, args: self .args .into_iter() @@ -549,7 +543,7 @@ impl EventSpec { /// default setup. Even though it would be useful for third party tools /// such as the Polkadot UI to know that we are handling with `Balance` /// types, we currently cannot communicate this without display names. -pub type DisplayName = scale_info::Path; +pub type DisplayName = scale_info::Path; /// A type specification. /// @@ -575,7 +569,7 @@ pub struct TypeSpec { /// The actual type. id: F::TypeId, /// The compile-time known displayed representation of the type. - display_name: DisplayName, + display_name: DisplayName, } impl IntoCompact for TypeSpec { @@ -584,7 +578,7 @@ impl IntoCompact for TypeSpec { fn into_compact(self, registry: &mut Registry) -> Self::Output { TypeSpec { id: registry.register_type(&self.id), - display_name: self.display_name.into_compact(registry), + display_name: self.display_name, } } } @@ -623,7 +617,7 @@ impl TypeSpec { pub fn with_name_segs(segments: S) -> Self where T: TypeInfo + 'static, - S: IntoIterator::String>, + S: IntoIterator, { Self { id: meta_type::(), @@ -649,7 +643,7 @@ impl TypeSpec { #[serde(bound = "F::TypeId: Serialize")] pub struct EventParamSpec { /// The name of the parameter. - name: F::String, + name: &'static str, /// If the event parameter is indexed. indexed: bool, /// The type of the parameter. @@ -664,7 +658,7 @@ impl IntoCompact for EventParamSpec { fn into_compact(self, registry: &mut Registry) -> Self::Output { EventParamSpec { - name: registry.register_string(self.name), + name: self.name, indexed: self.indexed, ty: self.ty.into_compact(registry), docs: self.docs, @@ -776,7 +770,7 @@ impl ReturnTypeSpec { #[serde(bound = "F::TypeId: Serialize")] pub struct MessageParamSpec { /// The name of the parameter. - name: F::String, + name: &'static str, /// The type of the parameter. #[serde(rename = "type")] ty: TypeSpec, @@ -787,7 +781,7 @@ impl IntoCompact for MessageParamSpec { fn into_compact(self, registry: &mut Registry) -> Self::Output { MessageParamSpec { - name: registry.register_string(self.name), + name: self.name, ty: self.ty.into_compact(registry), } } diff --git a/metadata/src/tests.rs b/metadata/src/tests.rs index 3202413b8ff..aa4b6794901 100644 --- a/metadata/src/tests.rs +++ b/metadata/src/tests.rs @@ -13,7 +13,7 @@ // limitations under the License. use super::*; -use assert_json_diff::assert_json_eq; +use pretty_assertions::assert_eq; use scale_info::{ IntoCompact, Registry, @@ -34,10 +34,10 @@ fn spec_constructor_selector_must_serialize_to_hex() { let json = serde_json::to_value(&cs.into_compact(&mut registry)).unwrap(); // then - assert_json_eq!( + assert_eq!( json, json!({ - "name": 1, + "name": "foo", "selector": "0x075bcd15", "args": [], "docs": [] @@ -48,7 +48,7 @@ fn spec_constructor_selector_must_serialize_to_hex() { #[test] fn spec_contract_json() { // given - let contract: ContractSpec = ContractSpec::new("incrementer") + let contract: ContractSpec = ContractSpec::new() .constructors(vec![ ConstructorSpec::new("new") .selector([94u8, 189u8, 136u8, 214u8]) @@ -97,30 +97,30 @@ fn spec_contract_json() { let json = serde_json::to_value(&contract.into_compact(&mut registry)).unwrap(); // then - assert_json_eq!( + assert_eq!( json, json!({ "constructors": [ { "args": [ { - "name": 3, + "name": "init_value", "type": { "displayName": [ - 4 + "i32" ], "id": 1 } } ], "docs": [], - "name": 2, + "name": "new", "selector": "0x5ebd88d6" }, { "args": [], "docs": [], - "name": 5, + "name": "default", "selector": "0x0222ff18" } ], @@ -130,10 +130,10 @@ fn spec_contract_json() { { "args": [ { - "name": 7, + "name": "by", "type": { "displayName": [ - 4 + "i32" ], "id": 1 } @@ -141,7 +141,7 @@ fn spec_contract_json() { ], "docs": [], "mutates": true, - "name": 6, + "name": "inc", "returnType": null, "selector": "0xe7d0590f" }, @@ -149,17 +149,16 @@ fn spec_contract_json() { "args": [], "docs": [], "mutates": false, - "name": 8, + "name": "get", "returnType": { "displayName": [ - 4 + "i32" ], "id": 1 }, "selector": "0x25444afe" } ], - "name": 1 }) ) } diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index f8c1d2d5504..68467e3e506 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -21,7 +21,7 @@ include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"] ink_prelude = { version = "2.1.0", path = "../prelude/", default-features = false } tiny-keccak = { version = "2.0", features = ["keccak"] } scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive", "full"] } -scale-info = { version = "0.2", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.3", default-features = false, features = ["derive"], optional = true } [dev-dependencies] criterion = "0.3.1"