Skip to content

Commit f0d85ac

Browse files
committed
cargo fmt --all
1 parent b4b7175 commit f0d85ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+14810
-13920
lines changed

support/procedural-fork/src/benchmark.rs

Lines changed: 1097 additions & 1020 deletions
Large diffs are not rendered by default.

support/procedural-fork/src/construct_runtime/expand/call.rs

Lines changed: 198 additions & 195 deletions
Large diffs are not rendered by default.

support/procedural-fork/src/construct_runtime/expand/composite_helper.rs

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -20,82 +20,82 @@ use proc_macro2::{Ident, TokenStream};
2020
use quote::quote;
2121

2222
pub(crate) fn expand_conversion_fn(
23-
composite_name: &str,
24-
path: &PalletPath,
25-
instance: Option<&Ident>,
26-
variant_name: &Ident,
23+
composite_name: &str,
24+
path: &PalletPath,
25+
instance: Option<&Ident>,
26+
variant_name: &Ident,
2727
) -> TokenStream {
28-
let composite_name = quote::format_ident!("{}", composite_name);
29-
let runtime_composite_name = quote::format_ident!("Runtime{}", composite_name);
28+
let composite_name = quote::format_ident!("{}", composite_name);
29+
let runtime_composite_name = quote::format_ident!("Runtime{}", composite_name);
3030

31-
if let Some(inst) = instance {
32-
quote! {
33-
impl From<#path::#composite_name<#path::#inst>> for #runtime_composite_name {
34-
fn from(hr: #path::#composite_name<#path::#inst>) -> Self {
35-
#runtime_composite_name::#variant_name(hr)
36-
}
37-
}
38-
}
39-
} else {
40-
quote! {
41-
impl From<#path::#composite_name> for #runtime_composite_name {
42-
fn from(hr: #path::#composite_name) -> Self {
43-
#runtime_composite_name::#variant_name(hr)
44-
}
45-
}
46-
}
47-
}
31+
if let Some(inst) = instance {
32+
quote! {
33+
impl From<#path::#composite_name<#path::#inst>> for #runtime_composite_name {
34+
fn from(hr: #path::#composite_name<#path::#inst>) -> Self {
35+
#runtime_composite_name::#variant_name(hr)
36+
}
37+
}
38+
}
39+
} else {
40+
quote! {
41+
impl From<#path::#composite_name> for #runtime_composite_name {
42+
fn from(hr: #path::#composite_name) -> Self {
43+
#runtime_composite_name::#variant_name(hr)
44+
}
45+
}
46+
}
47+
}
4848
}
4949

5050
pub(crate) fn expand_variant(
51-
composite_name: &str,
52-
index: u8,
53-
path: &PalletPath,
54-
instance: Option<&Ident>,
55-
variant_name: &Ident,
51+
composite_name: &str,
52+
index: u8,
53+
path: &PalletPath,
54+
instance: Option<&Ident>,
55+
variant_name: &Ident,
5656
) -> TokenStream {
57-
let composite_name = quote::format_ident!("{}", composite_name);
57+
let composite_name = quote::format_ident!("{}", composite_name);
5858

59-
if let Some(inst) = instance {
60-
quote! {
61-
#[codec(index = #index)]
62-
#variant_name(#path::#composite_name<#path::#inst>),
63-
}
64-
} else {
65-
quote! {
66-
#[codec(index = #index)]
67-
#variant_name(#path::#composite_name),
68-
}
69-
}
59+
if let Some(inst) = instance {
60+
quote! {
61+
#[codec(index = #index)]
62+
#variant_name(#path::#composite_name<#path::#inst>),
63+
}
64+
} else {
65+
quote! {
66+
#[codec(index = #index)]
67+
#variant_name(#path::#composite_name),
68+
}
69+
}
7070
}
7171

7272
pub(crate) fn expand_variant_count(
73-
composite_name: &str,
74-
path: &PalletPath,
75-
instance: Option<&Ident>,
73+
composite_name: &str,
74+
path: &PalletPath,
75+
instance: Option<&Ident>,
7676
) -> TokenStream {
77-
let composite_name = quote::format_ident!("{}", composite_name);
77+
let composite_name = quote::format_ident!("{}", composite_name);
7878

79-
if let Some(inst) = instance {
80-
quote! {
81-
#path::#composite_name::<#path::#inst>::VARIANT_COUNT
82-
}
83-
} else {
84-
// Wrapped `<`..`>` means: use default type parameter for enum.
85-
//
86-
// This is used for pallets without instance support or pallets with instance support when
87-
// we don't specify instance:
88-
//
89-
// ```
90-
// pub struct Pallet<T, I = ()>{..}
91-
//
92-
// #[pallet::composite_enum]
93-
// pub enum HoldReason<I: 'static = ()> {..}
94-
//
95-
// Pallet1: pallet_x, // <- default type parameter
96-
// ```
97-
quote! {
98-
<#path::#composite_name>::VARIANT_COUNT
99-
}
100-
}
79+
if let Some(inst) = instance {
80+
quote! {
81+
#path::#composite_name::<#path::#inst>::VARIANT_COUNT
82+
}
83+
} else {
84+
// Wrapped `<`..`>` means: use default type parameter for enum.
85+
//
86+
// This is used for pallets without instance support or pallets with instance support when
87+
// we don't specify instance:
88+
//
89+
// ```
90+
// pub struct Pallet<T, I = ()>{..}
91+
//
92+
// #[pallet::composite_enum]
93+
// pub enum HoldReason<I: 'static = ()> {..}
94+
//
95+
// Pallet1: pallet_x, // <- default type parameter
96+
// ```
97+
quote! {
98+
<#path::#composite_name>::VARIANT_COUNT
99+
}
100+
}
101101
}

