From 745378048e3ee8b289e16a2ff2a53d24de98ad5b Mon Sep 17 00:00:00 2001 From: James Wilson Date: Tue, 29 Apr 2025 10:40:14 +0100 Subject: [PATCH] Tidy Deprecation Information and prep 22.0.0 release (#101) * Alter Deprecation bits to avoid weird states * fmt * No need to deprecate the entire enum, only variants * Make it easy to signal nothing deprecated on EnumDeprecationInfo * Bump to 22.0.0 * Update changelog --- CHANGELOG.md | 6 ++ frame-metadata/Cargo.toml | 2 +- frame-metadata/src/v16.rs | 151 ++++++++++++++++++++++++-------------- 3 files changed, 103 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd9de50..00ea0d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [22.0.0] - 2025-04-24 + +### Changed + +- Alter the deprecation information metadata to remove duplicate/confusing states [#101](https://github.com/paritytech/frame-metadata/pull/101) + ## [21.0.0] - 2025-04-01 ### Changed diff --git a/frame-metadata/Cargo.toml b/frame-metadata/Cargo.toml index 1fc5004..c992993 100644 --- a/frame-metadata/Cargo.toml +++ b/frame-metadata/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "frame-metadata" -version = "21.0.0" +version = "22.0.0" authors = ["Parity Technologies "] edition = "2021" license = "Apache-2.0" diff --git a/frame-metadata/src/v16.rs b/frame-metadata/src/v16.rs index 438a53c..9fccf80 100644 --- a/frame-metadata/src/v16.rs +++ b/frame-metadata/src/v16.rs @@ -105,7 +105,7 @@ pub struct RuntimeApiMetadata { /// Trait documentation. pub docs: Vec, /// Deprecation info. - pub deprecation_info: DeprecationStatus, + pub deprecation_info: ItemDeprecationInfo, /// Runtime API version. pub version: Compact, } @@ -142,7 +142,7 @@ pub struct RuntimeApiMethodMetadata { /// Method documentation. pub docs: Vec, /// Deprecation info - pub deprecation_info: DeprecationStatus, + pub deprecation_info: ItemDeprecationInfo, } impl IntoPortable for RuntimeApiMethodMetadata { @@ -256,7 +256,7 @@ pub struct PalletMetadata { /// Pallet documentation. pub docs: Vec, /// Deprecation info - pub deprecation_info: DeprecationStatus, + pub deprecation_info: ItemDeprecationInfo, } impl IntoPortable for PalletMetadata { @@ -291,7 +291,7 @@ pub struct PalletCallMetadata { /// The corresponding enum type for the pallet call. pub ty: T::Type, /// Deprecation status of the pallet call - pub deprecation_info: DeprecationInfo, + pub deprecation_info: EnumDeprecationInfo, } impl IntoPortable for PalletCallMetadata { @@ -351,7 +351,7 @@ pub struct StorageEntryMetadata { /// Storage entry documentation. pub docs: Vec, /// Deprecation info - pub deprecation_info: DeprecationStatus, + pub deprecation_info: ItemDeprecationInfo, } impl IntoPortable for StorageEntryMetadata { @@ -381,7 +381,7 @@ pub struct PalletEventMetadata { /// The Event type. pub ty: T::Type, /// Deprecation info - pub deprecation_info: DeprecationInfo, + pub deprecation_info: EnumDeprecationInfo, } impl IntoPortable for PalletEventMetadata { @@ -413,7 +413,7 @@ pub struct PalletConstantMetadata { /// Documentation of the constant. pub docs: Vec, /// Deprecation info - pub deprecation_info: DeprecationStatus, + pub deprecation_info: ItemDeprecationInfo, } impl IntoPortable for PalletConstantMetadata { @@ -442,7 +442,7 @@ pub struct PalletErrorMetadata { /// The error type information. pub ty: T::Type, /// Deprecation info - pub deprecation_info: DeprecationInfo, + pub deprecation_info: EnumDeprecationInfo, } impl IntoPortable for PalletErrorMetadata { @@ -505,7 +505,7 @@ pub struct PalletViewFunctionMetadata { /// Method documentation. pub docs: Vec, /// Deprecation info - pub deprecation_info: DeprecationStatus, + pub deprecation_info: ItemDeprecationInfo, } impl IntoPortable for PalletViewFunctionMetadata { @@ -523,7 +523,7 @@ impl IntoPortable for PalletViewFunctionMetadata { } } -/// Deprecation status for an entry inside the metadata. +/// Deprecation information for generic items. #[derive(Clone, PartialEq, Eq, Encode, Debug)] #[cfg_attr(feature = "decode", derive(Decode))] #[cfg_attr(feature = "serde_full", derive(Serialize))] @@ -531,66 +531,107 @@ impl IntoPortable for PalletViewFunctionMetadata { feature = "serde_full", serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) )] -pub enum DeprecationStatus { - /// Entry is not deprecated +pub enum ItemDeprecationInfo { + /// Item is not deprecated. NotDeprecated, - /// Deprecated without a note. + /// Item is fully deprecated without a note. DeprecatedWithoutNote, - /// Entry is deprecated with an note and an optional `since` field. + /// Item is fully deprecated with a note and an optional `since` field. Deprecated { /// Note explaining the deprecation note: T::String, - /// Optional value for denoting version when the deprecation occurred. + /// Optional value for noting the version when the deprecation occurred. since: Option, }, } -impl IntoPortable for DeprecationStatus { - type Output = DeprecationStatus; + +impl IntoPortable for ItemDeprecationInfo { + type Output = ItemDeprecationInfo; + + fn into_portable(self, registry: &mut Registry) -> Self::Output { + match self { + Self::NotDeprecated => ItemDeprecationInfo::NotDeprecated, + Self::DeprecatedWithoutNote => ItemDeprecationInfo::DeprecatedWithoutNote, + Self::Deprecated { note, since } => { + let note = note.into_portable(registry); + let since = since.map(|x| x.into_portable(registry)); + ItemDeprecationInfo::Deprecated { note, since } + } + } + } +} + +/// Deprecation information for enums in which specific variants can be deprecated. +/// If the map is empty, then nothing is deprecated. +#[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 EnumDeprecationInfo(pub BTreeMap>); + +impl EnumDeprecationInfo { + /// Construct an instance in which nothing is marked for deprecation. + pub fn nothing_deprecated() -> Self { + Self(BTreeMap::new()) + } + + /// Are any variants deprecated? + pub fn has_deprecated_variants(&self) -> bool { + !self.0.is_empty() + } + + /// Is a specific variant deprecated? + pub fn is_variant_deprecated(&self, variant_index: u8) -> bool { + self.0.contains_key(&variant_index) + } +} + +impl IntoPortable for EnumDeprecationInfo { + type Output = EnumDeprecationInfo; + + fn into_portable(self, registry: &mut Registry) -> Self::Output { + let entries = self + .0 + .into_iter() + .map(|(k, entry)| (k, entry.into_portable(registry))); + EnumDeprecationInfo(entries.collect()) + } +} + +/// Deprecation information for an item or variant in the metadata. +#[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 VariantDeprecationInfo { + /// Variant is deprecated without a note. + DeprecatedWithoutNote, + /// Variant is deprecated with a note and an optional `since` field. + Deprecated { + /// Note explaining the deprecation + note: T::String, + /// Optional value for noting the version when the deprecation occurred. + since: Option, + }, +} + +impl IntoPortable for VariantDeprecationInfo { + type Output = VariantDeprecationInfo; fn into_portable(self, registry: &mut Registry) -> Self::Output { match self { Self::Deprecated { note, since } => { let note = note.into_portable(registry); let since = since.map(|x| x.into_portable(registry)); - DeprecationStatus::Deprecated { note, since } + VariantDeprecationInfo::Deprecated { note, since } } - Self::DeprecatedWithoutNote => DeprecationStatus::DeprecatedWithoutNote, - Self::NotDeprecated => DeprecationStatus::NotDeprecated, - } - } -} -/// Deprecation info for an enums/errors/calls. -/// Denotes full/partial deprecation of the type -#[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 DeprecationInfo { - /// Type is not deprecated - NotDeprecated, - /// Entry is fully deprecated. - ItemDeprecated(DeprecationStatus), - /// Entry is partially deprecated. - VariantsDeprecated(BTreeMap>), -} -impl IntoPortable for DeprecationInfo { - type Output = DeprecationInfo; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - match self { - Self::VariantsDeprecated(entries) => { - let entries = entries - .into_iter() - .map(|(k, entry)| (k, entry.into_portable(registry))); - DeprecationInfo::VariantsDeprecated(entries.collect()) - } - Self::ItemDeprecated(deprecation) => { - DeprecationInfo::ItemDeprecated(deprecation.into_portable(registry)) - } - Self::NotDeprecated => DeprecationInfo::NotDeprecated, + Self::DeprecatedWithoutNote => VariantDeprecationInfo::DeprecatedWithoutNote, } } }