referrerpolicy=no-referrer-when-downgrade

frame_support_procedural/construct_runtime/expand/
hold_reason.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
18use super::composite_helper;
19use crate::construct_runtime::Pallet;
20use proc_macro2::TokenStream;
21use quote::quote;
22
23pub fn expand_outer_hold_reason(pallet_decls: &[Pallet], scrate: &TokenStream) -> TokenStream {
24	let mut conversion_fns = Vec::new();
25	let mut hold_reason_variants = Vec::new();
26	let mut hold_reason_variants_count = Vec::new();
27	for decl in pallet_decls {
28		if let Some(_) = decl.find_part("HoldReason") {
29			let variant_name = &decl.name;
30			let path = &decl.path;
31			let index = decl.index;
32			let instance = decl.instance.as_ref();
33
34			conversion_fns.push(composite_helper::expand_conversion_fn(
35				"HoldReason",
36				path,
37				instance,
38				variant_name,
39			));
40
41			hold_reason_variants.push(composite_helper::expand_variant(
42				"HoldReason",
43				index,
44				path,
45				instance,
46				variant_name,
47			));
48
49			hold_reason_variants_count.push(composite_helper::expand_variant_count(
50				"HoldReason",
51				path,
52				instance,
53			));
54		}
55	}
56
57	quote! {
58		/// A reason for placing a hold on funds.
59		#[derive(
60			Copy, Clone, Eq, PartialEq,
61			#scrate::__private::codec::Encode,
62			#scrate::__private::codec::Decode,
63			#scrate::__private::codec::DecodeWithMemTracking,
64			#scrate::__private::codec::MaxEncodedLen,
65			#scrate::__private::scale_info::TypeInfo,
66			#scrate::__private::RuntimeDebug,
67		)]
68		pub enum RuntimeHoldReason {
69			#( #hold_reason_variants )*
70		}
71
72		impl #scrate::traits::VariantCount for RuntimeHoldReason {
73			const VARIANT_COUNT: u32 = 0 #( + #hold_reason_variants_count )*;
74		}
75
76		#( #conversion_fns )*
77	}
78}