From 69ad219325c41ffe09b95d29cc8cdd7fa88fdebf Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Thu, 22 Sep 2022 23:54:20 +0200 Subject: [PATCH] wip replace adress change check --- pallets/duniter-wot/src/lib.rs | 11 ++++++++--- pallets/identity/src/lib.rs | 7 +------ pallets/identity/src/traits.rs | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs index 39505cabf..525d63bb0 100644 --- a/pallets/duniter-wot/src/lib.rs +++ b/pallets/duniter-wot/src/lib.rs @@ -103,6 +103,8 @@ pub mod pallet { NotEnoughReceivedCertsToCreateIdty, /// Max number of emited certs reached MaxEmitedCertsReached, + /// Not allowed to change identity address + NotAllowedToChangeIdtyAddress, } } @@ -166,11 +168,14 @@ where Ok(()) } } - fn can_change_identity_address(idty_index: IdtyIndex) -> bool { + fn check_change_identity_address(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>::NotAllowedToChangeIdtyAddress.into()), + false => Ok(()), + } } else { - true + Ok(()) } } fn can_remove_identity(idty_index: IdtyIndex) -> bool { diff --git a/pallets/identity/src/lib.rs b/pallets/identity/src/lib.rs index 91da35b60..32be08e4b 100644 --- a/pallets/identity/src/lib.rs +++ b/pallets/identity/src/lib.rs @@ -411,10 +411,7 @@ pub mod pallet { Error::<T>::OwnerKeyAlreadyUsed ); - ensure!( - T::EnsureIdtyCallAllowed::can_change_identity_address(idty_index), - Error::<T>::NotAllowedToChangeIdtyAddress - ); + T::EnsureIdtyCallAllowed::check_change_identity_address(idty_index)?; let block_number = frame_system::Pallet::<T>::block_number(); let maybe_old_old_owner_key = @@ -604,8 +601,6 @@ pub mod pallet { InvalidRevocationKey, /// Revocation payload signature is invalid InvalidRevocationSig, - /// Identity not allowed to change address - NotAllowedToChangeIdtyAddress, /// Not allowed to remove identity NotAllowedToRemoveIdty, /// Identity creation period is not respected diff --git a/pallets/identity/src/traits.rs b/pallets/identity/src/traits.rs index 32a6e905a..e4a20190f 100644 --- a/pallets/identity/src/traits.rs +++ b/pallets/identity/src/traits.rs @@ -23,7 +23,7 @@ pub trait EnsureIdtyCallAllowed<T: Config> { fn check_create_identity(creator: T::IdtyIndex) -> Result<(), DispatchError>; fn check_confirm_identity(idty_index: T::IdtyIndex) -> Result<(), DispatchError>; fn check_validate_identity(idty_index: T::IdtyIndex) -> Result<(), DispatchError>; - fn can_change_identity_address(idty_index: T::IdtyIndex) -> bool; + fn check_change_identity_address(idty_index: T::IdtyIndex) -> Result<(), DispatchError>; fn can_remove_identity(idty_index: T::IdtyIndex) -> bool; } @@ -42,9 +42,9 @@ impl<T: Config> EnsureIdtyCallAllowed<T> for Tuple { for_tuples!( #( Tuple::check_validate_identity(idty_index)?; )* ); Ok(()) } - fn can_change_identity_address(idty_index: T::IdtyIndex) -> bool { - for_tuples!( #( if !Tuple::can_change_identity_address(idty_index) { return false; } )* ); - true + fn check_change_identity_address(idty_index: T::IdtyIndex) -> Result<(), DispatchError> { + 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; } )* ); -- GitLab