1use codec::{Compact, Decode, 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 pub version: Compact<u32>,
59}
60
61impl IntoPortable for RuntimeApiMetadataIR {
62 type Output = RuntimeApiMetadataIR<PortableForm>;
63
64 fn into_portable(self, registry: &mut Registry) -> Self::Output {
65 RuntimeApiMetadataIR {
66 name: self.name.into_portable(registry),
67 methods: registry.map_into_portable(self.methods),
68 docs: registry.map_into_portable(self.docs),
69 deprecation_info: self.deprecation_info.into_portable(registry),
70 version: self.version,
71 }
72 }
73}
74
75#[derive(Clone, PartialEq, Eq, Encode, Debug)]
77pub struct RuntimeApiMethodMetadataIR<T: Form = MetaForm> {
78 pub name: T::String,
80 pub inputs: Vec<RuntimeApiMethodParamMetadataIR<T>>,
82 pub output: T::Type,
84 pub docs: Vec<T::String>,
86 pub deprecation_info: DeprecationStatusIR<T>,
88}
89
90impl IntoPortable for RuntimeApiMethodMetadataIR {
91 type Output = RuntimeApiMethodMetadataIR<PortableForm>;
92
93 fn into_portable(self, registry: &mut Registry) -> Self::Output {
94 RuntimeApiMethodMetadataIR {
95 name: self.name.into_portable(registry),
96 inputs: registry.map_into_portable(self.inputs),
97 output: registry.register_type(&self.output),
98 docs: registry.map_into_portable(self.docs),
99 deprecation_info: self.deprecation_info.into_portable(registry),
100 }
101 }
102}
103
104#[derive(Clone, PartialEq, Eq, Encode, Debug)]
106pub struct RuntimeApiMethodParamMetadataIR<T: Form = MetaForm> {
107 pub name: T::String,
109 pub ty: T::Type,
111}
112
113impl IntoPortable for RuntimeApiMethodParamMetadataIR {
114 type Output = RuntimeApiMethodParamMetadataIR<PortableForm>;
115
116 fn into_portable(self, registry: &mut Registry) -> Self::Output {
117 RuntimeApiMethodParamMetadataIR {
118 name: self.name.into_portable(registry),
119 ty: registry.register_type(&self.ty),
120 }
121 }
122}
123
124#[derive(Clone, PartialEq, Eq, Encode, Decode, Debug)]
126pub struct PalletViewFunctionMetadataIR<T: Form = MetaForm> {
127 pub name: T::String,
129 pub id: [u8; 32],
131 pub inputs: Vec<PalletViewFunctionParamMetadataIR<T>>,
133 pub output: T::Type,
135 pub docs: Vec<T::String>,
137 pub deprecation_info: DeprecationStatusIR<T>,
139}
140
141impl IntoPortable for PalletViewFunctionMetadataIR {
142 type Output = PalletViewFunctionMetadataIR<PortableForm>;
143
144 fn into_portable(self, registry: &mut Registry) -> Self::Output {
145 PalletViewFunctionMetadataIR {
146 name: self.name.into_portable(registry),
147 id: self.id,
148 inputs: registry.map_into_portable(self.inputs),
149 output: registry.register_type(&self.output),
150 docs: registry.map_into_portable(self.docs),
151 deprecation_info: self.deprecation_info.into_portable(registry),
152 }
153 }
154}
155
156#[derive(Clone, PartialEq, Eq, Encode, Decode, Debug)]
158pub struct PalletViewFunctionParamMetadataIR<T: Form = MetaForm> {
159 pub name: T::String,
161 pub ty: T::Type,
163}
164
165impl IntoPortable for PalletViewFunctionParamMetadataIR {
166 type Output = PalletViewFunctionParamMetadataIR<PortableForm>;
167
168 fn into_portable(self, registry: &mut Registry) -> Self::Output {
169 PalletViewFunctionParamMetadataIR {
170 name: self.name.into_portable(registry),
171 ty: registry.register_type(&self.ty),
172 }
173 }
174}
175
176#[derive(Clone, PartialEq, Eq, Encode, Debug)]
178pub struct PalletMetadataIR<T: Form = MetaForm> {
179 pub name: T::String,
181 pub storage: Option<PalletStorageMetadataIR<T>>,
183 pub calls: Option<PalletCallMetadataIR<T>>,
185 pub view_functions: Vec<PalletViewFunctionMetadataIR<T>>,
187 pub event: Option<PalletEventMetadataIR<T>>,
189 pub constants: Vec<PalletConstantMetadataIR<T>>,
191 pub error: Option<PalletErrorMetadataIR<T>>,
193 pub associated_types: Vec<PalletAssociatedTypeMetadataIR<T>>,
195 pub index: u8,
198 pub docs: Vec<T::String>,
200 pub deprecation_info: DeprecationStatusIR<T>,
202}
203
204impl IntoPortable for PalletMetadataIR {
205 type Output = PalletMetadataIR<PortableForm>;
206
207 fn into_portable(self, registry: &mut Registry) -> Self::Output {
208 PalletMetadataIR {
209 name: self.name.into_portable(registry),
210 storage: self.storage.map(|storage| storage.into_portable(registry)),
211 calls: self.calls.map(|calls| calls.into_portable(registry)),
212 view_functions: self
213 .view_functions
214 .into_iter()
215 .map(|view_functions| view_functions.into_portable(registry))
216 .collect(),
217 event: self.event.map(|event| event.into_portable(registry)),
218 constants: registry.map_into_portable(self.constants),
219 error: self.error.map(|error| error.into_portable(registry)),
220 associated_types: registry.map_into_portable(self.associated_types),
221 index: self.index,
222 docs: registry.map_into_portable(self.docs),
223 deprecation_info: self.deprecation_info.into_portable(registry),
224 }
225 }
226}
227
228#[derive(Clone, PartialEq, Eq, Encode, Debug)]
230pub struct ExtrinsicMetadataIR<T: Form = MetaForm> {
231 pub ty: T::Type,
235 pub versions: Vec<u8>,
237 pub address_ty: T::Type,
239 pub call_ty: T::Type,
241 pub signature_ty: T::Type,
243 pub extra_ty: T::Type,
246 pub extensions: Vec<TransactionExtensionMetadataIR<T>>,
248}
249
250impl IntoPortable for ExtrinsicMetadataIR {
251 type Output = ExtrinsicMetadataIR<PortableForm>;
252
253 fn into_portable(self, registry: &mut Registry) -> Self::Output {
254 ExtrinsicMetadataIR {
255 ty: registry.register_type(&self.ty),
256 versions: self.versions,
257 address_ty: registry.register_type(&self.address_ty),
258 call_ty: registry.register_type(&self.call_ty),
259 signature_ty: registry.register_type(&self.signature_ty),
260 extra_ty: registry.register_type(&self.extra_ty),
261 extensions: registry.map_into_portable(self.extensions),
262 }
263 }
264}
265
266#[derive(Clone, PartialEq, Eq, Encode, Debug)]
268pub struct PalletAssociatedTypeMetadataIR<T: Form = MetaForm> {
269 pub name: T::String,
271 pub ty: T::Type,
273 pub docs: Vec<T::String>,
275}
276
277impl IntoPortable for PalletAssociatedTypeMetadataIR {
278 type Output = PalletAssociatedTypeMetadataIR<PortableForm>;
279
280 fn into_portable(self, registry: &mut Registry) -> Self::Output {
281 PalletAssociatedTypeMetadataIR {
282 name: self.name.into_portable(registry),
283 ty: registry.register_type(&self.ty),
284 docs: registry.map_into_portable(self.docs),
285 }
286 }
287}
288
289#[derive(Clone, PartialEq, Eq, Encode, Debug)]
291pub struct TransactionExtensionMetadataIR<T: Form = MetaForm> {
292 pub identifier: T::String,
294 pub ty: T::Type,
296 pub implicit: T::Type,
298}
299
300impl IntoPortable for TransactionExtensionMetadataIR {
301 type Output = TransactionExtensionMetadataIR<PortableForm>;
302
303 fn into_portable(self, registry: &mut Registry) -> Self::Output {
304 TransactionExtensionMetadataIR {
305 identifier: self.identifier.into_portable(registry),
306 ty: registry.register_type(&self.ty),
307 implicit: registry.register_type(&self.implicit),
308 }
309 }
310}
311
312#[derive(Clone, PartialEq, Eq, Encode, Debug)]
314pub struct PalletStorageMetadataIR<T: Form = MetaForm> {
316 pub prefix: T::String,
318 pub entries: Vec<StorageEntryMetadataIR<T>>,
320}
321
322impl IntoPortable for PalletStorageMetadataIR {
323 type Output = PalletStorageMetadataIR<PortableForm>;
324
325 fn into_portable(self, registry: &mut Registry) -> Self::Output {
326 PalletStorageMetadataIR {
327 prefix: self.prefix.into_portable(registry),
328 entries: registry.map_into_portable(self.entries),
329 }
330 }
331}
332
333#[derive(Clone, PartialEq, Eq, Encode, Debug)]
335pub struct StorageEntryMetadataIR<T: Form = MetaForm> {
336 pub name: T::String,
338 pub modifier: StorageEntryModifierIR,
340 pub ty: StorageEntryTypeIR<T>,
342 pub default: Vec<u8>,
344 pub docs: Vec<T::String>,
346 pub deprecation_info: DeprecationStatusIR<T>,
348}
349
350impl IntoPortable for StorageEntryMetadataIR {
351 type Output = StorageEntryMetadataIR<PortableForm>;
352
353 fn into_portable(self, registry: &mut Registry) -> Self::Output {
354 StorageEntryMetadataIR {
355 name: self.name.into_portable(registry),
356 modifier: self.modifier,
357 ty: self.ty.into_portable(registry),
358 default: self.default,
359 docs: registry.map_into_portable(self.docs),
360 deprecation_info: self.deprecation_info.into_portable(registry),
361 }
362 }
363}
364
365#[derive(Clone, PartialEq, Eq, Encode, Debug)]
373pub enum StorageEntryModifierIR {
374 Optional,
376 Default,
378}
379
380#[derive(Clone, PartialEq, Eq, Encode, Debug)]
382pub enum StorageHasherIR {
383 Blake2_128,
385 Blake2_256,
387 Blake2_128Concat,
389 Twox128,
391 Twox256,
393 Twox64Concat,
395 Identity,
397}
398
399#[derive(Clone, PartialEq, Eq, Encode, Debug)]
401pub enum StorageEntryTypeIR<T: Form = MetaForm> {
402 Plain(T::Type),
404 Map {
406 hashers: Vec<StorageHasherIR>,
408 key: T::Type,
410 value: T::Type,
412 },
413}
414
415impl IntoPortable for StorageEntryTypeIR {
416 type Output = StorageEntryTypeIR<PortableForm>;
417
418 fn into_portable(self, registry: &mut Registry) -> Self::Output {
419 match self {
420 Self::Plain(plain) => StorageEntryTypeIR::Plain(registry.register_type(&plain)),
421 Self::Map { hashers, key, value } => StorageEntryTypeIR::Map {
422 hashers,
423 key: registry.register_type(&key),
424 value: registry.register_type(&value),
425 },
426 }
427 }
428}
429
430#[derive(Clone, PartialEq, Eq, Encode, Debug)]
432pub struct PalletCallMetadataIR<T: Form = MetaForm> {
433 pub ty: T::Type,
435 pub deprecation_info: DeprecationInfoIR<T>,
437}
438
439impl IntoPortable for PalletCallMetadataIR {
440 type Output = PalletCallMetadataIR<PortableForm>;
441
442 fn into_portable(self, registry: &mut Registry) -> Self::Output {
443 PalletCallMetadataIR {
444 ty: registry.register_type(&self.ty),
445 deprecation_info: self.deprecation_info.into_portable(registry),
446 }
447 }
448}
449
450#[derive(Clone, PartialEq, Eq, Encode, Debug)]
452pub struct PalletEventMetadataIR<T: Form = MetaForm> {
453 pub ty: T::Type,
455 pub deprecation_info: DeprecationInfoIR<T>,
457}
458
459impl IntoPortable for PalletEventMetadataIR {
460 type Output = PalletEventMetadataIR<PortableForm>;
461
462 fn into_portable(self, registry: &mut Registry) -> Self::Output {
463 PalletEventMetadataIR {
464 ty: registry.register_type(&self.ty),
465 deprecation_info: self.deprecation_info.into_portable(registry),
466 }
467 }
468}
469
470#[derive(Clone, PartialEq, Eq, Encode, Debug)]
472pub struct PalletConstantMetadataIR<T: Form = MetaForm> {
473 pub name: T::String,
475 pub ty: T::Type,
477 pub value: Vec<u8>,
479 pub docs: Vec<T::String>,
481 pub deprecation_info: DeprecationStatusIR<T>,
483}
484
485impl IntoPortable for PalletConstantMetadataIR {
486 type Output = PalletConstantMetadataIR<PortableForm>;
487
488 fn into_portable(self, registry: &mut Registry) -> Self::Output {
489 PalletConstantMetadataIR {
490 name: self.name.into_portable(registry),
491 ty: registry.register_type(&self.ty),
492 value: self.value,
493 docs: registry.map_into_portable(self.docs),
494 deprecation_info: self.deprecation_info.into_portable(registry),
495 }
496 }
497}
498
499#[derive(Clone, PartialEq, Eq, Encode, Debug)]
501pub struct PalletErrorMetadataIR<T: Form = MetaForm> {
502 pub ty: T::Type,
504 pub deprecation_info: DeprecationInfoIR<T>,
506}
507
508impl IntoPortable for PalletErrorMetadataIR {
509 type Output = PalletErrorMetadataIR<PortableForm>;
510
511 fn into_portable(self, registry: &mut Registry) -> Self::Output {
512 PalletErrorMetadataIR {
513 ty: registry.register_type(&self.ty),
514 deprecation_info: self.deprecation_info.into_portable(registry),
515 }
516 }
517}
518
519#[derive(Clone, PartialEq, Eq, Encode, Debug)]
521pub struct OuterEnumsIR<T: Form = MetaForm> {
522 pub call_enum_ty: T::Type,
524 pub event_enum_ty: T::Type,
526 pub error_enum_ty: T::Type,
542}
543
544impl IntoPortable for OuterEnumsIR {
545 type Output = OuterEnumsIR<PortableForm>;
546
547 fn into_portable(self, registry: &mut Registry) -> Self::Output {
548 OuterEnumsIR {
549 call_enum_ty: registry.register_type(&self.call_enum_ty),
550 event_enum_ty: registry.register_type(&self.event_enum_ty),
551 error_enum_ty: registry.register_type(&self.error_enum_ty),
552 }
553 }
554}
555
556#[derive(Clone, PartialEq, Eq, Encode, Debug)]
558pub enum DeprecationStatusIR<T: Form = MetaForm> {
559 NotDeprecated,
561 DeprecatedWithoutNote,
563 Deprecated {
565 note: T::String,
567 since: Option<T::String>,
569 },
570}
571impl IntoPortable for DeprecationStatusIR {
572 type Output = DeprecationStatusIR<PortableForm>;
573
574 fn into_portable(self, registry: &mut Registry) -> Self::Output {
575 match self {
576 Self::Deprecated { note, since } => {
577 let note = note.into_portable(registry);
578 let since = since.map(|x| x.into_portable(registry));
579 DeprecationStatusIR::Deprecated { note, since }
580 },
581 Self::DeprecatedWithoutNote => DeprecationStatusIR::DeprecatedWithoutNote,
582 Self::NotDeprecated => DeprecationStatusIR::NotDeprecated,
583 }
584 }
585}
586#[derive(Clone, PartialEq, Eq, Encode, Debug)]
589pub enum DeprecationInfoIR<T: Form = MetaForm> {
590 NotDeprecated,
592 ItemDeprecated(DeprecationStatusIR<T>),
594 VariantsDeprecated(BTreeMap<Compact<u8>, DeprecationStatusIR<T>>),
596}
597impl IntoPortable for DeprecationInfoIR {
598 type Output = DeprecationInfoIR<PortableForm>;
599
600 fn into_portable(self, registry: &mut Registry) -> Self::Output {
601 match self {
602 Self::VariantsDeprecated(entries) => {
603 let entries =
604 entries.into_iter().map(|(k, entry)| (k, entry.into_portable(registry)));
605 DeprecationInfoIR::VariantsDeprecated(entries.collect())
606 },
607 Self::ItemDeprecated(deprecation) =>
608 DeprecationInfoIR::ItemDeprecated(deprecation.into_portable(registry)),
609 Self::NotDeprecated => DeprecationInfoIR::NotDeprecated,
610 }
611 }
612}