Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Prev Previous commit
Next Next commit
expose in pallet_prelude
  • Loading branch information
shawntabrizi committed Jun 12, 2021
commit 989d02bab7f4d8433443a70837896dead9d2290e
2 changes: 2 additions & 0 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub use self::storage::{
StorageValue, StorageMap, StorageDoubleMap, StorageNMap, StoragePrefixedMap,
IterableStorageMap, IterableStorageDoubleMap, IterableStorageNMap, migration,
bounded_vec::{BoundedVec, BoundedSlice}, weak_bounded_vec::WeakBoundedVec,
counted_map::CountedStorageMap,
};
pub use self::dispatch::{Parameter, Callable};
pub use sp_runtime::{self, ConsensusEngineId, print, traits::Printable};
Expand Down Expand Up @@ -1248,6 +1249,7 @@ pub mod pallet_prelude {
OptionQuery,
},
storage::bounded_vec::BoundedVec,
CountedStorageMap,
};
pub use codec::{Encode, Decode};
pub use crate::inherent::{InherentData, InherentIdentifier, ProvideInherent};
Expand Down
7 changes: 7 additions & 0 deletions frame/support/src/storage/counted_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,16 @@ where
///
/// This function iterates through all the items in the map and sets the counter. This operation
/// can be very heavy, so use with caution.
///
/// Returns the number of items in the map which is used to set the counter.
pub fn initialize_counter() -> u32 {
let count = Self::iter_values().count() as u32;
Counter::set(count);
count
}

/// Return the count.
pub fn count() -> u32 {
Counter::get()
}
}