1#[cfg(feature = "decode")]
17use codec::Decode;
18#[cfg(feature = "serde_full")]
19use serde::Serialize;
20
21use super::{RuntimeMetadataPrefixed, META_RESERVED};
22use codec::Encode;
23use scale_info::{
24 form::{Form, MetaForm, PortableForm},
25 prelude::{collections::BTreeMap, vec::Vec},
26 IntoPortable, PortableRegistry, Registry,
27};
28
29pub use super::v14::{StorageEntryModifier, StorageEntryType, StorageHasher};
30
31pub type RuntimeMetadataLastVersion = RuntimeMetadataV16;
33
34impl From<RuntimeMetadataLastVersion> for super::RuntimeMetadataPrefixed {
35 fn from(metadata: RuntimeMetadataLastVersion) -> RuntimeMetadataPrefixed {
36 RuntimeMetadataPrefixed(META_RESERVED, super::RuntimeMetadata::V16(metadata))
37 }
38}
39
40#[derive(Clone, PartialEq, Eq, Encode, Debug)]
42#[cfg_attr(feature = "decode", derive(Decode))]
43#[cfg_attr(feature = "serde_full", derive(Serialize))]
44pub struct RuntimeMetadataV16 {
45 pub types: PortableRegistry,
47 pub pallets: Vec<PalletMetadata<PortableForm>>,
49 pub extrinsic: ExtrinsicMetadata<PortableForm>,
51 pub apis: Vec<RuntimeApiMetadata<PortableForm>>,
53 pub outer_enums: OuterEnums<PortableForm>,
55 pub custom: CustomMetadata<PortableForm>,
57}
58
59impl RuntimeMetadataV16 {
60 pub fn new(
62 pallets: Vec<PalletMetadata>,
63 extrinsic: ExtrinsicMetadata,
64 apis: Vec<RuntimeApiMetadata>,
65 outer_enums: OuterEnums,
66 custom: CustomMetadata,
67 ) -> Self {
68 let mut registry = Registry::new();
69 let pallets = registry.map_into_portable(pallets);
70 let extrinsic = extrinsic.into_portable(&mut registry);
71 let apis = registry.map_into_portable(apis);
72 let outer_enums = outer_enums.into_portable(&mut registry);
73 let custom = custom.into_portable(&mut registry);
74
75 Self {
76 types: registry.into(),
77 pallets,
78 extrinsic,
79 apis,
80 outer_enums,
81 custom,
82 }
83 }
84}
85
86#[derive(Clone, PartialEq, Eq, Encode, Debug)]
88#[cfg_attr(feature = "decode", derive(Decode))]
89#[cfg_attr(feature = "serde_full", derive(Serialize))]
90#[cfg_attr(
91 feature = "serde_full",
92 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
93)]
94pub struct RuntimeApiMetadata<T: Form = MetaForm> {
95 pub name: T::String,
97 pub methods: Vec<RuntimeApiMethodMetadata<T>>,
99 pub docs: Vec<T::String>,
101 pub deprecation_info: DeprecationStatus<T>,
103 pub version: u32,
105}
106
107impl IntoPortable for RuntimeApiMetadata {
108 type Output = RuntimeApiMetadata<PortableForm>;
109
110 fn into_portable(self, registry: &mut Registry) -> Self::Output {
111 RuntimeApiMetadata {
112 name: self.name.into_portable(registry),
113 methods: registry.map_into_portable(self.methods),
114 docs: registry.map_into_portable(self.docs),
115 deprecation_info: self.deprecation_info.into_portable(registry),
116 version: self.version,
117 }
118 }
119}
120
121#[derive(Clone, PartialEq, Eq, Encode, Debug)]
123#[cfg_attr(feature = "decode", derive(Decode))]
124#[cfg_attr(feature = "serde_full", derive(Serialize))]
125#[cfg_attr(
126 feature = "serde_full",
127 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
128)]
129pub struct RuntimeApiMethodMetadata<T: Form = MetaForm> {
130 pub name: T::String,
132 pub inputs: Vec<RuntimeApiMethodParamMetadata<T>>,
134 pub output: T::Type,
136 pub docs: Vec<T::String>,
138 pub deprecation_info: DeprecationStatus<T>,
140}
141
142impl IntoPortable for RuntimeApiMethodMetadata {
143 type Output = RuntimeApiMethodMetadata<PortableForm>;
144
145 fn into_portable(self, registry: &mut Registry) -> Self::Output {
146 RuntimeApiMethodMetadata {
147 name: self.name.into_portable(registry),
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, Debug)]
158#[cfg_attr(feature = "decode", derive(Decode))]
159#[cfg_attr(feature = "serde_full", derive(Serialize))]
160#[cfg_attr(
161 feature = "serde_full",
162 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
163)]
164pub struct RuntimeApiMethodParamMetadata<T: Form = MetaForm> {
165 pub name: T::String,
167 pub ty: T::Type,
169}
170
171impl IntoPortable for RuntimeApiMethodParamMetadata {
172 type Output = RuntimeApiMethodParamMetadata<PortableForm>;
173
174 fn into_portable(self, registry: &mut Registry) -> Self::Output {
175 RuntimeApiMethodParamMetadata {
176 name: self.name.into_portable(registry),
177 ty: registry.register_type(&self.ty),
178 }
179 }
180}
181
182#[derive(Clone, PartialEq, Eq, Encode, Debug)]
184#[cfg_attr(feature = "decode", derive(Decode))]
185#[cfg_attr(feature = "serde_full", derive(Serialize))]
186#[cfg_attr(
187 feature = "serde_full",
188 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
189)]
190pub struct ExtrinsicMetadata<T: Form = MetaForm> {
191 pub versions: Vec<u8>,
193 pub address_ty: T::Type,
195 pub signature_ty: T::Type,
197 pub transaction_extensions_by_version: BTreeMap<u8, Vec<u32>>,
201 pub transaction_extensions: Vec<TransactionExtensionMetadata<T>>,
203}
204
205impl IntoPortable for ExtrinsicMetadata {
206 type Output = ExtrinsicMetadata<PortableForm>;
207
208 fn into_portable(self, registry: &mut Registry) -> Self::Output {
209 ExtrinsicMetadata {
210 versions: self.versions,
211 address_ty: registry.register_type(&self.address_ty),
212 signature_ty: registry.register_type(&self.signature_ty),
213 transaction_extensions_by_version: self.transaction_extensions_by_version,
214 transaction_extensions: registry.map_into_portable(self.transaction_extensions),
215 }
216 }
217}
218
219#[derive(Clone, PartialEq, Eq, Encode, Debug)]
221#[cfg_attr(feature = "decode", derive(Decode))]
222#[cfg_attr(feature = "serde_full", derive(Serialize))]
223#[cfg_attr(
224 feature = "serde_full",
225 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
226)]
227pub struct TransactionExtensionMetadata<T: Form = MetaForm> {
228 pub identifier: T::String,
230 pub ty: T::Type,
232 pub implicit: T::Type,
234}
235
236impl IntoPortable for TransactionExtensionMetadata {
237 type Output = TransactionExtensionMetadata<PortableForm>;
238
239 fn into_portable(self, registry: &mut Registry) -> Self::Output {
240 TransactionExtensionMetadata {
241 identifier: self.identifier.into_portable(registry),
242 ty: registry.register_type(&self.ty),
243 implicit: registry.register_type(&self.implicit),
244 }
245 }
246}
247
248#[derive(Clone, PartialEq, Eq, Encode, Debug)]
250#[cfg_attr(feature = "decode", derive(Decode))]
251#[cfg_attr(feature = "serde_full", derive(Serialize))]
252#[cfg_attr(
253 feature = "serde_full",
254 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
255)]
256pub struct PalletMetadata<T: Form = MetaForm> {
257 pub name: T::String,
259 pub storage: Option<PalletStorageMetadata<T>>,
261 pub calls: Option<PalletCallMetadata<T>>,
263 pub event: Option<PalletEventMetadata<T>>,
265 pub constants: Vec<PalletConstantMetadata<T>>,
267 pub error: Option<PalletErrorMetadata<T>>,
269 pub associated_types: Vec<PalletAssociatedTypeMetadata<T>>,
271 pub view_functions: Vec<PalletViewFunctionMetadata<T>>,
273 pub index: u8,
276 pub docs: Vec<T::String>,
278 pub deprecation_info: DeprecationStatus<T>,
280}
281
282impl IntoPortable for PalletMetadata {
283 type Output = PalletMetadata<PortableForm>;
284
285 fn into_portable(self, registry: &mut Registry) -> Self::Output {
286 PalletMetadata {
287 name: self.name.into_portable(registry),
288 storage: self.storage.map(|storage| storage.into_portable(registry)),
289 calls: self.calls.map(|calls| calls.into_portable(registry)),
290 event: self.event.map(|event| event.into_portable(registry)),
291 constants: registry.map_into_portable(self.constants),
292 error: self.error.map(|error| error.into_portable(registry)),
293 associated_types: registry.map_into_portable(self.associated_types),
294 view_functions: registry.map_into_portable(self.view_functions),
295 index: self.index,
296 docs: registry.map_into_portable(self.docs),
297 deprecation_info: self.deprecation_info.into_portable(registry),
298 }
299 }
300}
301
302#[derive(Clone, PartialEq, Eq, Encode, Debug)]
304#[cfg_attr(feature = "decode", derive(Decode))]
305#[cfg_attr(feature = "serde_full", derive(Serialize))]
306#[cfg_attr(
307 feature = "serde_full",
308 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
309)]
310pub struct PalletCallMetadata<T: Form = MetaForm> {
311 pub ty: T::Type,
313 pub deprecation_info: DeprecationInfo<T>,
315}
316
317impl IntoPortable for PalletCallMetadata {
318 type Output = PalletCallMetadata<PortableForm>;
319
320 fn into_portable(self, registry: &mut Registry) -> Self::Output {
321 PalletCallMetadata {
322 ty: registry.register_type(&self.ty),
323 deprecation_info: self.deprecation_info.into_portable(registry),
324 }
325 }
326}
327
328#[derive(Clone, PartialEq, Eq, Encode, Debug)]
330#[cfg_attr(feature = "decode", derive(Decode))]
331#[cfg_attr(feature = "serde_full", derive(Serialize))]
332#[cfg_attr(
333 feature = "serde_full",
334 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
335)]
336pub struct PalletStorageMetadata<T: Form = MetaForm> {
337 pub prefix: T::String,
339 pub entries: Vec<StorageEntryMetadata<T>>,
341}
342
343impl IntoPortable for PalletStorageMetadata {
344 type Output = PalletStorageMetadata<PortableForm>;
345
346 fn into_portable(self, registry: &mut Registry) -> Self::Output {
347 PalletStorageMetadata {
348 prefix: self.prefix.into_portable(registry),
349 entries: registry.map_into_portable(self.entries),
350 }
351 }
352}
353
354#[derive(Clone, PartialEq, Eq, Encode, Debug)]
356#[cfg_attr(feature = "decode", derive(Decode))]
357#[cfg_attr(feature = "serde_full", derive(Serialize))]
358#[cfg_attr(
359 feature = "serde_full",
360 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
361)]
362pub struct StorageEntryMetadata<T: Form = MetaForm> {
363 pub name: T::String,
365 pub modifier: StorageEntryModifier,
367 pub ty: StorageEntryType<T>,
369 pub default: Vec<u8>,
371 pub docs: Vec<T::String>,
373 pub deprecation_info: DeprecationStatus<T>,
375}
376
377impl IntoPortable for StorageEntryMetadata {
378 type Output = StorageEntryMetadata<PortableForm>;
379
380 fn into_portable(self, registry: &mut Registry) -> Self::Output {
381 StorageEntryMetadata {
382 name: self.name.into_portable(registry),
383 modifier: self.modifier,
384 ty: self.ty.into_portable(registry),
385 default: self.default,
386 docs: registry.map_into_portable(self.docs),
387 deprecation_info: self.deprecation_info.into_portable(registry),
388 }
389 }
390}
391
392#[derive(Clone, PartialEq, Eq, Encode, Debug)]
394#[cfg_attr(feature = "decode", derive(Decode))]
395#[cfg_attr(feature = "serde_full", derive(Serialize))]
396#[cfg_attr(
397 feature = "serde_full",
398 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
399)]
400pub struct PalletEventMetadata<T: Form = MetaForm> {
401 pub ty: T::Type,
403 pub deprecation_info: DeprecationInfo<T>,
405}
406
407impl IntoPortable for PalletEventMetadata {
408 type Output = PalletEventMetadata<PortableForm>;
409
410 fn into_portable(self, registry: &mut Registry) -> Self::Output {
411 PalletEventMetadata {
412 ty: registry.register_type(&self.ty),
413 deprecation_info: self.deprecation_info.into_portable(registry),
414 }
415 }
416}
417
418#[derive(Clone, PartialEq, Eq, Encode, Debug)]
420#[cfg_attr(feature = "decode", derive(Decode))]
421#[cfg_attr(feature = "serde_full", derive(Serialize))]
422#[cfg_attr(
423 feature = "serde_full",
424 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
425)]
426pub struct PalletConstantMetadata<T: Form = MetaForm> {
427 pub name: T::String,
429 pub ty: T::Type,
431 pub value: Vec<u8>,
433 pub docs: Vec<T::String>,
435 pub deprecation_info: DeprecationStatus<T>,
437}
438
439impl IntoPortable for PalletConstantMetadata {
440 type Output = PalletConstantMetadata<PortableForm>;
441
442 fn into_portable(self, registry: &mut Registry) -> Self::Output {
443 PalletConstantMetadata {
444 name: self.name.into_portable(registry),
445 ty: registry.register_type(&self.ty),
446 value: self.value,
447 docs: registry.map_into_portable(self.docs),
448 deprecation_info: self.deprecation_info.into_portable(registry),
449 }
450 }
451}
452
453#[derive(Clone, PartialEq, Eq, Encode, Debug)]
455#[cfg_attr(feature = "decode", derive(Decode))]
456#[cfg_attr(feature = "serde_full", derive(Serialize))]
457#[cfg_attr(
458 feature = "serde_full",
459 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
460)]
461pub struct PalletErrorMetadata<T: Form = MetaForm> {
462 pub ty: T::Type,
464 pub deprecation_info: DeprecationInfo<T>,
466}
467
468impl IntoPortable for PalletErrorMetadata {
469 type Output = PalletErrorMetadata<PortableForm>;
470
471 fn into_portable(self, registry: &mut Registry) -> Self::Output {
472 PalletErrorMetadata {
473 ty: registry.register_type(&self.ty),
474 deprecation_info: self.deprecation_info.into_portable(registry),
475 }
476 }
477}
478
479#[derive(Clone, PartialEq, Eq, Encode, Debug)]
481#[cfg_attr(feature = "decode", derive(Decode))]
482#[cfg_attr(feature = "serde_full", derive(Serialize))]
483#[cfg_attr(
484 feature = "serde_full",
485 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
486)]
487pub struct PalletAssociatedTypeMetadata<T: Form = MetaForm> {
488 pub name: T::String,
490 pub ty: T::Type,
492 pub docs: Vec<T::String>,
494}
495
496impl IntoPortable for PalletAssociatedTypeMetadata {
497 type Output = PalletAssociatedTypeMetadata<PortableForm>;
498
499 fn into_portable(self, registry: &mut Registry) -> Self::Output {
500 PalletAssociatedTypeMetadata {
501 name: self.name.into_portable(registry),
502 ty: registry.register_type(&self.ty),
503 docs: registry.map_into_portable(self.docs),
504 }
505 }
506}
507
508#[derive(Clone, PartialEq, Eq, Encode, Debug)]
510#[cfg_attr(feature = "decode", derive(Decode))]
511#[cfg_attr(feature = "serde_full", derive(Serialize))]
512#[cfg_attr(
513 feature = "serde_full",
514 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
515)]
516pub struct PalletViewFunctionMetadata<T: Form = MetaForm> {
517 pub name: T::String,
519 pub id: [u8; 32],
521 pub inputs: Vec<PalletViewFunctionParamMetadata<T>>,
523 pub output: T::Type,
525 pub docs: Vec<T::String>,
527 pub deprecation_info: DeprecationStatus<T>,
529}
530
531impl IntoPortable for PalletViewFunctionMetadata {
532 type Output = PalletViewFunctionMetadata<PortableForm>;
533
534 fn into_portable(self, registry: &mut Registry) -> Self::Output {
535 PalletViewFunctionMetadata {
536 name: self.name.into_portable(registry),
537 id: self.id,
538 inputs: registry.map_into_portable(self.inputs),
539 output: registry.register_type(&self.output),
540 docs: registry.map_into_portable(self.docs),
541 deprecation_info: self.deprecation_info.into_portable(registry),
542 }
543 }
544}
545
546#[derive(Clone, PartialEq, Eq, Encode, Debug)]
548#[cfg_attr(feature = "decode", derive(Decode))]
549#[cfg_attr(feature = "serde_full", derive(Serialize))]
550#[cfg_attr(
551 feature = "serde_full",
552 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
553)]
554pub struct PalletViewFunctionParamMetadata<T: Form = MetaForm> {
555 pub name: T::String,
557 pub ty: T::Type,
559}
560
561impl IntoPortable for PalletViewFunctionParamMetadata {
562 type Output = PalletViewFunctionParamMetadata<PortableForm>;
563
564 fn into_portable(self, registry: &mut Registry) -> Self::Output {
565 PalletViewFunctionParamMetadata {
566 name: self.name.into_portable(registry),
567 ty: registry.register_type(&self.ty),
568 }
569 }
570}
571
572#[derive(Clone, PartialEq, Eq, Encode, Debug)]
576#[cfg_attr(feature = "decode", derive(Decode))]
577#[cfg_attr(feature = "serde_full", derive(Serialize))]
578#[cfg_attr(
579 feature = "serde_full",
580 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
581)]
582pub struct CustomMetadata<T: Form = MetaForm> {
583 pub map: BTreeMap<T::String, CustomValueMetadata<T>>,
585}
586
587impl IntoPortable for CustomMetadata {
588 type Output = CustomMetadata<PortableForm>;
589
590 fn into_portable(self, registry: &mut Registry) -> Self::Output {
591 let map = self
592 .map
593 .into_iter()
594 .map(|(key, value)| (key.into_portable(registry), value.into_portable(registry)))
595 .collect();
596
597 CustomMetadata { map }
598 }
599}
600
601#[derive(Clone, PartialEq, Eq, Encode, Debug)]
603#[cfg_attr(feature = "decode", derive(Decode))]
604#[cfg_attr(feature = "serde_full", derive(Serialize))]
605#[cfg_attr(
606 feature = "serde_full",
607 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
608)]
609pub struct CustomValueMetadata<T: Form = MetaForm> {
610 pub ty: T::Type,
612 pub value: Vec<u8>,
614}
615
616impl IntoPortable for CustomValueMetadata {
617 type Output = CustomValueMetadata<PortableForm>;
618
619 fn into_portable(self, registry: &mut Registry) -> Self::Output {
620 CustomValueMetadata {
621 ty: registry.register_type(&self.ty),
622 value: self.value,
623 }
624 }
625}
626
627#[derive(Clone, PartialEq, Eq, Encode, Debug)]
629#[cfg_attr(feature = "decode", derive(Decode))]
630#[cfg_attr(feature = "serde_full", derive(Serialize))]
631#[cfg_attr(
632 feature = "serde_full",
633 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
634)]
635pub struct OuterEnums<T: Form = MetaForm> {
636 pub call_enum_ty: T::Type,
638 pub event_enum_ty: T::Type,
640 pub error_enum_ty: T::Type,
656}
657
658impl IntoPortable for OuterEnums {
659 type Output = OuterEnums<PortableForm>;
660
661 fn into_portable(self, registry: &mut Registry) -> Self::Output {
662 OuterEnums {
663 call_enum_ty: registry.register_type(&self.call_enum_ty),
664 event_enum_ty: registry.register_type(&self.event_enum_ty),
665 error_enum_ty: registry.register_type(&self.error_enum_ty),
666 }
667 }
668}
669
670#[derive(Clone, PartialEq, Eq, Encode, Debug)]
672#[cfg_attr(feature = "decode", derive(Decode))]
673#[cfg_attr(feature = "serde_full", derive(Serialize))]
674#[cfg_attr(
675 feature = "serde_full",
676 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
677)]
678pub enum DeprecationStatus<T: Form = MetaForm> {
679 NotDeprecated,
681 DeprecatedWithoutNote,
683 Deprecated {
685 note: T::String,
687 since: Option<T::String>,
689 },
690}
691impl IntoPortable for DeprecationStatus {
692 type Output = DeprecationStatus<PortableForm>;
693
694 fn into_portable(self, registry: &mut Registry) -> Self::Output {
695 match self {
696 Self::Deprecated { note, since } => {
697 let note = note.into_portable(registry);
698 let since = since.map(|x| x.into_portable(registry));
699 DeprecationStatus::Deprecated { note, since }
700 }
701 Self::DeprecatedWithoutNote => DeprecationStatus::DeprecatedWithoutNote,
702 Self::NotDeprecated => DeprecationStatus::NotDeprecated,
703 }
704 }
705}
706#[derive(Clone, PartialEq, Eq, Encode, Debug)]
709#[cfg_attr(feature = "decode", derive(Decode))]
710#[cfg_attr(feature = "serde_full", derive(Serialize))]
711#[cfg_attr(
712 feature = "serde_full",
713 serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
714)]
715pub enum DeprecationInfo<T: Form = MetaForm> {
716 NotDeprecated,
718 ItemDeprecated(DeprecationStatus<T>),
720 VariantsDeprecated(BTreeMap<u8, DeprecationStatus<T>>),
722}
723impl IntoPortable for DeprecationInfo {
724 type Output = DeprecationInfo<PortableForm>;
725
726 fn into_portable(self, registry: &mut Registry) -> Self::Output {
727 match self {
728 Self::VariantsDeprecated(entries) => {
729 let entries = entries
730 .into_iter()
731 .map(|(k, entry)| (k, entry.into_portable(registry)));
732 DeprecationInfo::VariantsDeprecated(entries.collect())
733 }
734 Self::ItemDeprecated(deprecation) => {
735 DeprecationInfo::ItemDeprecated(deprecation.into_portable(registry))
736 }
737 Self::NotDeprecated => DeprecationInfo::NotDeprecated,
738 }
739 }
740}