Skip to content

Commit aad46ec

Browse files
gavofyorkark0f
authored andcommitted
Expose tracks as a constant. (paritytech#12273)
* Expose tracks as a constant. * Formatting
1 parent 9ada362 commit aad46ec

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

bin/node/runtime/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
828828
}
829829
}
830830
}
831+
pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);
831832

832833
impl pallet_referenda::Config for Runtime {
833834
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;

frame/referenda/src/lib.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use frame_support::{
7272
v2::{Anon as ScheduleAnon, Named as ScheduleNamed},
7373
DispatchTime, MaybeHashed,
7474
},
75-
Currency, Get, LockIdentifier, OnUnbalanced, OriginTrait, PollStatus, Polling,
75+
Currency, LockIdentifier, OnUnbalanced, OriginTrait, PollStatus, Polling,
7676
ReservableCurrency, VoteTally,
7777
},
7878
BoundedVec,
@@ -108,6 +108,30 @@ mod tests;
108108
#[cfg(feature = "runtime-benchmarks")]
109109
pub mod benchmarking;
110110

111+
pub use frame_support::traits::Get;
112+
pub use sp_std::vec::Vec;
113+
114+
#[macro_export]
115+
macro_rules! impl_tracksinfo_get {
116+
($tracksinfo:ty, $balance:ty, $blocknumber:ty) => {
117+
impl
118+
$crate::Get<
119+
$crate::Vec<(
120+
<$tracksinfo as $crate::TracksInfo<$balance, $blocknumber>>::Id,
121+
$crate::TrackInfo<$balance, $blocknumber>,
122+
)>,
123+
> for $tracksinfo
124+
{
125+
fn get() -> $crate::Vec<(
126+
<$tracksinfo as $crate::TracksInfo<$balance, $blocknumber>>::Id,
127+
$crate::TrackInfo<$balance, $blocknumber>,
128+
)> {
129+
<$tracksinfo as $crate::TracksInfo<$balance, $blocknumber>>::tracks().to_vec()
130+
}
131+
}
132+
};
133+
}
134+
111135
const ASSEMBLY_ID: LockIdentifier = *b"assembly";
112136

113137
#[frame_support::pallet]
@@ -184,11 +208,17 @@ pub mod pallet {
184208

185209
// The other stuff.
186210
/// Information concerning the different referendum tracks.
187-
type Tracks: TracksInfo<
188-
BalanceOf<Self, I>,
189-
Self::BlockNumber,
190-
Origin = <Self::Origin as OriginTrait>::PalletsOrigin,
191-
>;
211+
#[pallet::constant]
212+
type Tracks: Get<
213+
Vec<(
214+
<Self::Tracks as TracksInfo<BalanceOf<Self, I>, Self::BlockNumber>>::Id,
215+
TrackInfo<BalanceOf<Self, I>, Self::BlockNumber>,
216+
)>,
217+
> + TracksInfo<
218+
BalanceOf<Self, I>,
219+
Self::BlockNumber,
220+
Origin = <Self::Origin as OriginTrait>::PalletsOrigin,
221+
>;
192222
}
193223

194224
/// The next free referendum index, aka the number of referenda started so far.

frame/referenda/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ impl TracksInfo<u64, u64> for TestTracksInfo {
210210
}
211211
}
212212
}
213+
impl_tracksinfo_get!(TestTracksInfo, u64, u64);
213214

214215
impl Config for Test {
215216
type WeightInfo = ();

0 commit comments

Comments
 (0)