diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs index 525d63bb04d3c19ecb58963eabfb0de9c3f8df3b..14883a23695a87ce5c4e36a067f414ddd7714d6c 100644 --- a/pallets/duniter-wot/src/lib.rs +++ b/pallets/duniter-wot/src/lib.rs @@ -105,6 +105,8 @@ pub mod pallet { MaxEmitedCertsReached, /// Not allowed to change identity address NotAllowedToChangeIdtyAddress, + /// Not allowed to remove identity + NotAllowedToRemoveIdty, } } @@ -178,11 +180,14 @@ where Ok(()) } } - fn can_remove_identity(idty_index: IdtyIndex) -> bool { + fn check_remove_identity(idty_index: IdtyIndex) -> Result<(), DispatchError> { if T::IsSubWot::get() { - !pallet_membership::Pallet::<T, I>::is_member(&idty_index) + match pallet_membership::Pallet::<T, I>::is_member(&idty_index) { + true => Err(Error::<T, I>::NotAllowedToRemoveIdty.into()), + false => Ok(()), + } } else { - true + Ok(()) } } } diff --git a/pallets/identity/src/lib.rs b/pallets/identity/src/lib.rs index 32be08e4bb771c3dfdbe9f2b30ccda82a94f7618..0c91a9546fb252ab7832ff0482ccb1ac54458290 100644 --- a/pallets/identity/src/lib.rs +++ b/pallets/identity/src/lib.rs @@ -498,10 +498,7 @@ pub mod pallet { Error::<T>::InvalidRevocationKey ); - ensure!( - T::EnsureIdtyCallAllowed::can_remove_identity(idty_index), - Error::<T>::NotAllowedToRemoveIdty - ); + T::EnsureIdtyCallAllowed::check_remove_identity(idty_index)?; let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero()); let revocation_payload = RevocationPayload { @@ -601,8 +598,6 @@ pub mod pallet { InvalidRevocationKey, /// Revocation payload signature is invalid InvalidRevocationSig, - /// Not allowed to remove identity - NotAllowedToRemoveIdty, /// Identity creation period is not respected NotRespectIdtyCreationPeriod, /// Not the same identity name diff --git a/pallets/identity/src/traits.rs b/pallets/identity/src/traits.rs index e4a20190f08454cb2fc4357ddf88dd87eb69b8be..181dec6cccb6a81828f63dc03756ea7f4c3f17e0 100644 --- a/pallets/identity/src/traits.rs +++ b/pallets/identity/src/traits.rs @@ -24,7 +24,7 @@ pub trait EnsureIdtyCallAllowed<T: Config> { fn check_confirm_identity(idty_index: T::IdtyIndex) -> Result<(), DispatchError>; fn check_validate_identity(idty_index: T::IdtyIndex) -> Result<(), DispatchError>; fn check_change_identity_address(idty_index: T::IdtyIndex) -> Result<(), DispatchError>; - fn can_remove_identity(idty_index: T::IdtyIndex) -> bool; + fn check_remove_identity(idty_index: T::IdtyIndex) -> Result<(), DispatchError>; } #[impl_for_tuples(5)] @@ -46,9 +46,9 @@ impl<T: Config> EnsureIdtyCallAllowed<T> for Tuple { for_tuples!( #( Tuple::check_change_identity_address(idty_index)?; )* ); Ok(()) } - fn can_remove_identity(idty_index: T::IdtyIndex) -> bool { - for_tuples!( #( if !Tuple::can_remove_identity(idty_index) { return false; } )* ); - true + fn check_remove_identity(idty_index: T::IdtyIndex) -> Result<(), DispatchError> { + for_tuples!( #( Tuple::check_remove_identity(idty_index)?; )* ); + Ok(()) } }