frame_metadata/
v16.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#[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
31/// Latest runtime metadata
32pub 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/// The metadata of a runtime.
41#[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	/// Type registry containing all types used in the metadata.
46	pub types: PortableRegistry,
47	/// Metadata of all the pallets.
48	pub pallets: Vec<PalletMetadata<PortableForm>>,
49	/// Metadata of the extrinsic.
50	pub extrinsic: ExtrinsicMetadata<PortableForm>,
51	/// Metadata of the Runtime API.
52	pub apis: Vec<RuntimeApiMetadata<PortableForm>>,
53	/// The outer enums types as found in the runtime.
54	pub outer_enums: OuterEnums<PortableForm>,
55	/// Allows users to add custom types to the metadata.
56	pub custom: CustomMetadata<PortableForm>,
57}
58
59impl RuntimeMetadataV16 {
60	/// Create a new instance of [`RuntimeMetadataV16`].
61	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/// Metadata of a runtime trait.
87#[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	/// Trait name.
96	pub name: T::String,
97	/// Trait methods.
98	pub methods: Vec<RuntimeApiMethodMetadata<T>>,
99	/// Trait documentation.
100	pub docs: Vec<T::String>,
101	/// Deprecation info.
102	pub deprecation_info: DeprecationStatus<T>,
103	/// Runtime API version.
104	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/// Metadata of a runtime method.
122#[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	/// Method name.
131	pub name: T::String,
132	/// Method parameters.
133	pub inputs: Vec<RuntimeApiMethodParamMetadata<T>>,
134	/// Method output.
135	pub output: T::Type,
136	/// Method documentation.
137	pub docs: Vec<T::String>,
138	/// Deprecation info
139	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/// Metadata of a runtime method parameter.
157#[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	/// Parameter name.
166	pub name: T::String,
167	/// Parameter type.
168	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/// Metadata of the extrinsic used by the runtime.
183#[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	/// Extrinsic versions supported by the runtime.
192	pub versions: Vec<u8>,
193	/// The type of the address that signs the extrinsic
194	pub address_ty: T::Type,
195	/// The type of the extrinsic's signature.
196	pub signature_ty: T::Type,
197	/// A mapping of supported transaction extrinsic versions to their respective transaction extension indexes.
198	///
199	/// For each supported version number, list the indexes, in order, of the extensions used.
200	pub transaction_extensions_by_version: BTreeMap<u8, Vec<u32>>,
201	/// The transaction extensions in the order they appear in the extrinsic.
202	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/// Metadata of an extrinsic's transaction extension.
220#[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	/// The unique transaction extension identifier, which may be different from the type name.
229	pub identifier: T::String,
230	/// The type of the transaction extension, with the data to be included in the extrinsic.
231	pub ty: T::Type,
232	/// The type of the implicit data, with the data to be included in the signed payload.
233	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/// All metadata about an runtime pallet.
249#[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	/// Pallet name.
258	pub name: T::String,
259	/// Pallet storage metadata.
260	pub storage: Option<PalletStorageMetadata<T>>,
261	/// Pallet calls metadata.
262	pub calls: Option<PalletCallMetadata<T>>,
263	/// Pallet event metadata.
264	pub event: Option<PalletEventMetadata<T>>,
265	/// Pallet constants metadata.
266	pub constants: Vec<PalletConstantMetadata<T>>,
267	/// Pallet error metadata.
268	pub error: Option<PalletErrorMetadata<T>>,
269	/// Config's trait associated types.
270	pub associated_types: Vec<PalletAssociatedTypeMetadata<T>>,
271	/// Pallet view functions metadata.
272	pub view_functions: Vec<PalletViewFunctionMetadata<T>>,
273	/// Define the index of the pallet, this index will be used for the encoding of pallet event,
274	/// call and origin variants.
275	pub index: u8,
276	/// Pallet documentation.
277	pub docs: Vec<T::String>,
278	/// Deprecation info
279	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/// Metadata for all calls in a pallet
303#[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	/// The corresponding enum type for the pallet call.
312	pub ty: T::Type,
313	/// Deprecation status of the pallet call
314	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/// All metadata of the pallet's storage.
329#[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	/// The common prefix used by all storage entries.
338	pub prefix: T::String,
339	/// Metadata for all storage entries.
340	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/// Metadata about one storage entry.
355#[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	/// Variable name of the storage entry.
364	pub name: T::String,
365	/// An `Option` modifier of that storage entry.
366	pub modifier: StorageEntryModifier,
367	/// Type of the value stored in the entry.
368	pub ty: StorageEntryType<T>,
369	/// Default value (SCALE encoded).
370	pub default: Vec<u8>,
371	/// Storage entry documentation.
372	pub docs: Vec<T::String>,
373	/// Deprecation info
374	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/// Metadata about the pallet Event type.
393#[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	/// The Event type.
402	pub ty: T::Type,
403	/// Deprecation info
404	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/// Metadata about one pallet constant.
419#[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	/// Name of the pallet constant.
428	pub name: T::String,
429	/// Type of the pallet constant.
430	pub ty: T::Type,
431	/// Value stored in the constant (SCALE encoded).
432	pub value: Vec<u8>,
433	/// Documentation of the constant.
434	pub docs: Vec<T::String>,
435	/// Deprecation info
436	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/// Metadata about a pallet error.
454#[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	/// The error type information.
463	pub ty: T::Type,
464	/// Deprecation info
465	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/// Metadata of a pallet's associated type.
480#[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	/// The name of the associated type.
489	pub name: T::String,
490	/// The type of the associated type.
491	pub ty: T::Type,
492	/// The documentation of the associated type.
493	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/// Metadata about a pallet view function.
509#[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	/// Method name.
518	pub name: T::String,
519	/// Method id.
520	pub id: [u8; 32],
521	/// Method parameters.
522	pub inputs: Vec<PalletViewFunctionParamMetadata<T>>,
523	/// Method output.
524	pub output: T::Type,
525	/// Method documentation.
526	pub docs: Vec<T::String>,
527	/// Deprecation info
528	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/// Metadata of a runtime view function parameter.
547#[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	/// Parameter name.
556	pub name: T::String,
557	/// Parameter type.
558	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/// Metadata for custom types.
573///
574/// This map associates a string key to a `CustomValueMetadata`.
575#[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	/// The custom map.
584	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/// The associated value of a custom metadata type.
602#[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	/// The custom type.
611	pub ty: T::Type,
612	/// The custom value of this type.
613	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/// The type of the outer enums.
628#[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	/// The type of the outer `RuntimeCall` enum.
637	pub call_enum_ty: T::Type,
638	/// The type of the outer `RuntimeEvent` enum.
639	pub event_enum_ty: T::Type,
640	/// The module error type of the
641	/// [`DispatchError::Module`](https://docs.rs/sp-runtime/24.0.0/sp_runtime/enum.DispatchError.html#variant.Module) variant.
642	///
643	/// The `Module` variant will be 5 scale encoded bytes which are normally decoded into
644	/// an `{ index: u8, error: [u8; 4] }` struct. This type ID points to an enum type which instead
645	/// interprets the first `index` byte as a pallet variant, and the remaining `error` bytes as the
646	/// appropriate `pallet::Error` type. It is an equally valid way to decode the error bytes, and
647	/// can be more informative.
648	///
649	/// # Note
650	///
651	/// - This type cannot be used directly to decode `sp_runtime::DispatchError` from the
652	///   chain. It provides just the information needed to decode `sp_runtime::DispatchError::Module`.
653	/// - Decoding the 5 error bytes into this type will not always lead to all of the bytes being consumed;
654	///   many error types do not require all of the bytes to represent them fully.
655	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/// Deprecation status for an entry inside the metadata.
671#[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	/// Entry is not deprecated
680	NotDeprecated,
681	/// Deprecated without a note.
682	DeprecatedWithoutNote,
683	/// Entry is deprecated with an note and an optional `since` field.
684	Deprecated {
685		/// Note explaining the deprecation
686		note: T::String,
687		/// Optional value for denoting version when the deprecation occurred.
688		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/// Deprecation info for an enums/errors/calls.
707/// Denotes full/partial deprecation of the type
708#[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	/// Type is not deprecated
717	NotDeprecated,
718	/// Entry is fully deprecated.
719	ItemDeprecated(DeprecationStatus<T>),
720	/// Entry is partially deprecated.
721	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}