#[cfg(feature = "decode")]
use codec::Decode;
#[cfg(feature = "serde_full")]
use serde::Serialize;
use super::{RuntimeMetadataPrefixed, META_RESERVED};
use codec::Encode;
use scale_info::{
form::{Form, MetaForm, PortableForm},
prelude::{collections::BTreeMap, vec::Vec},
IntoPortable, MetaType, PortableRegistry, Registry,
};
pub use super::v14::{
PalletCallMetadata, PalletConstantMetadata, PalletErrorMetadata, PalletEventMetadata,
PalletStorageMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType,
StorageHasher,
};
pub type RuntimeMetadataLastVersion = RuntimeMetadataV15;
impl From<RuntimeMetadataLastVersion> for super::RuntimeMetadataPrefixed {
fn from(metadata: RuntimeMetadataLastVersion) -> RuntimeMetadataPrefixed {
RuntimeMetadataPrefixed(META_RESERVED, super::RuntimeMetadata::V15(metadata))
}
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "decode", derive(Decode))]
#[cfg_attr(feature = "serde_full", derive(Serialize))]
pub struct RuntimeMetadataV15 {
pub types: PortableRegistry,
pub pallets: Vec<PalletMetadata<PortableForm>>,
pub extrinsic: ExtrinsicMetadata<PortableForm>,
pub ty: <PortableForm as Form>::Type,
pub apis: Vec<RuntimeApiMetadata<PortableForm>>,
pub outer_enums: OuterEnums<PortableForm>,
pub custom: CustomMetadata<PortableForm>,
}
impl RuntimeMetadataV15 {
pub fn new(
pallets: Vec<PalletMetadata>,
extrinsic: ExtrinsicMetadata,
runtime_type: MetaType,
apis: Vec<RuntimeApiMetadata>,
outer_enums: OuterEnums,
custom: CustomMetadata,
) -> Self {
let mut registry = Registry::new();
let pallets = registry.map_into_portable(pallets);
let extrinsic = extrinsic.into_portable(&mut registry);
let ty = registry.register_type(&runtime_type);
let apis = registry.map_into_portable(apis);
let outer_enums = outer_enums.into_portable(&mut registry);
let custom = custom.into_portable(&mut registry);
Self {
types: registry.into(),
pallets,
extrinsic,
ty,
apis,
outer_enums,
custom,
}
}
}
#[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 RuntimeApiMetadata<T: Form = MetaForm> {
pub name: T::String,
pub methods: Vec<RuntimeApiMethodMetadata<T>>,
pub docs: Vec<T::String>,
}
impl IntoPortable for RuntimeApiMetadata {
type Output = RuntimeApiMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMetadata {
name: self.name.into_portable(registry),
methods: registry.map_into_portable(self.methods),
docs: registry.map_into_portable(self.docs),
}
}
}
#[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 RuntimeApiMethodMetadata<T: Form = MetaForm> {
pub name: T::String,
pub inputs: Vec<RuntimeApiMethodParamMetadata<T>>,
pub output: T::Type,
pub docs: Vec<T::String>,
}
impl IntoPortable for RuntimeApiMethodMetadata {
type Output = RuntimeApiMethodMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMethodMetadata {
name: self.name.into_portable(registry),
inputs: registry.map_into_portable(self.inputs),
output: registry.register_type(&self.output),
docs: registry.map_into_portable(self.docs),
}
}
}
#[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<T: Form = MetaForm> {
pub name: T::String,
pub ty: T::Type,
}
impl IntoPortable for RuntimeApiMethodParamMetadata {
type Output = RuntimeApiMethodParamMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMethodParamMetadata {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
}
}
}
#[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 ExtrinsicMetadata<T: Form = MetaForm> {
pub version: u8,
pub address_ty: T::Type,
pub call_ty: T::Type,
pub signature_ty: T::Type,
pub extra_ty: T::Type,
pub signed_extensions: Vec<SignedExtensionMetadata<T>>,
}
impl IntoPortable for ExtrinsicMetadata {
type Output = ExtrinsicMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
ExtrinsicMetadata {
version: self.version,
address_ty: registry.register_type(&self.address_ty),
call_ty: registry.register_type(&self.call_ty),
signature_ty: registry.register_type(&self.signature_ty),
extra_ty: registry.register_type(&self.extra_ty),
signed_extensions: registry.map_into_portable(self.signed_extensions),
}
}
}
#[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 SignedExtensionMetadata<T: Form = MetaForm> {
pub identifier: T::String,
pub ty: T::Type,
pub additional_signed: T::Type,
}
impl IntoPortable for SignedExtensionMetadata {
type Output = SignedExtensionMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
SignedExtensionMetadata {
identifier: self.identifier.into_portable(registry),
ty: registry.register_type(&self.ty),
additional_signed: registry.register_type(&self.additional_signed),
}
}
}
#[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 PalletMetadata<T: Form = MetaForm> {
pub name: T::String,
pub storage: Option<PalletStorageMetadata<T>>,
pub calls: Option<PalletCallMetadata<T>>,
pub event: Option<PalletEventMetadata<T>>,
pub constants: Vec<PalletConstantMetadata<T>>,
pub error: Option<PalletErrorMetadata<T>>,
pub index: u8,
pub docs: Vec<T::String>,
}
impl IntoPortable for PalletMetadata {
type Output = PalletMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletMetadata {
name: self.name.into_portable(registry),
storage: self.storage.map(|storage| storage.into_portable(registry)),
calls: self.calls.map(|calls| calls.into_portable(registry)),
event: self.event.map(|event| event.into_portable(registry)),
constants: registry.map_into_portable(self.constants),
error: self.error.map(|error| error.into_portable(registry)),
index: self.index,
docs: registry.map_into_portable(self.docs),
}
}
}
#[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<T: Form = MetaForm> {
pub map: BTreeMap<T::String, CustomValueMetadata<T>>,
}
impl IntoPortable for CustomMetadata {
type Output = CustomMetadata<PortableForm>;
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 }
}
}
#[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<T: Form = MetaForm> {
pub ty: T::Type,
pub value: Vec<u8>,
}
impl IntoPortable for CustomValueMetadata {
type Output = CustomValueMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
CustomValueMetadata {
ty: registry.register_type(&self.ty),
value: self.value,
}
}
}
#[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<T: Form = MetaForm> {
pub call_enum_ty: T::Type,
pub event_enum_ty: T::Type,
pub error_enum_ty: T::Type,
}
impl IntoPortable for OuterEnums {
type Output = OuterEnums<PortableForm>;
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),
}
}
}