referrerpolicy=no-referrer-when-downgrade

frame_support_procedural/construct_runtime/expand/
slash_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_slash_reason(pallet_decls: &[Pallet], scrate: &TokenStream) -> TokenStream {
24	let mut conversion_fns = Vec::new();
25	let mut slash_reason_variants = Vec::new();
26	for decl in pallet_decls {
27		if let Some(_) = decl.find_part("SlashReason") {
28			let variant_name = &decl.name;
29			let path = &decl.path;
30			let index = decl.index;
31			let instance = decl.instance.as_ref();
32
33			conversion_fns.push(composite_helper::expand_conversion_fn(
34				"SlashReason",
35				path,
36				instance,
37				variant_name,
38			));
39
40			slash_reason_variants.push(composite_helper::expand_variant(
41				"SlashReason",
42				index,
43				path,
44				instance,
45				variant_name,
46			));
47		}
48	}
49
50	quote! {
51		/// A reason for slashing funds.
52		#[derive(
53			Copy, Clone, Eq, PartialEq,
54			#scrate::__private::codec::Encode,
55			#scrate::__private::codec::Decode,
56			#scrate::__private::codec::DecodeWithMemTracking,
57			#scrate::__private::codec::MaxEncodedLen,
58			#scrate::__private::scale_info::TypeInfo,
59			#scrate::__private::RuntimeDebug,
60		)]
61		pub enum RuntimeSlashReason {
62			#( #slash_reason_variants )*
63		}
64
65		#( #conversion_fns )*
66	}
67}