sp_metadata_ir/
v15.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Convert the IR to V15 metadata.
19
20use 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};
30
31impl From<MetadataIR> for RuntimeMetadataV15 {
32	fn from(ir: MetadataIR) -> Self {
33		RuntimeMetadataV15::new(
34			ir.pallets.into_iter().map(Into::into).collect(),
35			ir.extrinsic.into(),
36			ir.ty,
37			ir.apis.into_iter().map(Into::into).collect(),
38			ir.outer_enums.into(),
39			CustomMetadata { map: Default::default() },
40		)
41	}
42}
43
44impl From<RuntimeApiMetadataIR> for RuntimeApiMetadata {
45	fn from(ir: RuntimeApiMetadataIR) -> Self {
46		RuntimeApiMetadata {
47			name: ir.name,
48			methods: ir.methods.into_iter().map(Into::into).collect(),
49			docs: ir.docs,
50		}
51	}
52}
53
54impl From<RuntimeApiMethodMetadataIR> for RuntimeApiMethodMetadata {
55	fn from(ir: RuntimeApiMethodMetadataIR) -> Self {
56		RuntimeApiMethodMetadata {
57			name: ir.name,
58			inputs: ir.inputs.into_iter().map(Into::into).collect(),
59			output: ir.output,
60			docs: ir.docs,
61		}
62	}
63}
64
65impl From<RuntimeApiMethodParamMetadataIR> for RuntimeApiMethodParamMetadata {
66	fn from(ir: RuntimeApiMethodParamMetadataIR) -> Self {
67		RuntimeApiMethodParamMetadata { name: ir.name, ty: ir.ty }
68	}
69}
70
71impl From<PalletMetadataIR> for PalletMetadata {
72	fn from(ir: PalletMetadataIR) -> Self {
73		PalletMetadata {
74			name: ir.name,
75			storage: ir.storage.map(Into::into),
76			calls: ir.calls.map(Into::into),
77			event: ir.event.map(Into::into),
78			constants: ir.constants.into_iter().map(Into::into).collect(),
79			error: ir.error.map(Into::into),
80			index: ir.index,
81			docs: ir.docs,
82		}
83	}
84}
85
86impl From<TransactionExtensionMetadataIR> for SignedExtensionMetadata {
87	fn from(ir: TransactionExtensionMetadataIR) -> Self {
88		SignedExtensionMetadata {
89			identifier: ir.identifier,
90			ty: ir.ty,
91			additional_signed: ir.implicit,
92		}
93	}
94}
95
96impl From<ExtrinsicMetadataIR> for ExtrinsicMetadata {
97	fn from(ir: ExtrinsicMetadataIR) -> Self {
98		ExtrinsicMetadata {
99			version: *ir.versions.iter().min().expect("Metadata V15 supports only one version"),
100			address_ty: ir.address_ty,
101			call_ty: ir.call_ty,
102			signature_ty: ir.signature_ty,
103			extra_ty: ir.extra_ty,
104			signed_extensions: ir.extensions.into_iter().map(Into::into).collect(),
105		}
106	}
107}
108
109impl From<OuterEnumsIR> for OuterEnums {
110	fn from(ir: OuterEnumsIR) -> Self {
111		OuterEnums {
112			call_enum_ty: ir.call_enum_ty,
113			event_enum_ty: ir.event_enum_ty,
114			error_enum_ty: ir.error_enum_ty,
115		}
116	}
117}