mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
Pallet session new API (#4609)
* Initial work * Fix most things * fix test * fix old comment * migration * fix * remove useless stuff * fix * less spaghetti implementation * fix initial session * fix
This commit is contained in:
@@ -88,9 +88,10 @@ impl SessionHandler<u64> for TestSessionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TestOnSessionEnding;
|
||||
impl OnSessionEnding<u64> for TestOnSessionEnding {
|
||||
fn on_session_ending(_: SessionIndex, _: SessionIndex) -> Option<Vec<u64>> {
|
||||
pub struct TestSessionManager;
|
||||
impl SessionManager<u64> for TestSessionManager {
|
||||
fn end_session(_: SessionIndex) {}
|
||||
fn new_session(_: SessionIndex) -> Option<Vec<u64>> {
|
||||
if !TEST_SESSION_CHANGED.with(|l| *l.borrow()) {
|
||||
VALIDATORS.with(|v| {
|
||||
let mut v = v.borrow_mut();
|
||||
@@ -108,14 +109,13 @@ impl OnSessionEnding<u64> for TestOnSessionEnding {
|
||||
}
|
||||
|
||||
#[cfg(feature = "historical")]
|
||||
impl crate::historical::OnSessionEnding<u64, u64> for TestOnSessionEnding {
|
||||
fn on_session_ending(ending_index: SessionIndex, will_apply_at: SessionIndex)
|
||||
-> Option<(Vec<u64>, Vec<(u64, u64)>)>
|
||||
impl crate::historical::SessionManager<u64, u64> for TestSessionManager {
|
||||
fn end_session(_: SessionIndex) {}
|
||||
fn new_session(new_index: SessionIndex)
|
||||
-> Option<Vec<(u64, u64)>>
|
||||
{
|
||||
let pair_with_ids = |vals: &[u64]| vals.iter().map(|&v| (v, v)).collect::<Vec<_>>();
|
||||
<Self as OnSessionEnding<_>>::on_session_ending(ending_index, will_apply_at)
|
||||
.map(|vals| (pair_with_ids(&vals), vals))
|
||||
.map(|(ids, vals)| (vals, ids))
|
||||
<Self as SessionManager<_>>::new_session(new_index)
|
||||
.map(|vals| vals.into_iter().map(|val| (val, val)).collect())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,15 +190,14 @@ parameter_types! {
|
||||
impl Trait for Test {
|
||||
type ShouldEndSession = TestShouldEndSession;
|
||||
#[cfg(feature = "historical")]
|
||||
type OnSessionEnding = crate::historical::NoteHistoricalRoot<Test, TestOnSessionEnding>;
|
||||
type SessionManager = crate::historical::NoteHistoricalRoot<Test, TestSessionManager>;
|
||||
#[cfg(not(feature = "historical"))]
|
||||
type OnSessionEnding = TestOnSessionEnding;
|
||||
type SessionManager = TestSessionManager;
|
||||
type SessionHandler = TestSessionHandler;
|
||||
type ValidatorId = u64;
|
||||
type ValidatorIdOf = ConvertInto;
|
||||
type Keys = MockSessionKeys;
|
||||
type Event = ();
|
||||
type SelectInitialValidators = ();
|
||||
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user