Skip to content
Snippets Groups Projects
Commit 9bcb14ca authored by Cédric Moreau's avatar Cédric Moreau
Browse files

WIP: seems PendingNewAccounts has no more meaning

parent 373c1ce8
No related branches found
No related tags found
No related merge requests found
Pipeline #35779 failed
...@@ -82,13 +82,6 @@ pub mod pallet { ...@@ -82,13 +82,6 @@ pub mod pallet {
type Refund: pallet_quota::traits::RefundFee<Self>; 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 // // GENESIS STUFF //
#[pallet::genesis_config] #[pallet::genesis_config]
...@@ -225,71 +218,6 @@ pub mod pallet { ...@@ -225,71 +218,6 @@ pub mod pallet {
Ok(()) 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 // implement account linker
...@@ -344,31 +272,6 @@ where ...@@ -344,31 +272,6 @@ where
None None
}; };
let result = f(&mut some_data)?; 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 // do mutate the account by setting the balances
frame_system::Account::<T>::mutate(account_id, |a| { frame_system::Account::<T>::mutate(account_id, |a| {
a.data.set_balances(some_data.unwrap_or_default()) a.data.set_balances(some_data.unwrap_or_default())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment