1use codec::{Compact, Encode};
19use scale_info::{
20 form::{Form, MetaForm, PortableForm},
21 prelude::{collections::BTreeMap, vec::Vec},
22 IntoPortable, Registry,
23};
24
25pub struct MetadataIR<T: Form = MetaForm> {
34 pub pallets: Vec<PalletMetadataIR<T>>,
36 pub extrinsic: ExtrinsicMetadataIR<T>,
38 pub ty: T::Type,
40 pub apis: Vec<RuntimeApiMetadataIR<T>>,
42 pub outer_enums: OuterEnumsIR<T>,
44}
45
46#[derive(Clone, PartialEq, Eq, Encode, Debug)]
48pub struct RuntimeApiMetadataIR<T: Form = MetaForm> {
49 pub name: T::String,
51 pub methods: Vec<RuntimeApiMethodMetadataIR<T>>,
53 pub docs: Vec<T::String>,
55 pub deprecation_info: DeprecationStatusIR<T>,
57}
58
59impl IntoPortable for RuntimeApiMetadataIR {
60 type Output = RuntimeApiMetadataIR<PortableForm>;
61
62 fn into_portable(self, registry: &mut Registry) -> Self::Output {
63 RuntimeApiMetadataIR {
64 name: self.name.into_portable(registry),
65 methods: registry.map_into_portable(self.methods),
66 docs: registry.map_into_portable(self.docs),
67 deprecation_info: self.deprecation_info.into_portable(registry),
68 }
69 }
70}
71
72#[derive(Clone, PartialEq, Eq, Encode, Debug)]
74pub struct RuntimeApiMethodMetadataIR<T: Form = MetaForm> {
75 pub name: T::String,
77 pub inputs: Vec<RuntimeApiMethodParamMetadataIR<T>>,
79 pub output: T::Type,
81 pub docs: Vec<T::String>,
83 pub deprecation_info: DeprecationStatusIR<T>,
85}
86
87impl IntoPortable for RuntimeApiMethodMetadataIR {
88 type Output = RuntimeApiMethodMetadataIR<PortableForm>;
89
90 fn into_portable(self, registry: &mut Registry) -> Self::Output {
91 RuntimeApiMethodMetadataIR {
92 name: self.name.into_portable(registry),
93 inputs: registry.map_into_portable(self.inputs),
94 output: registry.register_type(&self.output),
95 docs: registry.map_into_portable(self.docs),
96 deprecation_info: self.deprecation_info.into_portable(registry),
97 }
98 }
99}
100
101#[derive(Clone, PartialEq, Eq, Encode, Debug)]
103pub struct RuntimeApiMethodParamMetadataIR<T: Form = MetaForm> {
104 pub name: T::String,
106 pub ty: T::Type,
108}
109
110impl IntoPortable for RuntimeApiMethodParamMetadataIR {
111 type Output = RuntimeApiMethodParamMetadataIR<PortableForm>;
112
113 fn into_portable(self, registry: &mut Registry) -> Self::Output {
114 RuntimeApiMethodParamMetadataIR {
115 name: self.name.into_portable(registry),
116 ty: registry.register_type(&self.ty),
117 }
118 }
119}
120
121#[derive(Clone, PartialEq, Eq, Encode, Debug)]
123pub struct PalletMetadataIR<T: Form = MetaForm> {
124 pub name: T::String,
126 pub storage: Option<PalletStorageMetadataIR<T>>,
128 pub calls: Option<PalletCallMetadataIR<T>>,
130 pub event: Option<PalletEventMetadataIR<T>>,
132 pub constants: Vec<PalletConstantMetadataIR<T>>,
134 pub error: Option<PalletErrorMetadataIR<T>>,
136 pub index: u8,
139 pub docs: Vec<T::String>,
141 pub deprecation_info: DeprecationStatusIR<T>,
143}
144
145impl IntoPortable for PalletMetadataIR {
146 type Output = PalletMetadataIR<PortableForm>;
147
148 fn into_portable(self, registry: &mut Registry) -> Self::Output {
149 PalletMetadataIR {
150 name: self.name.into_portable(registry),
151 storage: self.storage.map(|storage| storage.into_portable(registry)),
152 calls: self.calls.map(|calls| calls.into_portable(registry)),
153 event: self.event.map(|event| event.into_portable(registry)),
154 constants: registry.map_into_portable(self.constants),
155 error: self.error.map(|error| error.into_portable(registry)),
156 index: self.index,
157 docs: registry.map_into_portable(self.docs),
158 deprecation_info: self.deprecation_info.into_portable(registry),
159 }
160 }
161}
162
163#[derive(Clone, PartialEq, Eq, Encode, Debug)]
165pub struct ExtrinsicMetadataIR<T: Form = MetaForm> {
166 pub ty: T::Type,
170 pub version: u8,
172 pub address_ty: T::Type,
174 pub call_ty: T::Type,
176 pub signature_ty: T::Type,
178 pub extra_ty: T::Type,
180 pub signed_extensions: Vec<SignedExtensionMetadataIR<T>>,
182}
183
184impl IntoPortable for ExtrinsicMetadataIR {
185 type Output = ExtrinsicMetadataIR<PortableForm>;
186
187 fn into_portable(self, registry: &mut Registry) -> Self::Output {
188 ExtrinsicMetadataIR {
189 ty: registry.register_type(&self.ty),
190 version: self.version,
191 address_ty: registry.register_type(&self.address_ty),
192 call_ty: registry.register_type(&self.call_ty),
193 signature_ty: registry.register_type(&self.signature_ty),
194 extra_ty: registry.register_type(&self.extra_ty),
195 signed_extensions: registry.map_into_portable(self.signed_extensions),
196 }
197 }
198}
199
200#[derive(Clone, PartialEq, Eq, Encode, Debug)]
202pub struct SignedExtensionMetadataIR<T: Form = MetaForm> {
203 pub identifier: T::String,
205 pub ty: T::Type,
207 pub additional_signed: T::Type,
209}
210
211impl IntoPortable for SignedExtensionMetadataIR {
212 type Output = SignedExtensionMetadataIR<PortableForm>;
213
214 fn into_portable(self, registry: &mut Registry) -> Self::Output {
215 SignedExtensionMetadataIR {
216 identifier: self.identifier.into_portable(registry),
217 ty: registry.register_type(&self.ty),
218 additional_signed: registry.register_type(&self.additional_signed),
219 }
220 }
221}
222
223#[derive(Clone, PartialEq, Eq, Encode, Debug)]
225pub struct PalletStorageMetadataIR<T: Form = MetaForm> {
227 pub prefix: T::String,
229 pub entries: Vec<StorageEntryMetadataIR<T>>,
231}
232
233impl IntoPortable for PalletStorageMetadataIR {
234 type Output = PalletStorageMetadataIR<PortableForm>;
235
236 fn into_portable(self, registry: &mut Registry) -> Self::Output {
237 PalletStorageMetadataIR {
238 prefix: self.prefix.into_portable(registry),
239 entries: registry.map_into_portable(self.entries),
240 }
241 }
242}
243
244#[derive(Clone, PartialEq, Eq, Encode, Debug)]
246pub struct StorageEntryMetadataIR<T: Form = MetaForm> {
247 pub name: T::String,
249 pub modifier: StorageEntryModifierIR,
251 pub ty: StorageEntryTypeIR<T>,
253 pub default: Vec<u8>,
255 pub docs: Vec<T::String>,
257 pub deprecation_info: DeprecationStatusIR<T>,
259}
260
261impl IntoPortable for StorageEntryMetadataIR {
262 type Output = StorageEntryMetadataIR<PortableForm>;
263
264 fn into_portable(self, registry: &mut Registry) -> Self::Output {
265 StorageEntryMetadataIR {
266 name: self.name.into_portable(registry),
267 modifier: self.modifier,
268 ty: self.ty.into_portable(registry),
269 default: self.default,
270 docs: registry.map_into_portable(self.docs),
271 deprecation_info: self.deprecation_info.into_portable(registry),
272 }
273 }
274}
275
276#[derive(Clone, PartialEq, Eq, Encode, Debug)]
284pub enum StorageEntryModifierIR {
285 Optional,
287 Default,
289}
290
291#[derive(Clone, PartialEq, Eq, Encode, Debug)]
293pub enum StorageHasherIR {
294 Blake2_128,
296 Blake2_256,
298 Blake2_128Concat,
300 Twox128,
302 Twox256,
304 Twox64Concat,
306 Identity,
308}
309
310#[derive(Clone, PartialEq, Eq, Encode, Debug)]
312pub enum StorageEntryTypeIR<T: Form = MetaForm> {
313 Plain(T::Type),
315 Map {
317 hashers: Vec<StorageHasherIR>,
319 key: T::Type,
321 value: T::Type,
323 },
324}
325
326impl IntoPortable for StorageEntryTypeIR {
327 type Output = StorageEntryTypeIR<PortableForm>;
328
329 fn into_portable(self, registry: &mut Registry) -> Self::Output {
330 match self {
331 Self::Plain(plain) => StorageEntryTypeIR::Plain(registry.register_type(&plain)),
332 Self::Map { hashers, key, value } => StorageEntryTypeIR::Map {
333 hashers,
334 key: registry.register_type(&key),
335 value: registry.register_type(&value),
336 },
337 }
338 }
339}
340
341#[derive(Clone, PartialEq, Eq, Encode, Debug)]
343pub struct PalletCallMetadataIR<T: Form = MetaForm> {
344 pub ty: T::Type,
346 pub deprecation_info: DeprecationInfoIR<T>,
348}
349
350impl IntoPortable for PalletCallMetadataIR {
351 type Output = PalletCallMetadataIR<PortableForm>;
352
353 fn into_portable(self, registry: &mut Registry) -> Self::Output {
354 PalletCallMetadataIR {
355 ty: registry.register_type(&self.ty),
356 deprecation_info: self.deprecation_info.into_portable(registry),
357 }
358 }
359}
360
361#[derive(Clone, PartialEq, Eq, Encode, Debug)]
363pub struct PalletEventMetadataIR<T: Form = MetaForm> {
364 pub ty: T::Type,
366 pub deprecation_info: DeprecationInfoIR<T>,
368}
369
370impl IntoPortable for PalletEventMetadataIR {
371 type Output = PalletEventMetadataIR<PortableForm>;
372
373 fn into_portable(self, registry: &mut Registry) -> Self::Output {
374 PalletEventMetadataIR {
375 ty: registry.register_type(&self.ty),
376 deprecation_info: self.deprecation_info.into_portable(registry),
377 }
378 }
379}
380
381#[derive(Clone, PartialEq, Eq, Encode, Debug)]
383pub struct PalletConstantMetadataIR<T: Form = MetaForm> {
384 pub name: T::String,
386 pub ty: T::Type,
388 pub value: Vec<u8>,
390 pub docs: Vec<T::String>,
392 pub deprecation_info: DeprecationStatusIR<T>,
394}
395
396impl IntoPortable for PalletConstantMetadataIR {
397 type Output = PalletConstantMetadataIR<PortableForm>;
398
399 fn into_portable(self, registry: &mut Registry) -> Self::Output {
400 PalletConstantMetadataIR {
401 name: self.name.into_portable(registry),
402 ty: registry.register_type(&self.ty),
403 value: self.value,
404 docs: registry.map_into_portable(self.docs),
405 deprecation_info: self.deprecation_info.into_portable(registry),
406 }
407 }
408}
409
410#[derive(Clone, PartialEq, Eq, Encode, Debug)]
412pub struct PalletErrorMetadataIR<T: Form = MetaForm> {
413 pub ty: T::Type,
415 pub deprecation_info: DeprecationInfoIR<T>,
417}
418
419impl IntoPortable for PalletErrorMetadataIR {
420 type Output = PalletErrorMetadataIR<PortableForm>;
421
422 fn into_portable(self, registry: &mut Registry) -> Self::Output {
423 PalletErrorMetadataIR {
424 ty: registry.register_type(&self.ty),
425 deprecation_info: self.deprecation_info.into_portable(registry),
426 }
427 }
428}
429
430#[derive(Clone, PartialEq, Eq, Encode, Debug)]
432pub struct OuterEnumsIR<T: Form = MetaForm> {
433 pub call_enum_ty: T::Type,
435 pub event_enum_ty: T::Type,
437 pub error_enum_ty: T::Type,
453}
454
455impl IntoPortable for OuterEnumsIR {
456 type Output = OuterEnumsIR<PortableForm>;
457
458 fn into_portable(self, registry: &mut Registry) -> Self::Output {
459 OuterEnumsIR {
460 call_enum_ty: registry.register_type(&self.call_enum_ty),
461 event_enum_ty: registry.register_type(&self.event_enum_ty),
462 error_enum_ty: registry.register_type(&self.error_enum_ty),
463 }
464 }
465}
466
467#[derive(Clone, PartialEq, Eq, Encode, Debug)]
469pub enum DeprecationStatusIR<T: Form = MetaForm> {
470 NotDeprecated,
472 DeprecatedWithoutNote,
474 Deprecated {
476 note: T::String,
478 since: Option<T::String>,
480 },
481}
482impl IntoPortable for DeprecationStatusIR {
483 type Output = DeprecationStatusIR<PortableForm>;
484
485 fn into_portable(self, registry: &mut Registry) -> Self::Output {
486 match self {
487 Self::Deprecated { note, since } => {
488 let note = note.into_portable(registry);
489 let since = since.map(|x| x.into_portable(registry));
490 DeprecationStatusIR::Deprecated { note, since }
491 },
492 Self::DeprecatedWithoutNote => DeprecationStatusIR::DeprecatedWithoutNote,
493 Self::NotDeprecated => DeprecationStatusIR::NotDeprecated,
494 }
495 }
496}
497#[derive(Clone, PartialEq, Eq, Encode, Debug)]
500pub enum DeprecationInfoIR<T: Form = MetaForm> {
501 NotDeprecated,
503 ItemDeprecated(DeprecationStatusIR<T>),
505 VariantsDeprecated(BTreeMap<Compact<u8>, DeprecationStatusIR<T>>),
507}
508impl IntoPortable for DeprecationInfoIR {
509 type Output = DeprecationInfoIR<PortableForm>;
510
511 fn into_portable(self, registry: &mut Registry) -> Self::Output {
512 match self {
513 Self::VariantsDeprecated(entries) => {
514 let entries =
515 entries.into_iter().map(|(k, entry)| (k, entry.into_portable(registry)));
516 DeprecationInfoIR::VariantsDeprecated(entries.collect())
517 },
518 Self::ItemDeprecated(deprecation) =>
519 DeprecationInfoIR::ItemDeprecated(deprecation.into_portable(registry)),
520 Self::NotDeprecated => DeprecationInfoIR::NotDeprecated,
521 }
522 }
523}