support/procedural-fork/src/construct_runtime/expand/config.rs

Lines changed: 109 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -23,125 +23,135 @@ use std::str::FromStr;
2323
use syn::Ident;
2424

2525
pub fn expand_outer_config(
26-
runtime: &Ident,
27-
pallet_decls: &[Pallet],
28-
scrate: &TokenStream,
26+
runtime: &Ident,
27+
pallet_decls: &[Pallet],
28+
scrate: &TokenStream,
2929
) -> TokenStream {
30-
let mut types = TokenStream::new();
31-
let mut fields = TokenStream::new();
32-
let mut genesis_build_calls = TokenStream::new();
33-
let mut query_genesis_config_part_macros = Vec::new();
30+
let mut types = TokenStream::new();
31+
let mut fields = TokenStream::new();
32+
let mut genesis_build_calls = TokenStream::new();
33+
let mut query_genesis_config_part_macros = Vec::new();
3434

35-
for decl in pallet_decls {
36-
if let Some(pallet_entry) = decl.find_part("Config") {
37-
let path = &decl.path;
38-
let pallet_name = &decl.name;
39-
let path_str = path.into_token_stream().to_string();
40-
let config = format_ident!("{}Config", pallet_name);
41-
let field_name =
42-
&Ident::new(&pallet_name.to_string().to_snake_case(), decl.name.span());
43-
let part_is_generic = !pallet_entry.generics.params.is_empty();
44-
let attr = &decl.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| {
45-
let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original()))
46-
.expect("was successfully parsed before; qed");
47-
quote! {
48-
#acc
49-
#attr
50-
}
51-
});
35+
for decl in pallet_decls {
36+
if let Some(pallet_entry) = decl.find_part("Config") {
37+
let path = &decl.path;
38+
let pallet_name = &decl.name;
39+
let path_str = path.into_token_stream().to_string();
40+
let config = format_ident!("{}Config", pallet_name);
41+
let field_name =
42+
&Ident::new(&pallet_name.to_string().to_snake_case(), decl.name.span());
43+
let part_is_generic = !pallet_entry.generics.params.is_empty();
44+
let attr = &decl
45+
.cfg_pattern
46+
.iter()
47+
.fold(TokenStream::new(), |acc, pattern| {
48+
let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original()))
49+
.expect("was successfully parsed before; qed");
50+
quote! {
51+
#acc
52+
#attr
53+
}
54+
});
5255

53-
types.extend(expand_config_types(attr, runtime, decl, &config, part_is_generic));
54-
fields.extend(quote!(#attr pub #field_name: #config,));
55-
genesis_build_calls
56-
.extend(expand_config_build_storage_call(scrate, &config, attr, field_name));
57-
query_genesis_config_part_macros.push(quote! {
56+
types.extend(expand_config_types(
57+
attr,
58+
runtime,
59+
decl,
60+
&config,
61+
part_is_generic,
62+
));
63+
fields.extend(quote!(#attr pub #field_name: #config,));
64+
genesis_build_calls.extend(expand_config_build_storage_call(
65+
scrate, &config, attr, field_name,
66+
));
67+
query_genesis_config_part_macros.push(quote! {
5868
#path::__substrate_genesis_config_check::is_genesis_config_defined!(#pallet_name);
5969
#[cfg(feature = "std")]
6070
#path::__substrate_genesis_config_check::is_std_enabled_for_genesis!(#pallet_name, #path_str);
6171
});
62-
}
63-
}
72+
}
73+
}
6474

65-
quote! {
66-
#( #query_genesis_config_part_macros )*
75+
quote! {
76+
#( #query_genesis_config_part_macros )*
6777

68-
#types
78+
#types
6979

70-
use #scrate::__private::serde as __genesis_config_serde_import__;
71-
#[derive(#scrate::__private::serde::Serialize, #scrate::__private::serde::Deserialize, Default)]
72-
#[serde(rename_all = "camelCase")]
73-
#[serde(deny_unknown_fields)]
74-
#[serde(crate = "__genesis_config_serde_import__")]
75-
pub struct RuntimeGenesisConfig {
76-
#fields
77-
}
80+
use #scrate::__private::serde as __genesis_config_serde_import__;
81+
#[derive(#scrate::__private::serde::Serialize, #scrate::__private::serde::Deserialize, Default)]
82+
#[serde(rename_all = "camelCase")]
83+
#[serde(deny_unknown_fields)]
84+
#[serde(crate = "__genesis_config_serde_import__")]
85+
pub struct RuntimeGenesisConfig {
86+
#fields
87+
}
7888

79-
#[cfg(any(feature = "std", test))]
80-
impl #scrate::sp_runtime::BuildStorage for RuntimeGenesisConfig {
81-
fn assimilate_storage(
82-
&self,
83-
storage: &mut #scrate::sp_runtime::Storage,
84-
) -> std::result::Result<(), String> {
85-
#scrate::__private::BasicExternalities::execute_with_storage(storage, || {
86-
<Self as #scrate::traits::BuildGenesisConfig>::build(&self);
87-
Ok(())
88-
})
89-
}
90-
}
89+
#[cfg(any(feature = "std", test))]
90+
impl #scrate::sp_runtime::BuildStorage for RuntimeGenesisConfig {
91+
fn assimilate_storage(
92+
&self,
93+
storage: &mut #scrate::sp_runtime::Storage,
94+
) -> std::result::Result<(), String> {
95+
#scrate::__private::BasicExternalities::execute_with_storage(storage, || {
96+
<Self as #scrate::traits::BuildGenesisConfig>::build(&self);
97+
Ok(())
98+
})
99+
}
100+
}
91101

