From 32e54838a0efff849083be5714525e5e33409279 Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Sun, 3 Jul 2022 21:52:25 +0200 Subject: [PATCH] ref: move IdtyDataIter in common runtime --- pallets/identity/src/lib.rs | 29 ---------------------- runtime/common/src/pallets_config.rs | 2 +- runtime/common/src/providers.rs | 36 +++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/pallets/identity/src/lib.rs b/pallets/identity/src/lib.rs index 1da429a4a..0cc9fc089 100644 --- a/pallets/identity/src/lib.rs +++ b/pallets/identity/src/lib.rs @@ -620,32 +620,3 @@ where Ok(result) } } - -pub struct IdtyDataIter<T: Config>( - Box<dyn Iterator<Item = IdtyValue<T::BlockNumber, T::AccountId, T::IdtyData>>>, -); - -impl<T: Config> From<Option<Vec<u8>>> for IdtyDataIter<T> { - fn from(maybe_key: Option<Vec<u8>>) -> Self { - let mut iter = Identities::<T>::iter_values(); - if let Some(key) = maybe_key { - iter.set_last_raw_key(key); - } - Self(Box::new(iter)) - } -} - -impl<T: Config> Iterator for IdtyDataIter<T> { - type Item = (T::AccountId, T::IdtyData); - - fn next(&mut self) -> Option<Self::Item> { - if let Some(IdtyValue { - owner_key, data, .. - }) = self.0.next() - { - Some((owner_key, data)) - } else { - None - } - } -} diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index be602e77d..eb599c40e 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -400,7 +400,7 @@ macro_rules! pallets_config { type MaxPastReeval = frame_support::traits::ConstU32<4>; type MembersCount = MembersCount; type MembersStorage = Identity; - type MembersStorageIter = pallet_identity::IdtyDataIter<Runtime>; + type MembersStorageIter = common_runtime::providers::IdtyDataIter<Runtime>; type SquareMoneyGrowthRate = SquareMoneyGrowthRate; type UdCreationPeriod = UdCreationPeriod; type UdReevalPeriod = UdReevalPeriod; diff --git a/runtime/common/src/providers.rs b/runtime/common/src/providers.rs index cddf467a9..193a9bd98 100644 --- a/runtime/common/src/providers.rs +++ b/runtime/common/src/providers.rs @@ -15,8 +15,11 @@ // along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. use crate::{AccountId, IdtyIndex}; +use core::marker::PhantomData; +use sp_std::boxed::Box; +use sp_std::vec::Vec; -pub struct IdentityAccountIdProvider<Runtime>(core::marker::PhantomData<Runtime>); +pub struct IdentityAccountIdProvider<Runtime>(PhantomData<Runtime>); impl< Runtime: frame_system::Config<AccountId = AccountId> @@ -28,3 +31,34 @@ impl< pallet_identity::Pallet::<Runtime>::identity(idty_index).map(|idty| idty.owner_key) } } + +#[allow(clippy::type_complexity)] +pub struct IdtyDataIter<T: pallet_identity::Config>( + Box<dyn Iterator<Item = pallet_identity::IdtyValue<T::BlockNumber, T::AccountId, T::IdtyData>>>, + PhantomData<T>, +); + +impl<T: pallet_identity::Config> From<Option<Vec<u8>>> for IdtyDataIter<T> { + fn from(maybe_key: Option<Vec<u8>>) -> Self { + let mut iter = pallet_identity::Identities::<T>::iter_values(); + if let Some(key) = maybe_key { + iter.set_last_raw_key(key); + } + Self(Box::new(iter), PhantomData) + } +} + +impl<T: pallet_identity::Config> Iterator for IdtyDataIter<T> { + type Item = (T::AccountId, T::IdtyData); + + fn next(&mut self) -> Option<Self::Item> { + if let Some(pallet_identity::IdtyValue { + owner_key, data, .. + }) = self.0.next() + { + Some((owner_key, data)) + } else { + None + } + } +} -- GitLab