diff --git a/pallets/certification/src/lib.rs b/pallets/certification/src/lib.rs index 1daa79721c368a9e66700b6af5e35a3ca1d39943..d1e02a7b3bcf58b9ade7140f16b7e50d1d7db9d6 100644 --- a/pallets/certification/src/lib.rs +++ b/pallets/certification/src/lib.rs @@ -242,8 +242,6 @@ pub mod pallet { pub enum Error<T, I = ()> { /// An identity cannot certify itself CannotCertifySelf, - /// Certification non autorisée - CertNotAllowed, /// This identity has already issued the maximum number of certifications IssuedTooManyCert, /// Issuer not found @@ -325,10 +323,7 @@ pub mod pallet { ensure!(issuer_owner_key == who, DispatchError::BadOrigin); // Verify compatibility with other pallets state - ensure!( - T::IsCertAllowed::is_cert_allowed(issuer, receiver), - Error::<T, I>::CertNotAllowed - ); + T::IsCertAllowed::check_cert_allowed(issuer, receiver)?; // Verify rule MinReceivedCertToBeAbleToIssueCert let issuer_idty_cert_meta = <StorageIdtyCertMeta<T, I>>::get(issuer); diff --git a/pallets/certification/src/traits.rs b/pallets/certification/src/traits.rs index 6c41d8c90e35c23500d3c64202eea35ada3624b5..410ea643fab3789513172cf4760f7d38c0b7d81b 100644 --- a/pallets/certification/src/traits.rs +++ b/pallets/certification/src/traits.rs @@ -14,13 +14,15 @@ // You should have received a copy of the GNU Affero General Public License // along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. +use frame_support::pallet_prelude::*; + pub trait IsCertAllowed<IdtyIndex> { - fn is_cert_allowed(issuer: IdtyIndex, receiver: IdtyIndex) -> bool; + fn check_cert_allowed(issuer: IdtyIndex, receiver: IdtyIndex) -> Result<(), DispatchError>; } impl<IdtyIndex> IsCertAllowed<IdtyIndex> for () { - fn is_cert_allowed(_issuer: IdtyIndex, _receiver: IdtyIndex) -> bool { - true + fn check_cert_allowed(_issuer: IdtyIndex, _receiver: IdtyIndex) -> Result<(), DispatchError> { + Ok(()) } } diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs index 14883a23695a87ce5c4e36a067f414ddd7714d6c..0b5e1a0be6b4dc65425f9de6194f6cb4c5827146 100644 --- a/pallets/duniter-wot/src/lib.rs +++ b/pallets/duniter-wot/src/lib.rs @@ -107,6 +107,10 @@ pub mod pallet { NotAllowedToChangeIdtyAddress, /// Not allowed to remove identity NotAllowedToRemoveIdty, + /// Issuer can not emit cert because it is not validated + IssuerCanNotEmitCert, + /// Can not issue cert to unconfirmed identity + CertToUnconfirmedIdty, } } @@ -195,24 +199,19 @@ where impl<T: Config<I>, I: 'static> pallet_certification::traits::IsCertAllowed<IdtyIndex> for Pallet<T, I> { - fn is_cert_allowed(issuer: IdtyIndex, receiver: IdtyIndex) -> bool { + fn check_cert_allowed(issuer: IdtyIndex, receiver: IdtyIndex) -> Result<(), DispatchError> { if let Some(issuer_data) = pallet_identity::Pallet::<T>::identity(issuer) { if issuer_data.status != IdtyStatus::Validated { - return false; + return Err(Error::<T, I>::IssuerCanNotEmitCert.into()); } if let Some(receiver_data) = pallet_identity::Pallet::<T>::identity(receiver) { match receiver_data.status { - IdtyStatus::ConfirmedByOwner | IdtyStatus::Validated => true, - IdtyStatus::Created => false, + IdtyStatus::ConfirmedByOwner | IdtyStatus::Validated => (), + IdtyStatus::Created => return Err(Error::<T, I>::CertToUnconfirmedIdty.into()), } - } else { - // Receiver not found - false - } - } else { - // Issuer not found - false - } + }; + }; + Ok(()) } }