Skip to content

Commit 7453780

Browse files
authored
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
1 parent a060c2d commit 7453780

3 files changed

Lines changed: 88 additions & 41 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
## [22.0.0] - 2025-04-24
12+
13+
### Changed
14+
15+
- Alter the deprecation information metadata to remove duplicate/confusing states [#101](https://github.com/paritytech/frame-metadata/pull/101)
16+
1117
## [21.0.0] - 2025-04-01
1218

1319
### Changed

frame-metadata/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "frame-metadata"
3-
version = "21.0.0"
3+
version = "22.0.0"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2021"
66
license = "Apache-2.0"

frame-metadata/src/v16.rs

Lines changed: 81 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub struct RuntimeApiMetadata<T: Form = MetaForm> {
105105
/// Trait documentation.
106106
pub docs: Vec<T::String>,
107107
/// Deprecation info.
108-
pub deprecation_info: DeprecationStatus<T>,
108+
pub deprecation_info: ItemDeprecationInfo<T>,
109109
/// Runtime API version.
110110
pub version: Compact<u32>,
111111
}
@@ -142,7 +142,7 @@ pub struct RuntimeApiMethodMetadata<T: Form = MetaForm> {
142142
/// Method documentation.
143143
pub docs: Vec<T::String>,
144144
/// Deprecation info
145-
pub deprecation_info: DeprecationStatus<T>,
145+
pub deprecation_info: ItemDeprecationInfo<T>,
146146
}
147147

148148
impl IntoPortable for RuntimeApiMethodMetadata {
@@ -256,7 +256,7 @@ pub struct PalletMetadata<T: Form = MetaForm> {
256256
/// Pallet documentation.
257257
pub docs: Vec<T::String>,
258258
/// Deprecation info
259-
pub deprecation_info: DeprecationStatus<T>,
259+
pub deprecation_info: ItemDeprecationInfo<T>,
260260
}
261261

262262
impl IntoPortable for PalletMetadata {
@@ -291,7 +291,7 @@ pub struct PalletCallMetadata<T: Form = MetaForm> {
291291
/// The corresponding enum type for the pallet call.
292292
pub ty: T::Type,
293293
/// Deprecation status of the pallet call
294-
pub deprecation_info: DeprecationInfo<T>,
294+
pub deprecation_info: EnumDeprecationInfo<T>,
295295
}
296296

297297
impl IntoPortable for PalletCallMetadata {
@@ -351,7 +351,7 @@ pub struct StorageEntryMetadata<T: Form = MetaForm> {
351351
/// Storage entry documentation.
352352
pub docs: Vec<T::String>,
353353
/// Deprecation info
354-
pub deprecation_info: DeprecationStatus<T>,
354+
pub deprecation_info: ItemDeprecationInfo<T>,
355355
}
356356

357357
impl IntoPortable for StorageEntryMetadata {
@@ -381,7 +381,7 @@ pub struct PalletEventMetadata<T: Form = MetaForm> {
381381
/// The Event type.
382382
pub ty: T::Type,
383383
/// Deprecation info
384-
pub deprecation_info: DeprecationInfo<T>,
384+
pub deprecation_info: EnumDeprecationInfo<T>,
385385
}
386386

387387
impl IntoPortable for PalletEventMetadata {
@@ -413,7 +413,7 @@ pub struct PalletConstantMetadata<T: Form = MetaForm> {
413413
/// Documentation of the constant.
414414
pub docs: Vec<T::String>,
415415
/// Deprecation info
416-
pub deprecation_info: DeprecationStatus<T>,
416+
pub deprecation_info: ItemDeprecationInfo<T>,
417417
}
418418

419419
impl IntoPortable for PalletConstantMetadata {
@@ -442,7 +442,7 @@ pub struct PalletErrorMetadata<T: Form = MetaForm> {
442442
/// The error type information.
443443
pub ty: T::Type,
444444
/// Deprecation info
445-
pub deprecation_info: DeprecationInfo<T>,
445+
pub deprecation_info: EnumDeprecationInfo<T>,
446446
}
447447

448448
impl IntoPortable for PalletErrorMetadata {
@@ -505,7 +505,7 @@ pub struct PalletViewFunctionMetadata<T: Form = MetaForm> {
505505
/// Method documentation.
506506
pub docs: Vec<T::String>,
507507
/// Deprecation info
508-
pub deprecation_info: DeprecationStatus<T>,
508+
pub deprecation_info: ItemDeprecationInfo<T>,
509509
}
510510

511511
impl IntoPortable for PalletViewFunctionMetadata {
@@ -523,74 +523,115 @@ impl IntoPortable for PalletViewFunctionMetadata {
523523
}
524524
}
525525

526-
/// Deprecation status for an entry inside the metadata.
526+
/// Deprecation information for generic items.
527527
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
528528
#[cfg_attr(feature = "decode", derive(Decode))]
529529
#[cfg_attr(feature = "serde_full", derive(Serialize))]
530530
#[cfg_attr(
531531
feature = "serde_full",
532532
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
533533
)]
534-
pub enum DeprecationStatus<T: Form = MetaForm> {
535-
/// Entry is not deprecated
534+
pub enum ItemDeprecationInfo<T: Form = MetaForm> {
535+
/// Item is not deprecated.
536536
NotDeprecated,
537-
/// Deprecated without a note.
537+
/// Item is fully deprecated without a note.
538538
DeprecatedWithoutNote,
539-
/// Entry is deprecated with an note and an optional `since` field.
539+
/// Item is fully deprecated with a note and an optional `since` field.
540540
Deprecated {
541541
/// Note explaining the deprecation
542542
note: T::String,
543-
/// Optional value for denoting version when the deprecation occurred.
543+
/// Optional value for noting the version when the deprecation occurred.
544544
since: Option<T::String>,
545545
},
546546
}
547-
impl IntoPortable for DeprecationStatus {
548-
type Output = DeprecationStatus<PortableForm>;
547+
548+
impl IntoPortable for ItemDeprecationInfo {
549+
type Output = ItemDeprecationInfo<PortableForm>;
549550

550551
fn into_portable(self, registry: &mut Registry) -> Self::Output {
551552
match self {
553+
Self::NotDeprecated => ItemDeprecationInfo::NotDeprecated,
554+
Self::DeprecatedWithoutNote => ItemDeprecationInfo::DeprecatedWithoutNote,
552555
Self::Deprecated { note, since } => {
553556
let note = note.into_portable(registry);
554557
let since = since.map(|x| x.into_portable(registry));
555-
DeprecationStatus::Deprecated { note, since }
558+
ItemDeprecationInfo::Deprecated { note, since }
556559
}
557-
Self::DeprecatedWithoutNote => DeprecationStatus::DeprecatedWithoutNote,
558-
Self::NotDeprecated => DeprecationStatus::NotDeprecated,
559560
}
560561
}
561562
}
562-
/// Deprecation info for an enums/errors/calls.
563-
/// Denotes full/partial deprecation of the type
563+
564+
/// Deprecation information for enums in which specific variants can be deprecated.
565+
/// If the map is empty, then nothing is deprecated.
564566
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
565567
#[cfg_attr(feature = "decode", derive(Decode))]
566568
#[cfg_attr(feature = "serde_full", derive(Serialize))]
567569
#[cfg_attr(
568570
feature = "serde_full",
569571
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
570572
)]
571-
pub enum DeprecationInfo<T: Form = MetaForm> {
572-
/// Type is not deprecated
573-
NotDeprecated,
574-
/// Entry is fully deprecated.
575-
ItemDeprecated(DeprecationStatus<T>),
576-
/// Entry is partially deprecated.
577-
VariantsDeprecated(BTreeMap<u8, DeprecationStatus<T>>),
573+
pub struct EnumDeprecationInfo<T: Form = MetaForm>(pub BTreeMap<u8, VariantDeprecationInfo<T>>);
574+
575+
impl<T: Form> EnumDeprecationInfo<T> {
576+
/// Construct an instance in which nothing is marked for deprecation.
577+
pub fn nothing_deprecated() -> Self {
578+
Self(BTreeMap::new())
579+
}
580+
581+
/// Are any variants deprecated?
582+
pub fn has_deprecated_variants(&self) -> bool {
583+
!self.0.is_empty()
584+
}
585+
586+
/// Is a specific variant deprecated?
587+
pub fn is_variant_deprecated(&self, variant_index: u8) -> bool {
588+
self.0.contains_key(&variant_index)
589+
}
590+
}
591+
592+
impl IntoPortable for EnumDeprecationInfo {
593+
type Output = EnumDeprecationInfo<PortableForm>;
594+
595+
fn into_portable(self, registry: &mut Registry) -> Self::Output {
596+
let entries = self
597+
.0
598+
.into_iter()
599+
.map(|(k, entry)| (k, entry.into_portable(registry)));
600+
EnumDeprecationInfo(entries.collect())
601+
}
602+
}
603+
604+
/// Deprecation information for an item or variant in the metadata.
605+
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
606+
#[cfg_attr(feature = "decode", derive(Decode))]
607+
#[cfg_attr(feature = "serde_full", derive(Serialize))]
608+
#[cfg_attr(
609+
feature = "serde_full",
610+
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
611+
)]
612+
pub enum VariantDeprecationInfo<T: Form = MetaForm> {
613+
/// Variant is deprecated without a note.
614+
DeprecatedWithoutNote,
615+
/// Variant is deprecated with a note and an optional `since` field.
616+
Deprecated {
617+
/// Note explaining the deprecation
618+
note: T::String,
619+
/// Optional value for noting the version when the deprecation occurred.
620+
since: Option<T::String>,
621+
},
578622
}
579-
impl IntoPortable for DeprecationInfo {
580-
type Output = DeprecationInfo<PortableForm>;
623+
624+
impl IntoPortable for VariantDeprecationInfo {
625+
type Output = VariantDeprecationInfo<PortableForm>;
581626

582627
fn into_portable(self, registry: &mut Registry) -> Self::Output {
583628
match self {
584-
Self::VariantsDeprecated(entries) => {
585-
let entries = entries
586-
.into_iter()
587-
.map(|(k, entry)| (k, entry.into_portable(registry)));
588-
DeprecationInfo::VariantsDeprecated(entries.collect())
589-
}
590-
Self::ItemDeprecated(deprecation) => {
591-
DeprecationInfo::ItemDeprecated(deprecation.into_portable(registry))
629+
Self::Deprecated { note, since } => {
630+
let note = note.into_portable(registry);
631+
let since = since.map(|x| x.into_portable(registry));
632+
VariantDeprecationInfo::Deprecated { note, since }
592633
}
593-
Self::NotDeprecated => DeprecationInfo::NotDeprecated,
634+
Self::DeprecatedWithoutNote => VariantDeprecationInfo::DeprecatedWithoutNote,
594635
}
595636
}
596637
}

0 commit comments

Comments
 (0)