mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 13:17:56 +00:00
add iter-from for bags-list (#11104)
* add iter-from for bags-list * Fix * Apply suggestions from code review Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -1308,7 +1308,6 @@ impl<T: Config> SortedListProvider<T::AccountId> for UseNominatorsAndValidatorsM
|
||||
type Error = ();
|
||||
type Score = VoteWeight;
|
||||
|
||||
/// Returns iterator over voter list, which can have `take` called on it.
|
||||
fn iter() -> Box<dyn Iterator<Item = T::AccountId>> {
|
||||
Box::new(
|
||||
Validators::<T>::iter()
|
||||
@@ -1316,6 +1315,23 @@ impl<T: Config> SortedListProvider<T::AccountId> for UseNominatorsAndValidatorsM
|
||||
.chain(Nominators::<T>::iter().map(|(n, _)| n)),
|
||||
)
|
||||
}
|
||||
fn iter_from(
|
||||
start: &T::AccountId,
|
||||
) -> Result<Box<dyn Iterator<Item = T::AccountId>>, Self::Error> {
|
||||
if Validators::<T>::contains_key(start) {
|
||||
let start_key = Validators::<T>::hashed_key_for(start);
|
||||
Ok(Box::new(
|
||||
Validators::<T>::iter_from(start_key)
|
||||
.map(|(n, _)| n)
|
||||
.chain(Nominators::<T>::iter().map(|(x, _)| x)),
|
||||
))
|
||||
} else if Nominators::<T>::contains_key(start) {
|
||||
let start_key = Nominators::<T>::hashed_key_for(start);
|
||||
Ok(Box::new(Nominators::<T>::iter_from(start_key).map(|(n, _)| n)))
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
fn count() -> u32 {
|
||||
Nominators::<T>::count().saturating_add(Validators::<T>::count())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user