use codec::Encode;
use scale_info::{
form::{Form, MetaForm, PortableForm},
prelude::vec::Vec,
IntoPortable, MetaType, Registry,
};
pub struct MetadataIR<T: Form = MetaForm> {
pub pallets: Vec<PalletMetadataIR<T>>,
pub extrinsic: ExtrinsicMetadataIR<T>,
pub ty: T::Type,
pub apis: Vec<RuntimeApiMetadataIR<T>>,
pub outer_enums: OuterEnumsIR<T>,
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct RuntimeApiMetadataIR<T: Form = MetaForm> {
pub name: T::String,
pub methods: Vec<RuntimeApiMethodMetadataIR<T>>,
pub docs: Vec<T::String>,
}
impl IntoPortable for RuntimeApiMetadataIR {
type Output = RuntimeApiMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMetadataIR {
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)]
pub struct RuntimeApiMethodMetadataIR<T: Form = MetaForm> {
pub name: T::String,
pub inputs: Vec<RuntimeApiMethodParamMetadataIR<T>>,
pub output: T::Type,
pub docs: Vec<T::String>,
}
impl IntoPortable for RuntimeApiMethodMetadataIR {
type Output = RuntimeApiMethodMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMethodMetadataIR {
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)]
pub struct RuntimeApiMethodParamMetadataIR<T: Form = MetaForm> {
pub name: T::String,
pub ty: T::Type,
}
impl IntoPortable for RuntimeApiMethodParamMetadataIR {
type Output = RuntimeApiMethodParamMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMethodParamMetadataIR {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
}
}
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletMetadataIR<T: Form = MetaForm> {
pub name: T::String,
pub storage: Option<PalletStorageMetadataIR<T>>,
pub calls: Option<PalletCallMetadataIR<T>>,
pub event: Option<PalletEventMetadataIR<T>>,
pub constants: Vec<PalletConstantMetadataIR<T>>,
pub error: Option<PalletErrorMetadataIR<T>>,
pub index: u8,
pub docs: Vec<T::String>,
}
impl IntoPortable for PalletMetadataIR {
type Output = PalletMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletMetadataIR {
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)]
pub struct ExtrinsicMetadataIR<T: Form = MetaForm> {
pub ty: T::Type,
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<SignedExtensionMetadataIR<T>>,
}
impl IntoPortable for ExtrinsicMetadataIR {
type Output = ExtrinsicMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
ExtrinsicMetadataIR {
ty: registry.register_type(&self.ty),
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)]
pub struct SignedExtensionMetadataIR<T: Form = MetaForm> {
pub identifier: T::String,
pub ty: T::Type,
pub additional_signed: T::Type,
}
impl IntoPortable for SignedExtensionMetadataIR {
type Output = SignedExtensionMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
SignedExtensionMetadataIR {
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)]
pub struct PalletStorageMetadataIR<T: Form = MetaForm> {
pub prefix: T::String,
pub entries: Vec<StorageEntryMetadataIR<T>>,
}
impl IntoPortable for PalletStorageMetadataIR {
type Output = PalletStorageMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletStorageMetadataIR {
prefix: self.prefix.into_portable(registry),
entries: registry.map_into_portable(self.entries),
}
}
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct StorageEntryMetadataIR<T: Form = MetaForm> {
pub name: T::String,
pub modifier: StorageEntryModifierIR,
pub ty: StorageEntryTypeIR<T>,
pub default: Vec<u8>,
pub docs: Vec<T::String>,
}
impl IntoPortable for StorageEntryMetadataIR {
type Output = StorageEntryMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
StorageEntryMetadataIR {
name: self.name.into_portable(registry),
modifier: self.modifier,
ty: self.ty.into_portable(registry),
default: self.default,
docs: registry.map_into_portable(self.docs),
}
}
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub enum StorageEntryModifierIR {
Optional,
Default,
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub enum StorageHasherIR {
Blake2_128,
Blake2_256,
Blake2_128Concat,
Twox128,
Twox256,
Twox64Concat,
Identity,
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub enum StorageEntryTypeIR<T: Form = MetaForm> {
Plain(T::Type),
Map {
hashers: Vec<StorageHasherIR>,
key: T::Type,
value: T::Type,
},
}
impl IntoPortable for StorageEntryTypeIR {
type Output = StorageEntryTypeIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
match self {
Self::Plain(plain) => StorageEntryTypeIR::Plain(registry.register_type(&plain)),
Self::Map { hashers, key, value } => StorageEntryTypeIR::Map {
hashers,
key: registry.register_type(&key),
value: registry.register_type(&value),
},
}
}
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletCallMetadataIR<T: Form = MetaForm> {
pub ty: T::Type,
}
impl IntoPortable for PalletCallMetadataIR {
type Output = PalletCallMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletCallMetadataIR { ty: registry.register_type(&self.ty) }
}
}
impl From<MetaType> for PalletCallMetadataIR {
fn from(ty: MetaType) -> Self {
Self { ty }
}
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletEventMetadataIR<T: Form = MetaForm> {
pub ty: T::Type,
}
impl IntoPortable for PalletEventMetadataIR {
type Output = PalletEventMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletEventMetadataIR { ty: registry.register_type(&self.ty) }
}
}
impl From<MetaType> for PalletEventMetadataIR {
fn from(ty: MetaType) -> Self {
Self { ty }
}
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletConstantMetadataIR<T: Form = MetaForm> {
pub name: T::String,
pub ty: T::Type,
pub value: Vec<u8>,
pub docs: Vec<T::String>,
}
impl IntoPortable for PalletConstantMetadataIR {
type Output = PalletConstantMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletConstantMetadataIR {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
value: self.value,
docs: registry.map_into_portable(self.docs),
}
}
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletErrorMetadataIR<T: Form = MetaForm> {
pub ty: T::Type,
}
impl IntoPortable for PalletErrorMetadataIR {
type Output = PalletErrorMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletErrorMetadataIR { ty: registry.register_type(&self.ty) }
}
}
impl From<MetaType> for PalletErrorMetadataIR {
fn from(ty: MetaType) -> Self {
Self { ty }
}
}
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct OuterEnumsIR<T: Form = MetaForm> {
pub call_enum_ty: T::Type,
pub event_enum_ty: T::Type,
pub error_enum_ty: T::Type,
}
impl IntoPortable for OuterEnumsIR {
type Output = OuterEnumsIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
OuterEnumsIR {
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),
}
}
}