pub trait SortedListProvider<AccountId> {
    type Error: Debug;
    type Score: Bounded + Saturating + Zero;

Show 14 methods fn iter() -> Box<dyn Iterator<Item = AccountId>>; fn iter_from(
        start: &AccountId
    ) -> Result<Box<dyn Iterator<Item = AccountId>>, Self::Error>; fn count() -> u32; fn contains(id: &AccountId) -> bool; fn on_insert(id: AccountId, score: Self::Score) -> Result<(), Self::Error>; fn on_update(id: &AccountId, score: Self::Score) -> Result<(), Self::Error>; fn get_score(id: &AccountId) -> Result<Self::Score, Self::Error>; fn on_remove(id: &AccountId) -> Result<(), Self::Error>; fn unsafe_regenerate(
        all: impl IntoIterator<Item = AccountId>,
        score_of: Box<dyn Fn(&AccountId) -> Self::Score>
    ) -> u32; fn unsafe_clear(); fn try_state() -> Result<(), &'static str>; fn on_increase(
        id: &AccountId,
        additional: Self::Score
    ) -> Result<(), Self::Error> { ... } fn on_decrease(
        id: &AccountId,
        decreased: Self::Score
    ) -> Result<(), Self::Error> { ... } fn score_update_worst_case(
        _who: &AccountId,
        _is_increase: bool
    ) -> Self::Score { ... }
}
Expand description

A utility trait for something to implement ElectionDataProvider in a sensible way.

This is generic over AccountId and it can represent a validator, a nominator, or any other entity.

The scores (see Self::Score) are ascending, the higher, the better.

Something that implements this trait will do a best-effort sort over ids, and thus can be used on the implementing side of ElectionDataProvider.

Required Associated Types§

The list’s error type.

The type used by the list to compare nodes for ordering.

Required Methods§

An iterator over the list, which can have take called on it.

Returns an iterator over the list, starting right after from the given voter.

May return an error if start is invalid.

The current count of ids in the list.

Return true if the list already contains id.

Hook for inserting a new id.

Implementation should return an error if duplicate item is being inserted.

Hook for updating a single id.

The new score is given.

Returns Ok(()) iff it successfully updates an item, an Err(_) otherwise.

Get the score of id.

Hook for removing am id from the list.

Returns Ok(()) iff it successfully removes an item, an Err(_) otherwise.

Regenerate this list from scratch. Returns the count of items inserted.

This should typically only be used at a runtime upgrade.

WARNING

This function should be called with care, regenerate will remove the current list write the new list, which can lead to too many storage accesses, exhausting the block weight.

Remove all items from the list.

WARNING

This function should never be called in production settings because it can lead to an unbounded amount of storage accesses.

Check internal state of list. Only meant for debugging.

Provided Methods§

Same as on_update, but incorporate some increased score.

Same as on_update, but incorporate some decreased score.

If the new score of the item is Zero, it is removed.

If who changes by the returned amount they are guaranteed to have a worst case change in their list position.

Implementors§