From c50498a70b7e610678e20f0b68a1e08e52218a8a Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 27 Apr 2021 17:28:40 +0100 Subject: [PATCH] Encapsulate call and event metadata types, remove OuterEventMetadata --- frame-metadata/src/v13.rs | 103 ++++++++++++++------------------------ 1 file changed, 37 insertions(+), 66 deletions(-) diff --git a/frame-metadata/src/v13.rs b/frame-metadata/src/v13.rs index 6e1d928..d79fb0b 100644 --- a/frame-metadata/src/v13.rs +++ b/frame-metadata/src/v13.rs @@ -132,10 +132,10 @@ impl IntoPortable for SignedExtensionMetadata { pub struct ModuleMetadata { pub name: T::String, pub storage: Option>, - pub calls: Option>>, - pub event: Option>>, + pub calls: Option>, + pub event: Option>, pub constants: Option>>, - pub errors: Vec>, + pub errors: ErrorMetadata, /// Define the index of the module, this index will be used for the encoding of module event, /// call and origin variants. pub index: u8, @@ -148,12 +148,12 @@ impl IntoPortable for ModuleMetadata { ModuleMetadata { name: self.name.into_portable(registry), storage: self.storage.map(|storage| storage.into_portable(registry)), - calls: self.calls.map(|calls| registry.map_into_portable(calls)), - event: self.event.map(|event| registry.map_into_portable(event)), + calls: self.calls.map(|calls| calls.into_portable(registry)), + event: self.event.map(|event| event.into_portable(registry)), constants: self .constants .map(|constant| registry.map_into_portable(constant)), - errors: registry.map_into_portable(self.errors), + errors: self.errors.into_portable(registry), index: self.index, } } @@ -292,6 +292,30 @@ impl IntoPortable for StorageEntryType { } } +/// Metadata for all +#[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 ModuleCallsMetadata { + /// The corresponding enum type for the module call. + pub ty: T::Type, + pub calls: Vec>, +} + +impl IntoPortable for ModuleCallsMetadata { + type Output = ModuleCallsMetadata; + + fn into_portable(self, registry: &mut Registry) -> Self::Output { + ModuleCallsMetadata { + ty: registry.register_type(&self.ty), + calls: registry.map_into_portable(self.calls), + } + } +} + /// All the metadata about a function. #[derive(Clone, PartialEq, Eq, Encode)] #[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))] @@ -327,7 +351,6 @@ impl IntoPortable for FunctionMetadata { pub struct FunctionArgumentMetadata { pub name: T::String, pub ty: T::Type, - pub is_compact: bool, } impl IntoPortable for FunctionArgumentMetadata { @@ -337,30 +360,6 @@ impl IntoPortable for FunctionArgumentMetadata { FunctionArgumentMetadata { name: self.name.into_portable(registry), ty: registry.register_type(&self.ty), - is_compact: self.is_compact, - } - } -} - -/// All the metadata about an outer event. -#[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 OuterEventMetadata { - pub name: T::String, - pub events: Vec>, -} - -impl IntoPortable for OuterEventMetadata { - type Output = OuterEventMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - OuterEventMetadata { - name: self.name.into_portable(registry), - events: registry.map_into_portable(self.events), } } } @@ -373,8 +372,7 @@ impl IntoPortable for OuterEventMetadata { serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) )] pub struct ModuleEventMetadata { - pub name: T::String, - pub events: Vec>, + pub ty: T::Type, } impl IntoPortable for ModuleEventMetadata { @@ -382,33 +380,7 @@ impl IntoPortable for ModuleEventMetadata { fn into_portable(self, registry: &mut Registry) -> Self::Output { ModuleEventMetadata { - name: self.name.into_portable(registry), - events: registry.map_into_portable(self.events), - } - } -} - -/// All the metadata about an event. -#[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 EventMetadata { - pub name: T::String, - pub arguments: Vec>, - pub documentation: Vec, -} - -impl IntoPortable for EventMetadata { - type Output = EventMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - EventMetadata { - name: self.name.into_portable(registry), - arguments: registry.map_into_portable(self.arguments), - documentation: registry.map_into_portable(self.documentation), + ty: registry.register_type(&self.ty), } } } @@ -440,16 +412,16 @@ impl IntoPortable for ModuleConstantMetadata { } } -/// All the metadata about a module error. +/// Metadata about a module error. #[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")) + serde(bound(serialize = "T::Type: Serialize")) )] pub struct ErrorMetadata { - pub name: T::String, - pub documentation: Vec, + /// The error type information. + pub ty: T::Type } impl IntoPortable for ErrorMetadata { @@ -457,8 +429,7 @@ impl IntoPortable for ErrorMetadata { fn into_portable(self, registry: &mut Registry) -> Self::Output { ErrorMetadata { - name: self.name.into_portable(registry), - documentation: registry.map_into_portable(self.documentation), + ty: registry.register_type(&self.ty) } } }