Skip to content
Snippets Groups Projects

Fix account linking

Merged Benjamin Gallois requested to merge bgallois/duniter-v2s:153-linking into master
Compare and
6 files
+ 111
47
Compare changes
  • Side-by-side
  • Inline
Files
6
@@ -32,7 +32,6 @@ use frame_support::pallet_prelude::*;
@@ -32,7 +32,6 @@ use frame_support::pallet_prelude::*;
use frame_support::traits::{Currency, ExistenceRequirement, StorageVersion};
use frame_support::traits::{Currency, ExistenceRequirement, StorageVersion};
use frame_support::traits::{OnUnbalanced, StoredMap};
use frame_support::traits::{OnUnbalanced, StoredMap};
use frame_system::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use pallet_identity::IdtyEvent;
use pallet_provide_randomness::RequestId;
use pallet_provide_randomness::RequestId;
use pallet_quota::traits::RefundFee;
use pallet_quota::traits::RefundFee;
use pallet_transaction_payment::OnChargeTransaction;
use pallet_transaction_payment::OnChargeTransaction;
@@ -219,7 +218,16 @@ pub mod pallet {
@@ -219,7 +218,16 @@ pub mod pallet {
}
}
/// link account to identity
/// link account to identity
pub fn do_link_identity(account_id: T::AccountId, idty_id: IdtyIdOf<T>) {
pub fn do_link_identity(
 
account_id: T::AccountId,
 
idty_id: IdtyIdOf<T>,
 
) -> Result<(), DispatchError> {
 
// Check that account exist
 
ensure!(
 
(frame_system::Account::<T>::get(&account_id).providers >= 1)
 
|| (frame_system::Account::<T>::get(&account_id).sufficients >= 1),
 
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
.data
@@ -234,6 +242,7 @@ pub mod pallet {
@@ -234,6 +242,7 @@ pub mod pallet {
});
});
})
})
}
}
 
Ok(())
}
}
}
}
@@ -326,8 +335,9 @@ impl<T> pallet_identity::traits::LinkIdty<T::AccountId, IdtyIdOf<T>> for Pallet<
@@ -326,8 +335,9 @@ 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>) {
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)?;
 
Ok(())
}
}
}
}
@@ -478,16 +488,3 @@ where
@@ -478,16 +488,3 @@ where
Ok(())
Ok(())
}
}
}
}
// implement identity event handler
impl<T: Config> pallet_identity::traits::OnIdtyChange<T> for Pallet<T> {
fn on_idty_change(idty_id: IdtyIdOf<T>, idty_event: &IdtyEvent<T>) {
match idty_event {
// link account to newly created identity
IdtyEvent::Created { owner_key, .. } => {
Self::do_link_identity(owner_key.clone(), idty_id);
}
IdtyEvent::Removed { .. } => {}
}
}
}
Loading