diff --git a/pallets/duniter-account/src/lib.rs b/pallets/duniter-account/src/lib.rs index 5482389c9e54b462013cc3dbd189031f8d65ff0f..3a016a40105e270cc258d8e7bdccd6aeb211a7c3 100644 --- a/pallets/duniter-account/src/lib.rs +++ b/pallets/duniter-account/src/lib.rs @@ -82,13 +82,6 @@ pub mod pallet { type Refund: pallet_quota::traits::RefundFee<Self>; } - // STORAGE // - - #[pallet::storage] - #[pallet::getter(fn pending_new_accounts)] - pub type PendingNewAccounts<T: Config> = - StorageMap<_, Blake2_128Concat, T::AccountId, (), OptionQuery>; - // GENESIS STUFF // #[pallet::genesis_config] @@ -225,71 +218,6 @@ pub mod pallet { Ok(()) } } - - // HOOKS // - #[pallet::hooks] - impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { - // on initialize, withdraw account creation tax - fn on_initialize(_: T::BlockNumber) -> Weight { - let mut total_weight = Weight::zero(); - for account_id in PendingNewAccounts::<T>::iter_keys() - .drain() - .take(T::MaxNewAccountsPerBlock::get() as usize) - { - if frame_system::Pallet::<T>::sufficients(&account_id) > 0 { - // If the account is self-sufficient, it is exempt from account creation fees - total_weight += <T as pallet::Config>::WeightInfo::on_initialize_sufficient( - T::MaxNewAccountsPerBlock::get(), - ); - } else { - // If the account is not self-sufficient, it must pay the account creation fees - let account_data = frame_system::Pallet::<T>::get(&account_id); - let price = T::NewAccountPrice::get(); - if account_data.free >= T::ExistentialDeposit::get() + price { - // The account can pay the new account price, we should: - // 1. Withdraw the "new account price" amount - // TODO: supprimer 2. Increment consumers to prevent the destruction of the account before the random id is assigned - // 3. Manage the funds collected - let res = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::withdraw( - &account_id, - price, - frame_support::traits::WithdrawReasons::FEE, - ExistenceRequirement::KeepAlive, - ); - debug_assert!( - res.is_ok(), - "Cannot fail because we checked that the free balance was sufficient" - ); - if let Ok(imbalance) = res { - // TODO: decrement consumers? - T::OnUnbalanced::on_unbalanced(imbalance); - total_weight += - <T as pallet::Config>::WeightInfo::on_initialize_with_balance( - T::MaxNewAccountsPerBlock::get(), - ); - } - } else { - // The charges could not be deducted, we must destroy the account - let balance_to_suppr = - account_data.free.saturating_add(account_data.reserved); - // Force account data supression - frame_system::Account::<T>::remove(&account_id); - Self::deposit_event(Event::ForceDestroy { - who: account_id, - balance: balance_to_suppr, - }); - T::OnUnbalanced::on_unbalanced(pallet_balances::NegativeImbalance::new( - balance_to_suppr, - )); - total_weight += <T as pallet::Config>::WeightInfo::on_initialize_no_balance( - T::MaxNewAccountsPerBlock::get(), - ); - } - } - } - total_weight - } - } } // implement account linker @@ -344,31 +272,6 @@ where None }; let result = f(&mut some_data)?; - let is_providing = some_data.is_some(); - match (was_providing, is_providing) { - // the account has just been created, increment its provider - (false, true) => { - frame_system::Pallet::<T>::inc_providers(account_id); - PendingNewAccounts::<T>::insert(account_id, ()); - } - // the account was existing but is not anymore, decrement the provider - (true, false) => { - match frame_system::Pallet::<T>::dec_providers(account_id)? { - frame_system::DecRefStatus::Reaped => return Ok(result), - frame_system::DecRefStatus::Exists => { - // Update value as normal - } - } - } - // mutation on unprovided account - (false, false) => { - return Ok(result); - } - // mutation on provided account - (true, true) => { - // Update value as normal - } - } // do mutate the account by setting the balances frame_system::Account::<T>::mutate(account_id, |a| { a.data.set_balances(some_data.unwrap_or_default())