Skip to content

Commit

Permalink
Rename track_ids and return iterator as well
Browse files Browse the repository at this point in the history
  • Loading branch information
olanod committed Feb 22, 2024
1 parent ecbe227 commit 6a877dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions substrate/frame/referenda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ macro_rules! impl_tracksinfo_get {
>,
> {
<$tracksinfo as $crate::TracksInfo<$balance, $blocknumber>>::tracks()
.map(|t: sp_std::borrow::Cow<'static, $crate::Track<_, _, _>>| t.into_owned())
.map(|t| t.into_owned())
.collect()
}
}
Expand Down Expand Up @@ -744,7 +744,7 @@ impl<T: Config<I>, I: 'static> Polling<T::Tally> for Pallet<T, I> {
type Class = TrackIdOf<T, I>;

fn classes() -> Vec<Self::Class> {
T::Tracks::tracks_ids()
T::Tracks::track_ids().collect()
}

fn access_poll<R>(
Expand Down
14 changes: 6 additions & 8 deletions substrate/frame/referenda/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ pub struct Deposit<AccountId, Balance> {
pub amount: Balance,
}

const DEFAULT_MAX_TRACK_NAME_LEN: usize = 25;
pub const DEFAULT_MAX_TRACK_NAME_LEN: usize = 25;

/// Detailed information about the configuration of a referenda track
#[derive(Clone, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub struct TrackInfo<Balance, Moment, const N: usize = DEFAULT_MAX_TRACK_NAME_LEN> {
/// Name of this track.
Expand All @@ -138,6 +139,7 @@ pub struct TrackInfo<Balance, Moment, const N: usize = DEFAULT_MAX_TRACK_NAME_LE
pub min_support: Curve,
}

/// Track groups the information of a voting track with its corresponding identifier
#[derive(Clone, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub struct Track<Id, Balance, Moment, const N: usize = DEFAULT_MAX_TRACK_NAME_LEN> {
pub id: Id,
Expand Down Expand Up @@ -166,8 +168,8 @@ where
fn track_for(origin: &Self::RuntimeOrigin) -> Result<Self::Id, ()>;

/// Return the list of identifiers of the known tracks.
fn tracks_ids() -> Vec<Self::Id> {
Self::tracks().map(|x| x.id).collect()
fn track_ids() -> impl Iterator<Item = Self::Id> {
Self::tracks().map(|x| x.id)
}

/// Return the track info for track `id`, by default this just looks it up in `Self::tracks()`.
Expand All @@ -179,11 +181,7 @@ where
}

/// Check assumptions about the static data that this trait provides.
fn check_integrity() -> Result<(), &'static str>
where
Balance: 'static,
Moment: 'static,
{
fn check_integrity() -> Result<(), &'static str> {
use core::cmp::Ordering;
// Adapted from Iterator::is_sorted implementation available in nightly
// https://github.com/rust-lang/rust/issues/53485
Expand Down

0 comments on commit 6a877dc

Please sign in to comment.