mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 11:38:01 +00:00
Proposal: Flatten AllPallets and similar types (#11813)
* flratten AllPallets types * feature flag it * fix * fix * fmt * remove todo * Update frame/support/src/traits/metadata.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update frame/support/src/migrations.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * fix * mark as deprecated * add docs * fix ui test? * fmt Co-authored-by: parity-processbot <> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -308,47 +308,26 @@ fn decl_all_pallets<'a>(
|
||||
names.push(&pallet_declaration.name);
|
||||
}
|
||||
|
||||
// Make nested tuple structure like:
|
||||
// `((FirstPallet, (SecondPallet, ( ... , LastPallet) ... ))))`
|
||||
// But ignore the system pallet.
|
||||
let all_pallets_without_system = names
|
||||
.iter()
|
||||
.filter(|n| **n != SYSTEM_PALLET_NAME)
|
||||
.rev()
|
||||
.fold(TokenStream2::default(), |combined, name| quote!((#name, #combined)));
|
||||
|
||||
// Make nested tuple structure like:
|
||||
// `((FirstPallet, (SecondPallet, ( ... , LastPallet) ... ))))`
|
||||
let all_pallets_with_system = names
|
||||
.iter()
|
||||
.rev()
|
||||
.fold(TokenStream2::default(), |combined, name| quote!((#name, #combined)));
|
||||
|
||||
// Make nested tuple structure like:
|
||||
// `((LastPallet, (SecondLastPallet, ( ... , FirstPallet) ... ))))`
|
||||
// But ignore the system pallet.
|
||||
let all_pallets_without_system_reversed = names
|
||||
.iter()
|
||||
.filter(|n| **n != SYSTEM_PALLET_NAME)
|
||||
.fold(TokenStream2::default(), |combined, name| quote!((#name, #combined)));
|
||||
|
||||
// Make nested tuple structure like:
|
||||
// `((LastPallet, (SecondLastPallet, ( ... , FirstPallet) ... ))))`
|
||||
let all_pallets_with_system_reversed = names
|
||||
.iter()
|
||||
.fold(TokenStream2::default(), |combined, name| quote!((#name, #combined)));
|
||||
|
||||
let system_pallet = match names.iter().find(|n| **n == SYSTEM_PALLET_NAME) {
|
||||
Some(name) => name,
|
||||
None =>
|
||||
return syn::Error::new(
|
||||
proc_macro2::Span::call_site(),
|
||||
"`System` pallet declaration is missing. \
|
||||
Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event<T>},`",
|
||||
Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event<T>},`",
|
||||
)
|
||||
.into_compile_error(),
|
||||
};
|
||||
|
||||
let names_without_system =
|
||||
names.iter().filter(|n| **n != SYSTEM_PALLET_NAME).collect::<Vec<_>>();
|
||||
let names_reversed = names.clone().into_iter().rev().collect::<Vec<_>>();
|
||||
let names_without_system_reverse =
|
||||
names_without_system.clone().into_iter().rev().collect::<Vec<_>>();
|
||||
let names_reversed_with_system_first = std::iter::once(system_pallet)
|
||||
.chain(names_without_system_reverse.clone().into_iter())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
quote!(
|
||||
#types
|
||||
|
||||
@@ -364,25 +343,28 @@ fn decl_all_pallets<'a>(
|
||||
pub type AllPallets = AllPalletsWithSystem;
|
||||
|
||||
/// All pallets included in the runtime as a nested tuple of types.
|
||||
pub type AllPalletsWithSystem = ( #all_pallets_with_system );
|
||||
pub type AllPalletsWithSystem = ( #(#names),* );
|
||||
|
||||
/// All pallets included in the runtime as a nested tuple of types.
|
||||
/// Excludes the System pallet.
|
||||
pub type AllPalletsWithoutSystem = ( #all_pallets_without_system );
|
||||
pub type AllPalletsWithoutSystem = ( #(#names_without_system),* );
|
||||
|
||||
/// All pallets included in the runtime as a nested tuple of types in reversed order.
|
||||
/// Excludes the System pallet.
|
||||
pub type AllPalletsWithoutSystemReversed = ( #all_pallets_without_system_reversed );
|
||||
#[deprecated(note = "Using reverse pallet orders is deprecated. use only \
|
||||
`AllPalletWithSystem or AllPalletsWithoutSystem`")]
|
||||
pub type AllPalletsWithoutSystemReversed =( #(#names_without_system_reverse),* );
|
||||
|
||||
/// All pallets included in the runtime as a nested tuple of types in reversed order.
|
||||
pub type AllPalletsWithSystemReversed = ( #all_pallets_with_system_reversed );
|
||||
#[deprecated(note = "Using reverse pallet orders is deprecated. use only \
|
||||
`AllPalletWithSystem or AllPalletsWithoutSystem`")]
|
||||
pub type AllPalletsWithSystemReversed = ( #(#names_reversed),* );
|
||||
|
||||
/// All pallets included in the runtime as a nested tuple of types in reversed order.
|
||||
/// With the system pallet first.
|
||||
pub type AllPalletsReversedWithSystemFirst = (
|
||||
#system_pallet,
|
||||
AllPalletsWithoutSystemReversed
|
||||
);
|
||||
#[deprecated(note = "Using reverse pallet orders is deprecated. use only \
|
||||
`AllPalletWithSystem or AllPalletsWithoutSystem`")]
|
||||
pub type AllPalletsReversedWithSystemFirst = ( #(#names_reversed_with_system_first),* );
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -240,9 +240,7 @@ pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
#config_where_clause
|
||||
{
|
||||
fn count() -> usize { 1 }
|
||||
fn accumulate(
|
||||
acc: &mut #frame_support::sp_std::vec::Vec<#frame_support::traits::PalletInfoData>
|
||||
) {
|
||||
fn infos() -> #frame_support::sp_std::vec::Vec<#frame_support::traits::PalletInfoData> {
|
||||
use #frame_support::traits::PalletInfoAccess;
|
||||
let item = #frame_support::traits::PalletInfoData {
|
||||
index: Self::index(),
|
||||
@@ -250,7 +248,7 @@ pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
module_name: Self::module_name(),
|
||||
crate_version: Self::crate_version(),
|
||||
};
|
||||
acc.push(item);
|
||||
#frame_support::sp_std::vec![item]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user