Skip to content
Snippets Groups Projects
Unverified Commit 9397afa8 authored by bgallois's avatar bgallois
Browse files

refactore double queries

parent fc2880aa
No related branches found
No related tags found
No related merge requests found
Pipeline #39995 failed
......@@ -589,27 +589,24 @@ impl<T: Config> Pallet<T> {
/// Handle the event when a Smith goes online.
pub fn on_smith_goes_online(idty_index: T::IdtyIndex) {
if let Some(smith_meta) = Smiths::<T>::get(idty_index) {
if smith_meta.expires_on.is_some() {
Smiths::<T>::mutate(idty_index, |maybe_smith_meta| {
if let Some(smith_meta) = maybe_smith_meta {
if smith_meta.expires_on.is_some() {
// As long as the smith is online, it cannot expire
smith_meta.expires_on = None;
smith_meta.last_online = None;
}
});
}
}
});
}
/// Handle the event when a Smith goes offline.
pub fn on_smith_goes_offline(idty_index: T::IdtyIndex) {
if let Some(smith_meta) = Smiths::<T>::get(idty_index) {
Smiths::<T>::mutate(idty_index, |maybe_smith_meta| {
if let Some(smith_meta) = maybe_smith_meta {
// Smith can go offline after main membership expiry
// in this case, there is no scheduled expiry since it is already excluded
if smith_meta.status != SmithStatus::Excluded {
Smiths::<T>::mutate(idty_index, |maybe_smith_meta| {
if let Some(smith_meta) = maybe_smith_meta {
// schedule expiry
let new_expires_on =
CurrentSession::<T>::get() + T::SmithInactivityMaxDuration::get();
......@@ -618,17 +615,13 @@ impl<T: Config> Pallet<T> {
smith_meta.last_online = Some(block_number);
ExpiresOn::<T>::append(new_expires_on, idty_index);
}
});
}
}
});
}
/// Provide whether the given identity index is a Smith.
fn provide_is_member(idty_id: &T::IdtyIndex) -> bool {
let Some(smith) = Smiths::<T>::get(idty_id) else {
return false;
};
smith.status == SmithStatus::Smith
Smiths::<T>::get(idty_id).map_or(false, |smith| smith.status == SmithStatus::Smith)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment