1use super::types::{
21 ExtrinsicMetadataIR, MetadataIR, OuterEnumsIR, PalletMetadataIR, RuntimeApiMetadataIR,
22 RuntimeApiMethodMetadataIR, RuntimeApiMethodParamMetadataIR, TransactionExtensionMetadataIR,
23};
24
25use frame_metadata::v15::{
26 CustomMetadata, ExtrinsicMetadata, OuterEnums, PalletMetadata, RuntimeApiMetadata,
27 RuntimeApiMethodMetadata, RuntimeApiMethodParamMetadata, RuntimeMetadataV15,
28 SignedExtensionMetadata,
29};
30use scale_info::{IntoPortable, Registry};
31
32impl From<MetadataIR> for RuntimeMetadataV15 {
33 fn from(ir: MetadataIR) -> Self {
34 let mut registry = Registry::new();
35 let pallets =
36 registry.map_into_portable(ir.pallets.into_iter().map(Into::<PalletMetadata>::into));
37 let extrinsic = Into::<ExtrinsicMetadata>::into(ir.extrinsic).into_portable(&mut registry);
38 let ty = registry.register_type(&ir.ty);
39 let apis =
40 registry.map_into_portable(ir.apis.into_iter().map(Into::<RuntimeApiMetadata>::into));
41 let outer_enums = Into::<OuterEnums>::into(ir.outer_enums).into_portable(&mut registry);
42 let custom = CustomMetadata { map: Default::default() };
43
44 Self { types: registry.into(), pallets, extrinsic, ty, apis, outer_enums, custom }
45 }
46}
47
48impl From<RuntimeApiMetadataIR> for RuntimeApiMetadata {
49 fn from(ir: RuntimeApiMetadataIR) -> Self {
50 RuntimeApiMetadata {
51 name: ir.name,
52 methods: ir.methods.into_iter().map(Into::into).collect(),
53 docs: ir.docs,
54 }
55 }
56}
57
58impl From<RuntimeApiMethodMetadataIR> for RuntimeApiMethodMetadata {
59 fn from(ir: RuntimeApiMethodMetadataIR) -> Self {
60 RuntimeApiMethodMetadata {
61 name: ir.name,
62 inputs: ir.inputs.into_iter().map(Into::into).collect(),
63 output: ir.output,
64 docs: ir.docs,
65 }
66 }
67}
68
69impl From<RuntimeApiMethodParamMetadataIR> for RuntimeApiMethodParamMetadata {
70 fn from(ir: RuntimeApiMethodParamMetadataIR) -> Self {
71 RuntimeApiMethodParamMetadata { name: ir.name, ty: ir.ty }
72 }
73}
74
75impl From<PalletMetadataIR> for PalletMetadata {
76 fn from(ir: PalletMetadataIR) -> Self {
77 PalletMetadata {
78 name: ir.name,
79 storage: ir.storage.map(Into::into),
80 calls: ir.calls.map(Into::into),
81 event: ir.event.map(Into::into),
82 constants: ir.constants.into_iter().map(Into::into).collect(),
83 error: ir.error.map(Into::into),
84 index: ir.index,
85 docs: ir.docs,
86 }
87 }
88}
89
90impl From<TransactionExtensionMetadataIR> for SignedExtensionMetadata {
91 fn from(ir: TransactionExtensionMetadataIR) -> Self {
92 SignedExtensionMetadata {
93 identifier: ir.identifier,
94 ty: ir.ty,
95 additional_signed: ir.implicit,
96 }
97 }
98}
99
100impl From<ExtrinsicMetadataIR> for ExtrinsicMetadata {
101 fn from(ir: ExtrinsicMetadataIR) -> Self {
102 ExtrinsicMetadata {
103 version: *ir.versions.iter().min().expect("Metadata V15 supports only one version"),
104 address_ty: ir.address_ty,
105 call_ty: ir.call_ty,
106 signature_ty: ir.signature_ty,
107 extra_ty: ir.extra_ty,
108 signed_extensions: ir.extensions.into_iter().map(Into::into).collect(),
109 }
110 }
111}
112
113impl From<OuterEnumsIR> for OuterEnums {
114 fn from(ir: OuterEnumsIR) -> Self {
115 OuterEnums {
116 call_enum_ty: ir.call_enum_ty,
117 event_enum_ty: ir.event_enum_ty,
118 error_enum_ty: ir.error_enum_ty,
119 }
120 }
121}