1// This file is part of Substrate.
23// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
56// 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
1718use super::composite_helper;
19use crate::construct_runtime::Pallet;
20use proc_macro2::TokenStream;
21use quote::quote;
2223pub fn expand_outer_slash_reason(pallet_decls: &[Pallet], scrate: &TokenStream) -> TokenStream {
24let mut conversion_fns = Vec::new();
25let mut slash_reason_variants = Vec::new();
26for decl in pallet_decls {
27if let Some(_) = decl.find_part("SlashReason") {
28let variant_name = &decl.name;
29let path = &decl.path;
30let index = decl.index;
31let instance = decl.instance.as_ref();
3233 conversion_fns.push(composite_helper::expand_conversion_fn(
34"SlashReason",
35 path,
36 instance,
37 variant_name,
38 ));
3940 slash_reason_variants.push(composite_helper::expand_variant(
41"SlashReason",
42 index,
43 path,
44 instance,
45 variant_name,
46 ));
47 }
48 }
4950quote! {
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 )]
61pub enum RuntimeSlashReason {
62 #( #slash_reason_variants )*
63 }
6465 #( #conversion_fns )*
66 }
67}