Skip to content
Snippets Groups Projects
Unverified Commit 0b75ae3f authored by bgallois's avatar bgallois
Browse files

optimize AccountLinker

parent 54d8caf9
Branches
Tags
No related merge requests found
...@@ -219,22 +219,18 @@ pub mod pallet { ...@@ -219,22 +219,18 @@ pub mod pallet {
/// link account to identity /// link account to identity
pub fn do_link_identity( pub fn do_link_identity(
account_id: T::AccountId, account_id: &T::AccountId,
idty_id: IdtyIdOf<T>, idty_id: IdtyIdOf<T>,
) -> Result<(), DispatchError> { ) -> Result<(), DispatchError> {
// Check that account exist // Check that account exist
ensure!( ensure!(
(frame_system::Account::<T>::get(&account_id).providers >= 1) (frame_system::Account::<T>::get(account_id).providers >= 1)
|| (frame_system::Account::<T>::get(&account_id).sufficients >= 1), || (frame_system::Account::<T>::get(account_id).sufficients >= 1),
pallet_identity::Error::<T>::AccountNotExist pallet_identity::Error::<T>::AccountNotExist
); );
// no-op if identity does not change // no-op if identity does not change
if frame_system::Account::<T>::get(&account_id) if frame_system::Account::<T>::get(account_id).data.linked_idty != Some(idty_id) {
.data frame_system::Account::<T>::mutate(account_id, |account| {
.linked_idty
!= Some(idty_id)
{
frame_system::Account::<T>::mutate(&account_id, |account| {
account.data.linked_idty = Some(idty_id); account.data.linked_idty = Some(idty_id);
Self::deposit_event(Event::AccountLinked { Self::deposit_event(Event::AccountLinked {
who: account_id.clone(), who: account_id.clone(),
...@@ -335,7 +331,7 @@ impl<T> pallet_identity::traits::LinkIdty<T::AccountId, IdtyIdOf<T>> for Pallet< ...@@ -335,7 +331,7 @@ impl<T> pallet_identity::traits::LinkIdty<T::AccountId, IdtyIdOf<T>> for Pallet<
where where
T: Config, T: Config,
{ {
fn link_identity(account_id: T::AccountId, idty_id: IdtyIdOf<T>) -> Result<(), DispatchError> { fn link_identity(account_id: &T::AccountId, idty_id: IdtyIdOf<T>) -> Result<(), DispatchError> {
Self::do_link_identity(account_id, idty_id) Self::do_link_identity(account_id, idty_id)
} }
} }
......
...@@ -328,7 +328,7 @@ pub mod pallet { ...@@ -328,7 +328,7 @@ pub mod pallet {
idty_index, idty_index,
owner_key: owner_key.clone(), owner_key: owner_key.clone(),
}); });
T::AccountLinker::link_identity(owner_key.clone(), idty_index)?; T::AccountLinker::link_identity(&owner_key, idty_index)?;
T::OnIdtyChange::on_idty_change( T::OnIdtyChange::on_idty_change(
idty_index, idty_index,
&IdtyEvent::Created { &IdtyEvent::Created {
...@@ -455,7 +455,7 @@ pub mod pallet { ...@@ -455,7 +455,7 @@ pub mod pallet {
frame_system::Pallet::<T>::inc_sufficients(&idty_value.owner_key); frame_system::Pallet::<T>::inc_sufficients(&idty_value.owner_key);
IdentityIndexOf::<T>::insert(&idty_value.owner_key, idty_index); IdentityIndexOf::<T>::insert(&idty_value.owner_key, idty_index);
Identities::<T>::insert(idty_index, idty_value); Identities::<T>::insert(idty_index, idty_value);
T::AccountLinker::link_identity(new_key.clone(), idty_index)?; T::AccountLinker::link_identity(&new_key, idty_index)?;
Self::deposit_event(Event::IdtyChangedOwnerKey { Self::deposit_event(Event::IdtyChangedOwnerKey {
idty_index, idty_index,
new_owner_key: new_key, new_owner_key: new_key,
...@@ -586,7 +586,7 @@ pub mod pallet { ...@@ -586,7 +586,7 @@ pub mod pallet {
Error::<T>::InvalidSignature Error::<T>::InvalidSignature
); );
// apply // apply
T::AccountLinker::link_identity(account_id, idty_index)?; T::AccountLinker::link_identity(&account_id, idty_index)?;
Ok(().into()) Ok(().into())
} }
......
...@@ -53,10 +53,10 @@ impl<T: Config> OnIdtyChange<T> for Tuple { ...@@ -53,10 +53,10 @@ impl<T: Config> OnIdtyChange<T> for Tuple {
/// trait used to link an account to an identity /// trait used to link an account to an identity
pub trait LinkIdty<AccountId, IdtyIndex> { pub trait LinkIdty<AccountId, IdtyIndex> {
fn link_identity(account_id: AccountId, idty_index: IdtyIndex) -> Result<(), DispatchError>; fn link_identity(account_id: &AccountId, idty_index: IdtyIndex) -> Result<(), DispatchError>;
} }
impl<AccountId, IdtyIndex> LinkIdty<AccountId, IdtyIndex> for () { impl<AccountId, IdtyIndex> LinkIdty<AccountId, IdtyIndex> for () {
fn link_identity(_: AccountId, _: IdtyIndex) -> Result<(), DispatchError> { fn link_identity(_: &AccountId, _: IdtyIndex) -> Result<(), DispatchError> {
Ok(()) Ok(())
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment