Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Prev Previous commit
Next Next commit
Fixes
  • Loading branch information
gavofyork committed Oct 20, 2021
commit f690e43e5d3ff7bda6d002ea272ee6432186b12d
3 changes: 2 additions & 1 deletion frame/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,8 @@ macro_rules! decl_module {
for $mod_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{
fn count() -> usize { 1 }
fn accumulate(acc: &mut $crate::traits::PalletInfoData) {
fn accumulate(acc: &mut Vec<$crate::traits::PalletInfoData>) {
use $crate::traits::PalletInfoAccess;
let item = $crate::traits::PalletInfoData {
index: Self::index(),
name: Self::name(),
Expand Down
7 changes: 3 additions & 4 deletions frame/support/src/traits/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//! Traits for managing information attached to pallets and their constituents.

use codec::{Decode, Encode};
use impl_trait_for_tuples::impl_for_tuples;
use sp_runtime::RuntimeDebug;
use sp_std::prelude::*;

Expand Down Expand Up @@ -80,8 +79,8 @@ pub trait PalletsInfoAccess {

/// All of the pallets' information that this type represents. Relevant for tuples.
fn infos() -> Vec<PalletInfoData> {
let mut result = Vec::with_capacity(Self::infos_len());
Self::accumulate_infos(&mut result);
let mut result = Vec::with_capacity(Self::count());
Self::accumulate(&mut result);
result
}
}
Expand All @@ -95,8 +94,8 @@ impl<T: PalletsInfoAccess> PalletsInfoAccess for (T,) {
impl<T1: PalletsInfoAccess, T2: PalletsInfoAccess> PalletsInfoAccess for (T1, T2) {
fn count() -> usize { T1::count() + T2::count() }
fn accumulate(acc: &mut Vec<PalletInfoData>) {
T1::accumulate(acc);
T2::accumulate(acc);
T1::accumulate(acc);
}
}

Expand Down
8 changes: 7 additions & 1 deletion frame/support/test/tests/pallet_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,18 @@ fn storage_expand() {

#[test]
fn pallet_metadata_expands() {
use frame_support::traits::{CrateVersion, PalletInfoAccess, PalletInfoData};
use frame_support::traits::{CrateVersion, PalletsInfoAccess, PalletInfoData};
let mut infos = AllPalletsWithSystem::infos();
infos.sort_by_key(|x| x.index);
assert_eq!(
infos,
vec![
PalletInfoData {
index: 0,
name: "System",
module_name: "frame_system",
crate_version: CrateVersion { major: 4, minor: 0, patch: 0 },
},
PalletInfoData {
index: 1,
name: "Example",
Expand Down