diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs index 39505cabf4036271eaddc5a9f10cc2c101c5db51..525d63bb04d3c19ecb58963eabfb0de9c3f8df3b 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 91da35b60b4eae67079be8c8cec6a076dbee3d8e..32be08e4bb771c3dfdbe9f2b30ccda82a94f7618 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 32a6e905accb8408da79e7f9fe78d62a7be5f439..e4a20190f08454cb2fc4357ddf88dd87eb69b8be 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; } )* );