From 7bb2935f9c2a51193708d5cd4b190deee726c663 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 14 Jul 2021 17:13:21 +0100 Subject: [PATCH] Remove Call metadata redundancy (#20) * Remove Call metadata redundancy * Add convenient From impls for Call, Event and Error types * Add convenient From impls for Call, Event and Error types --- frame-metadata/src/v14.rs | 60 +++++++++++---------------------------- 1 file changed, 16 insertions(+), 44 deletions(-) diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index 05592e4..f394f09 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -27,7 +27,7 @@ use codec::Encode; use scale_info::prelude::vec::Vec; use scale_info::{ form::{Form, MetaForm, PortableForm}, - IntoPortable, PortableRegistry, Registry, + IntoPortable, MetaType, PortableRegistry, Registry, }; /// Current prefix of metadata @@ -305,7 +305,6 @@ impl IntoPortable for StorageEntryType { pub struct PalletCallMetadata { /// The corresponding enum type for the pallet call. pub ty: T::Type, - pub calls: Vec>, } impl IntoPortable for PalletCallMetadata { @@ -314,52 +313,13 @@ impl IntoPortable for PalletCallMetadata { fn into_portable(self, registry: &mut Registry) -> Self::Output { PalletCallMetadata { ty: registry.register_type(&self.ty), - calls: registry.map_into_portable(self.calls), } } } -/// Metadata about a function. -#[derive(Clone, PartialEq, Eq, Encode)] -#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))] -#[cfg_attr( - feature = "std", - serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) -)] -pub struct FunctionMetadata { - pub name: T::String, - pub args: Vec>, - pub docs: Vec, -} - -impl IntoPortable for FunctionMetadata { - type Output = FunctionMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - FunctionMetadata { - name: self.name.into_portable(registry), - args: registry.map_into_portable(self.args), - docs: registry.map_into_portable(self.docs), - } - } -} - -/// Metadata about a function argument. -#[derive(Clone, PartialEq, Eq, Encode)] -#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))] -pub struct FunctionArgumentMetadata { - pub name: T::String, - pub ty: T::Type, -} - -impl IntoPortable for FunctionArgumentMetadata { - type Output = FunctionArgumentMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - FunctionArgumentMetadata { - name: self.name.into_portable(registry), - ty: registry.register_type(&self.ty), - } +impl From for PalletCallMetadata { + fn from(ty: MetaType) -> Self { + Self { ty } } } @@ -380,6 +340,12 @@ impl IntoPortable for PalletEventMetadata { } } +impl From for PalletEventMetadata { + fn from(ty: MetaType) -> Self { + Self { ty } + } +} + /// Metadata about one pallet constant. #[derive(Clone, PartialEq, Eq, Encode)] #[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))] @@ -425,3 +391,9 @@ impl IntoPortable for PalletErrorMetadata { } } } + +impl From for PalletErrorMetadata { + fn from(ty: MetaType) -> Self { + Self { ty } + } +}