Skip to content
Snippets Groups Projects

smith-members

Merged Cédric Moreau requested to merge feature/smith-members into master
Compare and Show latest version
3 files
+ 76
8
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -116,8 +116,22 @@ pub mod pallet {
@@ -116,8 +116,22 @@ pub mod pallet {
#[pallet::event]
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
pub enum Event<T: Config> {
 
/// An identity is being inivited to become a smith
 
InvitationSent {
 
idty_index: T::IdtyIndex,
 
invited_by: T::IdtyIndex,
 
},
 
/// The invitation has been accepted
 
InvitationAccepted { idty_index: T::IdtyIndex },
 
/// Certification received
 
CertificationReceived {
 
idty_index: T::IdtyIndex,
 
issued_by: T::IdtyIndex,
 
},
/// A smith gathered enough certifications to become an authority (can call `go_online()`).
/// A smith gathered enough certifications to become an authority (can call `go_online()`).
SmithBecameAuthority { idty_index: T::IdtyIndex },
PromotedToSmith { idty_index: T::IdtyIndex },
 
/// A smith has been removed from the smiths set
 
SmithExcluded { idty_index: T::IdtyIndex },
}
}
#[pallet::genesis_config]
#[pallet::genesis_config]
@@ -248,7 +262,7 @@ pub mod pallet {
@@ -248,7 +262,7 @@ pub mod pallet {
let who = ensure_signed(origin.clone())?;
let who = ensure_signed(origin.clone())?;
let issuer = T::IdtyIdOf::convert(who.clone()).ok_or(Error::<T>::UnknownIssuer)?;
let issuer = T::IdtyIdOf::convert(who.clone()).ok_or(Error::<T>::UnknownIssuer)?;
Self::check_invite_smith(issuer, receiver)?;
Self::check_invite_smith(issuer, receiver)?;
Self::do_invite_smith(receiver);
Self::do_invite_smith(issuer, receiver);
Ok(().into())
Ok(().into())
}
}
@@ -299,7 +313,7 @@ impl<T: Config> Pallet<T> {
@@ -299,7 +313,7 @@ impl<T: Config> Pallet<T> {
Ok(().into())
Ok(().into())
}
}
fn do_invite_smith(receiver: T::IdtyIndex) {
fn do_invite_smith(issuer: T::IdtyIndex, receiver: T::IdtyIndex) {
let new_expires_on = CurrentSession::<T>::get() + T::InactivityMaxDuration::get();
let new_expires_on = CurrentSession::<T>::get() + T::InactivityMaxDuration::get();
// TODO: another way to write this?
// TODO: another way to write this?
if Smiths::<T>::get(receiver).is_some() {
if Smiths::<T>::get(receiver).is_some() {
@@ -321,6 +335,10 @@ impl<T: Config> Pallet<T> {
@@ -321,6 +335,10 @@ impl<T: Config> Pallet<T> {
);
);
}
}
ExpiresOn::<T>::append(new_expires_on, receiver);
ExpiresOn::<T>::append(new_expires_on, receiver);
 
Self::deposit_event(Event::<T>::InvitationSent {
 
idty_index: receiver,
 
invited_by: issuer,
 
});
}
}
fn check_accept_invitation(receiver: T::IdtyIndex) -> DispatchResultWithPostInfo {
fn check_accept_invitation(receiver: T::IdtyIndex) -> DispatchResultWithPostInfo {
@@ -339,6 +357,9 @@ impl<T: Config> Pallet<T> {
@@ -339,6 +357,9 @@ impl<T: Config> Pallet<T> {
let maybe_smith_meta = maybe_smith_meta.as_mut().expect("status checked earlier");
let maybe_smith_meta = maybe_smith_meta.as_mut().expect("status checked earlier");
maybe_smith_meta.status = SmithStatus::Pending;
maybe_smith_meta.status = SmithStatus::Pending;
});
});
 
Self::deposit_event(Event::<T>::InvitationAccepted {
 
idty_index: receiver,
 
});
Ok(().into())
Ok(().into())
}
}
@@ -388,8 +409,12 @@ impl<T: Config> Pallet<T> {
@@ -388,8 +409,12 @@ impl<T: Config> Pallet<T> {
// expiry postponed
// expiry postponed
let new_expires_on = CurrentSession::<T>::get() + T::InactivityMaxDuration::get();
let new_expires_on = CurrentSession::<T>::get() + T::InactivityMaxDuration::get();
maybe_smith_meta.expires_on = Some(new_expires_on);
maybe_smith_meta.expires_on = Some(new_expires_on);
 
Self::deposit_event(Event::<T>::CertificationReceived {
 
idty_index: receiver,
 
issued_by: issuer,
 
});
if maybe_smith_meta.status == SmithStatus::Smith {
if maybe_smith_meta.status == SmithStatus::Smith {
Self::deposit_event(Event::<T>::SmithBecameAuthority {
Self::deposit_event(Event::<T>::PromotedToSmith {
idty_index: receiver,
idty_index: receiver,
});
});
}
}
@@ -433,7 +458,7 @@ impl<T: Config> Pallet<T> {
@@ -433,7 +458,7 @@ impl<T: Config> Pallet<T> {
smith,
smith,
SmithRemovalReason::OfflineTooLong,
SmithRemovalReason::OfflineTooLong,
);
);
// TODO: add event? (+ add others too)
Self::deposit_event(Event::<T>::SmithExcluded { idty_index: smith });
}
}
}
}
}
}
@@ -479,9 +504,7 @@ impl<T: Config> Pallet<T> {
@@ -479,9 +504,7 @@ impl<T: Config> Pallet<T> {
// T::OnSmithDelete::on_smith_delete(idty_index, SmithRemovalReason::Blacklisted);
// T::OnSmithDelete::on_smith_delete(idty_index, SmithRemovalReason::Blacklisted);
// }
// }
}
}
}
impl<T: Config> Pallet<T> {
fn provide_is_member(idty_id: &T::IdtyIndex) -> bool {
fn provide_is_member(idty_id: &T::IdtyIndex) -> bool {
let Some(smith) = Smiths::<T>::get(idty_id) else {
let Some(smith) = Smiths::<T>::get(idty_id) else {
return false;
return false;
Loading