Skip to content
Snippets Groups Projects
Commit 32e54838 authored by Éloïs's avatar Éloïs
Browse files

ref: move IdtyDataIter in common runtime

parent 8f20d4e9
No related branches found
No related tags found
1 merge request!83feat(runtime): create UDs manually with new call universalDividend.claim_uds
...@@ -620,32 +620,3 @@ where ...@@ -620,32 +620,3 @@ where
Ok(result) 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
}
}
}
...@@ -400,7 +400,7 @@ macro_rules! pallets_config { ...@@ -400,7 +400,7 @@ macro_rules! pallets_config {
type MaxPastReeval = frame_support::traits::ConstU32<4>; type MaxPastReeval = frame_support::traits::ConstU32<4>;
type MembersCount = MembersCount; type MembersCount = MembersCount;
type MembersStorage = Identity; type MembersStorage = Identity;
type MembersStorageIter = pallet_identity::IdtyDataIter<Runtime>; type MembersStorageIter = common_runtime::providers::IdtyDataIter<Runtime>;
type SquareMoneyGrowthRate = SquareMoneyGrowthRate; type SquareMoneyGrowthRate = SquareMoneyGrowthRate;
type UdCreationPeriod = UdCreationPeriod; type UdCreationPeriod = UdCreationPeriod;
type UdReevalPeriod = UdReevalPeriod; type UdReevalPeriod = UdReevalPeriod;
......
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. // along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::{AccountId, IdtyIndex}; 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< impl<
Runtime: frame_system::Config<AccountId = AccountId> Runtime: frame_system::Config<AccountId = AccountId>
...@@ -28,3 +31,34 @@ impl< ...@@ -28,3 +31,34 @@ impl<
pallet_identity::Pallet::<Runtime>::identity(idty_index).map(|idty| idty.owner_key) 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
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment