diff --git a/frame-metadata/Cargo.toml b/frame-metadata/Cargo.toml index e3ee518..80b2f99 100644 --- a/frame-metadata/Cargo.toml +++ b/frame-metadata/Cargo.toml @@ -33,6 +33,7 @@ unstable = ["current"] # Serde support without relying on std features serde_full = [ "scale-info/serde", + "codec/serde", "serde", "serde/alloc", ] diff --git a/frame-metadata/src/v16.rs b/frame-metadata/src/v16.rs index a63d430..438a53c 100644 --- a/frame-metadata/src/v16.rs +++ b/frame-metadata/src/v16.rs @@ -19,16 +19,22 @@ use codec::Decode; use serde::Serialize; use super::{RuntimeMetadataPrefixed, META_RESERVED}; -use codec::Encode; +use codec::{Compact, Encode}; use scale_info::{ form::{Form, MetaForm, PortableForm}, prelude::{collections::BTreeMap, vec::Vec}, IntoPortable, PortableRegistry, Registry, }; +// These types have not changed, so we re-export from our v14/v15 definitions: pub use super::v14::{StorageEntryModifier, StorageEntryType, StorageHasher}; +pub use super::v15::{CustomMetadata, CustomValueMetadata, OuterEnums}; -/// Latest runtime metadata +/// The metadata for a method or function parameter. This is identical to +/// [`crate::v15::RuntimeApiMethodParamMetadata`]. +pub type FunctionParamMetadata = super::v15::RuntimeApiMethodParamMetadata; + +/// Latest runtime metadata. pub type RuntimeMetadataLastVersion = RuntimeMetadataV16; impl From for super::RuntimeMetadataPrefixed { @@ -101,7 +107,7 @@ pub struct RuntimeApiMetadata { /// Deprecation info. pub deprecation_info: DeprecationStatus, /// Runtime API version. - pub version: u32, + pub version: Compact, } impl IntoPortable for RuntimeApiMetadata { @@ -130,7 +136,7 @@ pub struct RuntimeApiMethodMetadata { /// Method name. pub name: T::String, /// Method parameters. - pub inputs: Vec>, + pub inputs: Vec>, /// Method output. pub output: T::Type, /// Method documentation. @@ -153,32 +159,6 @@ impl IntoPortable for RuntimeApiMethodMetadata { } } -/// Metadata of a runtime method parameter. -#[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 RuntimeApiMethodParamMetadata { - /// Parameter name. - pub name: T::String, - /// Parameter type. - pub ty: T::Type, -} - -impl IntoPortable for RuntimeApiMethodParamMetadata { - type Output = RuntimeApiMethodParamMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - RuntimeApiMethodParamMetadata { - name: self.name.into_portable(registry), - ty: registry.register_type(&self.ty), - } - } -} - /// Metadata of the extrinsic used by the runtime. #[derive(Clone, PartialEq, Eq, Encode, Debug)] #[cfg_attr(feature = "decode", derive(Decode))] @@ -197,7 +177,7 @@ pub struct ExtrinsicMetadata { /// A mapping of supported transaction extrinsic versions to their respective transaction extension indexes. /// /// For each supported version number, list the indexes, in order, of the extensions used. - pub transaction_extensions_by_version: BTreeMap>, + pub transaction_extensions_by_version: BTreeMap>>, /// The transaction extensions in the order they appear in the extrinsic. pub transaction_extensions: Vec>, } @@ -299,7 +279,7 @@ impl IntoPortable for PalletMetadata { } } -/// Metadata for all calls in a pallet +/// 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))] @@ -519,7 +499,7 @@ pub struct PalletViewFunctionMetadata { /// Method id. pub id: [u8; 32], /// Method parameters. - pub inputs: Vec>, + pub inputs: Vec>, /// Method output. pub output: T::Type, /// Method documentation. @@ -543,130 +523,6 @@ impl IntoPortable for PalletViewFunctionMetadata { } } -/// Metadata of a runtime view function parameter. -#[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 PalletViewFunctionParamMetadata { - /// Parameter name. - pub name: T::String, - /// Parameter type. - pub ty: T::Type, -} - -impl IntoPortable for PalletViewFunctionParamMetadata { - type Output = PalletViewFunctionParamMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - PalletViewFunctionParamMetadata { - name: self.name.into_portable(registry), - ty: registry.register_type(&self.ty), - } - } -} - -/// Metadata for custom types. -/// -/// This map associates a string key to a `CustomValueMetadata`. -#[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 CustomMetadata { - /// The custom map. - pub map: BTreeMap>, -} - -impl IntoPortable for CustomMetadata { - type Output = CustomMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - let map = self - .map - .into_iter() - .map(|(key, value)| (key.into_portable(registry), value.into_portable(registry))) - .collect(); - - CustomMetadata { map } - } -} - -/// The associated value of a custom metadata 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 struct CustomValueMetadata { - /// The custom type. - pub ty: T::Type, - /// The custom value of this type. - pub value: Vec, -} - -impl IntoPortable for CustomValueMetadata { - type Output = CustomValueMetadata; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - CustomValueMetadata { - ty: registry.register_type(&self.ty), - value: self.value, - } - } -} - -/// The type of the outer enums. -#[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 OuterEnums { - /// The type of the outer `RuntimeCall` enum. - pub call_enum_ty: T::Type, - /// The type of the outer `RuntimeEvent` enum. - pub event_enum_ty: T::Type, - /// The module error type of the - /// [`DispatchError::Module`](https://docs.rs/sp-runtime/24.0.0/sp_runtime/enum.DispatchError.html#variant.Module) variant. - /// - /// The `Module` variant will be 5 scale encoded bytes which are normally decoded into - /// an `{ index: u8, error: [u8; 4] }` struct. This type ID points to an enum type which instead - /// interprets the first `index` byte as a pallet variant, and the remaining `error` bytes as the - /// appropriate `pallet::Error` type. It is an equally valid way to decode the error bytes, and - /// can be more informative. - /// - /// # Note - /// - /// - This type cannot be used directly to decode `sp_runtime::DispatchError` from the - /// 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 error_enum_ty: T::Type, -} - -impl IntoPortable for OuterEnums { - type Output = OuterEnums; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - OuterEnums { - call_enum_ty: registry.register_type(&self.call_enum_ty), - event_enum_ty: registry.register_type(&self.event_enum_ty), - error_enum_ty: registry.register_type(&self.error_enum_ty), - } - } -} - /// Deprecation status for an entry inside the metadata. #[derive(Clone, PartialEq, Eq, Encode, Debug)] #[cfg_attr(feature = "decode", derive(Decode))]