From 8b2548acf6b7edb351183fd08d41c691b20cf223 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Fri, 23 Sep 2022 00:38:51 +0200 Subject: [PATCH] wip replace cert allowed check --- pallets/certification/src/lib.rs | 7 +------ pallets/certification/src/traits.rs | 8 +++++--- pallets/duniter-wot/src/lib.rs | 23 +++++++++++------------ 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/pallets/certification/src/lib.rs b/pallets/certification/src/lib.rs index 1daa79721..d1e02a7b3 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 6c41d8c90..410ea643f 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 14883a236..0b5e1a0be 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(()) } } -- GitLab