92-
impl #scrate::traits::BuildGenesisConfig for RuntimeGenesisConfig {
93-
fn build(&self) {
94-
#genesis_build_calls
95-
<AllPalletsWithSystem as #scrate::traits::OnGenesis>::on_genesis();
96-
}
97-
}
102+
impl #scrate::traits::BuildGenesisConfig for RuntimeGenesisConfig {
103+
fn build(&self) {
104+
#genesis_build_calls
105+
<AllPalletsWithSystem as #scrate::traits::OnGenesis>::on_genesis();
106+
}
107+
}
98108

99-
/// Test the `Default` derive impl of the `RuntimeGenesisConfig`.
100-
#[cfg(test)]
101-
#[test]
102-
fn test_genesis_config_builds() {
103-
#scrate::__private::sp_io::TestExternalities::default().execute_with(|| {
104-
<RuntimeGenesisConfig as #scrate::traits::BuildGenesisConfig>::build(
105-
&RuntimeGenesisConfig::default()
106-
);
107-
});
108-
}
109-
}
109+
/// Test the `Default` derive impl of the `RuntimeGenesisConfig`.
110+
#[cfg(test)]
111+
#[test]
112+
fn test_genesis_config_builds() {
113+
#scrate::__private::sp_io::TestExternalities::default().execute_with(|| {
114+
<RuntimeGenesisConfig as #scrate::traits::BuildGenesisConfig>::build(
115+
&RuntimeGenesisConfig::default()
116+
);
117+
});
118+
}
119+
}
110120
}
111121

112122
fn expand_config_types(
113-
attr: &TokenStream,
114-
runtime: &Ident,
115-
decl: &Pallet,
116-
config: &Ident,
117-
part_is_generic: bool,
123+
attr: &TokenStream,
124+
runtime: &Ident,
125+
decl: &Pallet,
126+
config: &Ident,
127+
part_is_generic: bool,
118128
) -> TokenStream {
119-
let path = &decl.path;
129+
let path = &decl.path;
120130

121-
match (decl.instance.as_ref(), part_is_generic) {
122-
(Some(inst), true) => quote! {
123-
#attr
124-
pub type #config = #path::GenesisConfig<#runtime, #path::#inst>;
125-
},
126-
(None, true) => quote! {
127-
#attr
128-
pub type #config = #path::GenesisConfig<#runtime>;
129-
},
130-
(_, false) => quote! {
131-
#attr
132-
pub type #config = #path::GenesisConfig;
133-
},
134-
}
131+
match (decl.instance.as_ref(), part_is_generic) {
132+
(Some(inst), true) => quote! {
133+
#attr
134+
pub type #config = #path::GenesisConfig<#runtime, #path::#inst>;
135+
},
136+
(None, true) => quote! {
137+
#attr
138+
pub type #config = #path::GenesisConfig<#runtime>;
139+
},
140+
(_, false) => quote! {
141+
#attr
142+
pub type #config = #path::GenesisConfig;
143+
},
144+
}
135145
}
136146

137147
fn expand_config_build_storage_call(
138-
scrate: &TokenStream,
139-
pallet_genesis_config: &Ident,
140-
attr: &TokenStream,
141-
field_name: &Ident,
148+
scrate: &TokenStream,
149+
pallet_genesis_config: &Ident,
150+
attr: &TokenStream,
151+
field_name: &Ident,
142152
) -> TokenStream {
143-
quote! {
144-
#attr
145-
<#pallet_genesis_config as #scrate::traits::BuildGenesisConfig>::build(&self.#field_name);
146-
}
153+
quote! {
154+
#attr
155+
<#pallet_genesis_config as #scrate::traits::BuildGenesisConfig>::build(&self.#field_name);
156+
}
147157
}

0 commit comments

Comments
 (0)