diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 266cb59..6000d68 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -137,7 +137,7 @@ jobs: version: 0.5 - name: Checking wasm32 (v14) - run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --features v14 --skip legacy,v8,v9,v10,v11,v12,v13 --depth 4 --target wasm32-unknown-unknown + run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --features current --skip legacy --depth 4 --target wasm32-unknown-unknown - name: Checking wasm32 (all features) run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --skip decode,serde_full --depth 4 --target wasm32-unknown-unknown @@ -167,7 +167,7 @@ jobs: version: 0.5 - name: Checking v14 feature combinations (native) - run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --features v14 --skip legacy,v8,v9,v10,v11,v12,v13 --depth 4 + run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --features current --skip legacy --depth 4 - name: Checking feature combinations excluding decode/serde_full (native) run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --skip decode,serde_full --depth 4 diff --git a/frame-metadata/Cargo.toml b/frame-metadata/Cargo.toml index 2eb7760..9985da3 100644 --- a/frame-metadata/Cargo.toml +++ b/frame-metadata/Cargo.toml @@ -19,16 +19,16 @@ scale-info = { version = "2.0.0", default-features = false, optional = true, fea serde = { version = "1.0.101", default-features = false, optional = true, features = ["derive"] } [features] -default = ["std", "v14"] -v8 = [] -v9 = [] -v10 = [] -v11 = [] -v12 = [] -v13 = [] -legacy = ["v13", "v12", "v11", "v10", "v9", "v8"] -v14 = ["scale-info"] -v15-unstable = ["scale-info"] +default = ["std", "current"] + +# Feature flag for pre-V14 versions. +legacy = [] + +# The current stable metadata versions. +current = ["scale-info"] + +# Unstable next metadata version. +unstable = ["current"] # Serde support without relying on std features serde_full = [ @@ -36,6 +36,7 @@ serde_full = [ "serde", "serde/alloc", ] + # Scale decode support without relying on std features decode = ["scale-info/decode"] diff --git a/frame-metadata/src/lib.rs b/frame-metadata/src/lib.rs index a49d1c2..8216f4a 100644 --- a/frame-metadata/src/lib.rs +++ b/frame-metadata/src/lib.rs @@ -19,15 +19,7 @@ #![warn(missing_docs)] #[cfg(all( any(feature = "decode", feature = "serde_full"), - any( - feature = "v13", - feature = "v12", - feature = "v11", - feature = "v10", - feature = "v9", - feature = "v8", - feature = "legacy" - ), + feature = "legacy", not(feature = "std") ))] compile_error!("decode and serde_full features prior to v14 require std"); @@ -48,53 +40,45 @@ cfg_if::cfg_if! { use codec::{Encode, Output}; /// A type that decodes to a different type than it encodes. -#[cfg(any( - feature = "v13", - feature = "v12", - feature = "v11", - feature = "v10", - feature = "v9", - feature = "v8", - feature = "legacy" -))] +#[cfg(feature = "legacy")] pub mod decode_different; /// Metadata v8 -#[cfg(feature = "v8")] +#[cfg(feature = "legacy")] pub mod v8; /// Metadata v9 -#[cfg(feature = "v9")] +#[cfg(feature = "legacy")] pub mod v9; /// Metadata v10 -#[cfg(feature = "v10")] +#[cfg(feature = "legacy")] pub mod v10; /// Metadata v11 -#[cfg(feature = "v11")] +#[cfg(feature = "legacy")] pub mod v11; /// Metadata v12 -#[cfg(feature = "v12")] +#[cfg(feature = "legacy")] pub mod v12; /// Metadata v13 -#[cfg(feature = "v13")] +#[cfg(feature = "legacy")] pub mod v13; /// Metadata v14 -#[cfg(feature = "v14")] +#[cfg(feature = "current")] pub mod v14; /// Metadata v15 -#[cfg(feature = "v15-unstable")] +#[cfg(feature = "unstable")] pub mod v15; // Reexport all the types from the latest version. // // When a new version becomes available, update this. -#[cfg(feature = "v14")] +#[cfg(feature = "current")] pub use self::v14::*; /// Metadata prefix. @@ -136,52 +120,52 @@ pub enum RuntimeMetadata { /// Version 7 for runtime metadata. No longer used. V7(RuntimeMetadataDeprecated), /// Version 8 for runtime metadata. - #[cfg(any(feature = "v8", feature = "legacy"))] + #[cfg(feature = "legacy")] V8(v8::RuntimeMetadataV8), /// Version 8 for runtime metadata, as raw encoded bytes. - #[cfg(not(feature = "v8"))] + #[cfg(not(feature = "legacy"))] V8(OpaqueMetadata), /// Version 9 for runtime metadata. - #[cfg(any(feature = "v9", feature = "legacy"))] + #[cfg(feature = "legacy")] V9(v9::RuntimeMetadataV9), /// Version 9 for runtime metadata, as raw encoded bytes. - #[cfg(not(feature = "v9"))] + #[cfg(not(feature = "legacy"))] V9(OpaqueMetadata), /// Version 10 for runtime metadata. - #[cfg(any(feature = "v10", feature = "legacy"))] + #[cfg(feature = "legacy")] V10(v10::RuntimeMetadataV10), /// Version 10 for runtime metadata, as raw encoded bytes. - #[cfg(not(feature = "v10"))] + #[cfg(not(feature = "legacy"))] V10(OpaqueMetadata), /// Version 11 for runtime metadata. - #[cfg(any(feature = "v11", feature = "legacy"))] + #[cfg(feature = "legacy")] V11(v11::RuntimeMetadataV11), /// Version 11 for runtime metadata, as raw encoded bytes. - #[cfg(not(feature = "v11"))] + #[cfg(not(feature = "legacy"))] V11(OpaqueMetadata), /// Version 12 for runtime metadata - #[cfg(any(feature = "v12", feature = "legacy"))] + #[cfg(feature = "legacy")] V12(v12::RuntimeMetadataV12), /// Version 12 for runtime metadata, as raw encoded bytes. - #[cfg(not(feature = "v12"))] + #[cfg(not(feature = "legacy"))] V12(OpaqueMetadata), /// Version 13 for runtime metadata. - #[cfg(any(feature = "v13", feature = "legacy"))] + #[cfg(feature = "legacy")] V13(v13::RuntimeMetadataV13), /// Version 13 for runtime metadata, as raw encoded bytes. - #[cfg(not(feature = "v13"))] + #[cfg(not(feature = "legacy"))] V13(OpaqueMetadata), /// Version 14 for runtime metadata. - #[cfg(feature = "v14")] + #[cfg(feature = "current")] V14(v14::RuntimeMetadataV14), /// Version 14 for runtime metadata, as raw encoded bytes. - #[cfg(not(feature = "v14"))] + #[cfg(not(feature = "current"))] V14(OpaqueMetadata), /// Version 15 for runtime metadata. - #[cfg(feature = "v15-unstable")] + #[cfg(feature = "unstable")] V15(v15::RuntimeMetadataV15), /// Version 15 for runtime metadata, as raw encoded bytes. - #[cfg(not(feature = "v15-unstable"))] + #[cfg(not(feature = "unstable"))] V15(OpaqueMetadata), } diff --git a/frame-metadata/src/v15.rs b/frame-metadata/src/v15.rs index e113545..4b1536c 100644 --- a/frame-metadata/src/v15.rs +++ b/frame-metadata/src/v15.rs @@ -26,6 +26,12 @@ use scale_info::{ IntoPortable, MetaType, PortableRegistry, Registry, }; +pub use super::v14::{ + PalletCallMetadata, PalletConstantMetadata, PalletErrorMetadata, PalletEventMetadata, + PalletStorageMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType, + StorageHasher, +}; + /// Latest runtime metadata pub type RuntimeMetadataLastVersion = RuntimeMetadataV15; @@ -285,256 +291,6 @@ impl IntoPortable for PalletMetadata { } } -/// All metadata of the pallet's storage. -#[derive(Clone, PartialEq, Eq, Encode, Debug)] -#[cfg_attr(feature = "decode", derive(Decode))] -#[cfg_attr(feature = "serde_full", derive(Serialize))] -#[cfg_attr( - feature = "serde_full", - serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) -)] -pub struct PalletStorageMetadata { - /// The common prefix used by all storage entries. - pub prefix: T::String, - /// Metadata for all storage entries. - pub entries: Vec>, -} - -impl IntoPortable for PalletStorageMetadata { - type Output = PalletStorageMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - PalletStorageMetadata { - prefix: self.prefix.into_portable(registry), - entries: registry.map_into_portable(self.entries), - } - } -} - -/// Metadata about one storage entry. -#[derive(Clone, PartialEq, Eq, Encode, Debug)] -#[cfg_attr(feature = "decode", derive(Decode))] -#[cfg_attr(feature = "serde_full", derive(Serialize))] -#[cfg_attr( - feature = "serde_full", - serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) -)] -pub struct StorageEntryMetadata { - /// Variable name of the storage entry. - pub name: T::String, - /// An `Option` modifier of that storage entry. - pub modifier: StorageEntryModifier, - /// Type of the value stored in the entry. - pub ty: StorageEntryType, - /// Default value (SCALE encoded). - pub default: Vec, - /// Storage entry documentation. - pub docs: Vec, -} - -impl IntoPortable for StorageEntryMetadata { - type Output = StorageEntryMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - StorageEntryMetadata { - name: self.name.into_portable(registry), - modifier: self.modifier, - ty: self.ty.into_portable(registry), - default: self.default, - docs: registry.map_into_portable(self.docs), - } - } -} - -/// A storage entry modifier indicates how a storage entry is returned when fetched and what the value will be if the key is not present. -/// Specifically this refers to the "return type" when fetching a storage entry, and what the value will be if the key is not present. -/// -/// `Optional` means you should expect an `Option`, with `None` returned if the key is not present. -/// `Default` means you should expect a `T` with the default value of default if the key is not present. -#[derive(Clone, PartialEq, Eq, Encode, Debug)] -#[cfg_attr(feature = "decode", derive(Decode))] -#[cfg_attr(feature = "serde_full", derive(Serialize))] -pub enum StorageEntryModifier { - /// The storage entry returns an `Option`, with `None` if the key is not present. - Optional, - /// The storage entry returns `T::Default` if the key is not present. - Default, -} - -/// Hasher used by storage maps -#[derive(Clone, PartialEq, Eq, Encode, Debug)] -#[cfg_attr(feature = "decode", derive(Decode))] -#[cfg_attr(feature = "serde_full", derive(Serialize))] -pub enum StorageHasher { - /// 128-bit Blake2 hash. - Blake2_128, - /// 256-bit Blake2 hash. - Blake2_256, - /// Multiple 128-bit Blake2 hashes concatenated. - Blake2_128Concat, - /// 128-bit XX hash. - Twox128, - /// 256-bit XX hash. - Twox256, - /// Multiple 64-bit XX hashes concatenated. - Twox64Concat, - /// Identity hashing (no hashing). - Identity, -} - -/// A type of storage value. -#[derive(Clone, PartialEq, Eq, Encode, Debug)] -#[cfg_attr(feature = "decode", derive(Decode))] -#[cfg_attr(feature = "serde_full", derive(Serialize))] -#[cfg_attr( - feature = "serde_full", - serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) -)] -pub enum StorageEntryType { - /// Plain storage entry (just the value). - Plain(T::Type), - /// A storage map. - Map { - /// One or more hashers, should be one hasher per key element. - hashers: Vec, - /// The type of the key, can be a tuple with elements for each of the hashers. - key: T::Type, - /// The type of the value. - value: T::Type, - }, -} - -impl IntoPortable for StorageEntryType { - type Output = StorageEntryType; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - match self { - Self::Plain(plain) => StorageEntryType::Plain(registry.register_type(&plain)), - Self::Map { - hashers, - key, - value, - } => StorageEntryType::Map { - hashers, - key: registry.register_type(&key), - value: registry.register_type(&value), - }, - } - } -} - -/// Metadata for all calls in a pallet -#[derive(Clone, PartialEq, Eq, Encode, Debug)] -#[cfg_attr(feature = "decode", derive(Decode))] -#[cfg_attr(feature = "serde_full", derive(Serialize))] -#[cfg_attr( - feature = "serde_full", - serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) -)] -pub struct PalletCallMetadata { - /// The corresponding enum type for the pallet call. - pub ty: T::Type, -} - -impl IntoPortable for PalletCallMetadata { - type Output = PalletCallMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - PalletCallMetadata { - ty: registry.register_type(&self.ty), - } - } -} - -impl From for PalletCallMetadata { - fn from(ty: MetaType) -> Self { - Self { ty } - } -} - -/// Metadata about the pallet Event type. -#[derive(Clone, PartialEq, Eq, Encode, Debug)] -#[cfg_attr(feature = "decode", derive(Decode))] -#[cfg_attr(feature = "serde_full", derive(Serialize))] -pub struct PalletEventMetadata { - /// The Event type. - pub ty: T::Type, -} - -impl IntoPortable for PalletEventMetadata { - type Output = PalletEventMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - PalletEventMetadata { - ty: registry.register_type(&self.ty), - } - } -} - -impl From for PalletEventMetadata { - fn from(ty: MetaType) -> Self { - Self { ty } - } -} - -/// Metadata about one pallet constant. -#[derive(Clone, PartialEq, Eq, Encode, Debug)] -#[cfg_attr(feature = "decode", derive(Decode))] -#[cfg_attr(feature = "serde_full", derive(Serialize))] -#[cfg_attr( - feature = "serde_full", - serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) -)] -pub struct PalletConstantMetadata { - /// Name of the pallet constant. - pub name: T::String, - /// Type of the pallet constant. - pub ty: T::Type, - /// Value stored in the constant (SCALE encoded). - pub value: Vec, - /// Documentation of the constant. - pub docs: Vec, -} - -impl IntoPortable for PalletConstantMetadata { - type Output = PalletConstantMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - PalletConstantMetadata { - name: self.name.into_portable(registry), - ty: registry.register_type(&self.ty), - value: self.value, - docs: registry.map_into_portable(self.docs), - } - } -} - -/// Metadata about a pallet error. -#[derive(Clone, PartialEq, Eq, Encode, Debug)] -#[cfg_attr(feature = "decode", derive(Decode))] -#[cfg_attr(feature = "serde_full", derive(Serialize))] -#[cfg_attr(feature = "serde_full", serde(bound(serialize = "T::Type: Serialize")))] -pub struct PalletErrorMetadata { - /// The error type information. - pub ty: T::Type, -} - -impl IntoPortable for PalletErrorMetadata { - type Output = PalletErrorMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - PalletErrorMetadata { - ty: registry.register_type(&self.ty), - } - } -} - -impl From for PalletErrorMetadata { - fn from(ty: MetaType) -> Self { - Self { ty } - } -} - /// Metadata for custom types. /// /// This map associates a string key to a `CustomValueMetadata`. @@ -618,7 +374,7 @@ pub struct OuterEnums { /// chain. It provides just the information needed to decode `sp_runtime::DispatchError::Module`. /// - Decoding the 5 error bytes into this type will not always lead to all of the bytes being consumed; /// many error types do not require all of the bytes to represent them fully. - pub module_error_enum_ty: T::Type, + pub error_enum_ty: T::Type, } impl IntoPortable for OuterEnums { @@ -628,7 +384,7 @@ impl IntoPortable for OuterEnums { OuterEnums { call_enum_ty: registry.register_type(&self.call_enum_ty), event_enum_ty: registry.register_type(&self.event_enum_ty), - module_error_enum_ty: registry.register_type(&self.module_error_enum_ty), + error_enum_ty: registry.register_type(&self.error_enum_ty), } } }