diff --git a/pallets/identity/src/lib.rs b/pallets/identity/src/lib.rs index 1da429a4a0b0d3de3cfd095abf6181f2f4de55c3..0cc9fc0895b89dc5a44acb99ae3f936da3267fd3 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 be602e77dc69c1e0a2cbbc9236e0d8c9f72ea6cc..eb599c40ed5fdf81a091c236e8d1d4421f8466b0 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 cddf467a9a8eeac8596b22e2cd5974c7177ed783..193a9bd98fc9c6d558d7c7f6748529fef3454243 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 + } + } +}