Skip to content
Snippets Groups Projects

smith-members

Merged Cédric Moreau requested to merge feature/smith-members into master
2 files
+ 108
36
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -225,30 +225,28 @@ pub mod pallet {
#[pallet::error]
pub enum Error<T> {
/// Certification issuer has no known identity ID
UnknownIssuer,
/// Issuer of anything (invitation, acceptance, certification) must have an identity ID
OriginMustHaveAnIdentity,
/// Issuer must be known as a potential smith
IssuerHasNoSmithStatus,
OriginHasNeverBeenInvited,
/// Invitation is reseverd to smiths
CannotInvite,
/// Must have receive invitation to accept it
NotInvited,
InvitationIsASmithPrivilege,
/// Invitation must not have been accepted yet
AlreadyAcceptedInvitation,
/// Recevier must not be known among smiths
OnlyExcludedCanComeBack,
/// Recevier must have accepted to eventually become a smith
ReceveirMustAcceptInvitation,
InvitationAlreadyAccepted,
/// Invitation of an already known smith is forbidden except if it has been excluded
InvitationOfNonExcluded,
/// Certification cannot be made on someone who has not accepted an invitation
CertificationMustBeAgreed,
/// Certification cannot be made on excluded
CertificationOnExcludedIsForbidden,
/// Issuer must be a smith
IssuerIsNotASmith,
CertificationIsASmithPrivilege,
/// Smith cannot certify itself
CannotCertifySelf,
CertificationOfSelfIsForbidden,
/// Receiver must be invited by another smith
ReceiverHasNotBeenInvited,
/// Smith must be a member of the main WoT
NotAMember,
CertificationReceiverMustHaveBeenInvited,
/// A smith has a limited stock of certifications
TooMuchCertificationsIssued,
CertificationStockFullyConsumed,
}
#[pallet::call]
@@ -260,7 +258,8 @@ pub mod pallet {
receiver: T::IdtyIndex,
) -> DispatchResultWithPostInfo {
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>::OriginMustHaveAnIdentity)?;
Self::check_invite_smith(issuer, receiver)?;
Self::do_invite_smith(issuer, receiver);
Ok(().into())
@@ -270,7 +269,8 @@ pub mod pallet {
#[pallet::weight(1_000_000_000)]
pub fn accept_invitation(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin.clone())?;
let receiver = T::IdtyIdOf::convert(who.clone()).ok_or(Error::<T>::UnknownIssuer)?;
let receiver =
T::IdtyIdOf::convert(who.clone()).ok_or(Error::<T>::OriginMustHaveAnIdentity)?;
Self::check_accept_invitation(receiver)?;
Self::do_accept_invitation(receiver)?;
Ok(().into())
@@ -283,7 +283,8 @@ pub mod pallet {
receiver: T::IdtyIndex,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let issuer = T::IdtyIdOf::convert(who.clone()).ok_or(Error::<T>::UnknownIssuer)?;
let issuer =
T::IdtyIdOf::convert(who.clone()).ok_or(Error::<T>::OriginMustHaveAnIdentity)?;
Self::check_certify_smith(issuer, receiver)?;
Self::do_certify_smith(receiver, issuer);
Ok(().into())
@@ -297,16 +298,16 @@ impl<T: Config> Pallet<T> {
receiver: T::IdtyIndex,
) -> DispatchResultWithPostInfo {
let issuer_status = Smiths::<T>::get(issuer)
.ok_or(Error::<T>::IssuerHasNoSmithStatus)?
.ok_or(Error::<T>::OriginHasNeverBeenInvited)?
.status;
ensure!(
issuer_status == SmithStatus::Smith,
Error::<T>::CannotInvite
Error::<T>::InvitationIsASmithPrivilege
);
if let Some(receiver_meta) = Smiths::<T>::get(receiver) {
ensure!(
receiver_meta.status == SmithStatus::Excluded,
Error::<T>::OnlyExcludedCanComeBack
Error::<T>::InvitationOfNonExcluded
);
}
@@ -343,11 +344,11 @@ impl<T: Config> Pallet<T> {
fn check_accept_invitation(receiver: T::IdtyIndex) -> DispatchResultWithPostInfo {
let pretender_status = Smiths::<T>::get(receiver)
.ok_or(Error::<T>::NotInvited)?
.ok_or(Error::<T>::OriginHasNeverBeenInvited)?
.status;
ensure!(
pretender_status == SmithStatus::Invited,
Error::<T>::AlreadyAcceptedInvitation
Error::<T>::InvitationAlreadyAccepted
);
Ok(().into())
}
@@ -367,23 +368,30 @@ impl<T: Config> Pallet<T> {
issuer: T::IdtyIndex,
receiver: T::IdtyIndex,
) -> DispatchResultWithPostInfo {
ensure!(issuer != receiver, Error::<T>::CannotCertifySelf);
let issuer = Smiths::<T>::get(issuer).ok_or(Error::<T>::IssuerHasNoSmithStatus)?;
ensure!(
issuer != receiver,
Error::<T>::CertificationOfSelfIsForbidden
);
let issuer = Smiths::<T>::get(issuer).ok_or(Error::<T>::OriginHasNeverBeenInvited)?;
ensure!(
issuer.status == SmithStatus::Smith,
Error::<T>::IssuerIsNotASmith
Error::<T>::CertificationIsASmithPrivilege
);
let issued_certs = issuer.issued_certs.len() as u32;
ensure!(
issued_certs < T::MaxByIssuer::get(),
Error::<T>::TooMuchCertificationsIssued
Error::<T>::CertificationStockFullyConsumed
);
let receiver_status = Smiths::<T>::get(receiver)
.ok_or(Error::<T>::ReceiverHasNotBeenInvited)?
.ok_or(Error::<T>::CertificationReceiverMustHaveBeenInvited)?
.status;
ensure!(
receiver_status != SmithStatus::Invited,
Error::<T>::ReceveirMustAcceptInvitation
Error::<T>::CertificationMustBeAgreed
);
ensure!(
receiver_status != SmithStatus::Excluded,
Error::<T>::CertificationOnExcludedIsForbidden
);
Ok(().into())
Loading