frame_support_procedural/construct_runtime/expand/
unsigned.rs
1use crate::construct_runtime::Pallet;
19use proc_macro2::TokenStream;
20use quote::quote;
21use syn::Ident;
22
23pub fn expand_outer_validate_unsigned(
24 runtime: &Ident,
25 pallet_decls: &[Pallet],
26 scrate: &TokenStream,
27) -> TokenStream {
28 let mut pallet_names = Vec::new();
29 let mut pallet_attrs = Vec::new();
30 let mut query_validate_unsigned_part_macros = Vec::new();
31
32 for pallet_decl in pallet_decls {
33 if pallet_decl.exists_part("ValidateUnsigned") {
34 let name = &pallet_decl.name;
35 let path = &pallet_decl.path;
36 let attr = pallet_decl.get_attributes();
37
38 pallet_names.push(name);
39 pallet_attrs.push(attr);
40 query_validate_unsigned_part_macros.push(quote! {
41 #path::__substrate_validate_unsigned_check::is_validate_unsigned_part_defined!(#name);
42 });
43 }
44 }
45
46 quote! {
47 #( #query_validate_unsigned_part_macros )*
48
49 impl #scrate::unsigned::ValidateUnsigned for #runtime {
50 type Call = RuntimeCall;
51
52 fn pre_dispatch(call: &Self::Call) -> Result<(), #scrate::unsigned::TransactionValidityError> {
53 #[allow(unreachable_patterns)]
54 match call {
55 #(
56 #pallet_attrs
57 RuntimeCall::#pallet_names(inner_call) => #pallet_names::pre_dispatch(inner_call),
58 )*
59 _ => Ok(()),
62 }
63 }
64
65 fn validate_unsigned(
66 #[allow(unused_variables)]
67 source: #scrate::unsigned::TransactionSource,
68 call: &Self::Call,
69 ) -> #scrate::unsigned::TransactionValidity {
70 #[allow(unreachable_patterns)]
71 match call {
72 #(
73 #pallet_attrs
74 RuntimeCall::#pallet_names(inner_call) => #pallet_names::validate_unsigned(source, inner_call),
75 )*
76 _ => #scrate::unsigned::UnknownTransaction::NoUnsignedValidator.into(),
77 }
78 }
79 }
80 }
81}