mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 22:21:07 +00:00
Introduce OnReapAccount (#4585)
* Initial run and gun at `OnReapAccount` * Fix some imports * More fixes * Whitespace * More wack-a-mole * Gotta catch em all * Update lib.rs * Small doc update * Whitespace
This commit is contained in:
committed by
Gavin Wood
parent
78c73e76c3
commit
a1e0076aa8
@@ -205,6 +205,8 @@ impl balances::Trait for Runtime {
|
||||
type Balance = Balance;
|
||||
/// What to do if an account's free balance gets zeroed.
|
||||
type OnFreeBalanceZero = ();
|
||||
/// What to do if an account is fully reaped from the system.
|
||||
type OnReapAccount = System;
|
||||
/// What to do if a new account is created.
|
||||
type OnNewAccount = Indices;
|
||||
/// The ubiquitous event type.
|
||||
|
||||
@@ -174,6 +174,7 @@ parameter_types! {
|
||||
impl pallet_balances::Trait for Runtime {
|
||||
type Balance = Balance;
|
||||
type OnFreeBalanceZero = ((Staking, Contracts), Session);
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = Indices;
|
||||
type Event = Event;
|
||||
type DustRemoval = ();
|
||||
|
||||
@@ -165,7 +165,7 @@ use codec::{Codec, Encode, Decode};
|
||||
use frame_support::{
|
||||
StorageValue, Parameter, decl_event, decl_storage, decl_module, decl_error,
|
||||
traits::{
|
||||
UpdateBalanceOutcome, Currency, OnFreeBalanceZero, OnUnbalanced, TryDrop,
|
||||
UpdateBalanceOutcome, Currency, OnFreeBalanceZero, OnReapAccount, OnUnbalanced, TryDrop,
|
||||
WithdrawReason, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement,
|
||||
Imbalance, SignedImbalance, ReservableCurrency, Get, VestingCurrency,
|
||||
},
|
||||
@@ -198,6 +198,12 @@ pub trait Subtrait<I: Instance = DefaultInstance>: frame_system::Trait {
|
||||
/// Gives a chance to clean up resources associated with the given account.
|
||||
type OnFreeBalanceZero: OnFreeBalanceZero<Self::AccountId>;
|
||||
|
||||
/// A function that is invoked when the free-balance and the reserved-balance has fallen below
|
||||
/// the existential deposit and both have been reduced to zero.
|
||||
///
|
||||
/// All resources should be cleaned up all resources associated with the given account.
|
||||
type OnReapAccount: OnReapAccount<Self::AccountId>;
|
||||
|
||||
/// Handler for when a new account is created.
|
||||
type OnNewAccount: OnNewAccount<Self::AccountId>;
|
||||
|
||||
@@ -222,6 +228,12 @@ pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {
|
||||
/// Gives a chance to clean up resources associated with the given account.
|
||||
type OnFreeBalanceZero: OnFreeBalanceZero<Self::AccountId>;
|
||||
|
||||
/// A function that is invoked when the free-balance and the reserved-balance has fallen below
|
||||
/// the existential deposit and both have been reduced to zero.
|
||||
///
|
||||
/// All resources should be cleaned up all resources associated with the given account.
|
||||
type OnReapAccount: OnReapAccount<Self::AccountId>;
|
||||
|
||||
/// Handler for when a new account is created.
|
||||
type OnNewAccount: OnNewAccount<Self::AccountId>;
|
||||
|
||||
@@ -248,6 +260,7 @@ pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {
|
||||
impl<T: Trait<I>, I: Instance> Subtrait<I> for T {
|
||||
type Balance = T::Balance;
|
||||
type OnFreeBalanceZero = T::OnFreeBalanceZero;
|
||||
type OnReapAccount = T::OnReapAccount;
|
||||
type OnNewAccount = T::OnNewAccount;
|
||||
type ExistentialDeposit = T::ExistentialDeposit;
|
||||
type TransferFee = T::TransferFee;
|
||||
@@ -597,7 +610,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
|
||||
///
|
||||
/// This just removes the nonce and leaves an event.
|
||||
fn reap_account(who: &T::AccountId, dust: T::Balance) {
|
||||
<frame_system::AccountNonce<T>>::remove(who);
|
||||
T::OnReapAccount::on_reap_account(who);
|
||||
Self::deposit_event(RawEvent::ReapedAccount(who.clone(), dust));
|
||||
}
|
||||
|
||||
@@ -850,6 +863,7 @@ impl<T: Subtrait<I>, I: Instance> frame_system::Trait for ElevatedTrait<T, I> {
|
||||
impl<T: Subtrait<I>, I: Instance> Trait<I> for ElevatedTrait<T, I> {
|
||||
type Balance = T::Balance;
|
||||
type OnFreeBalanceZero = T::OnFreeBalanceZero;
|
||||
type OnReapAccount = T::OnReapAccount;
|
||||
type OnNewAccount = T::OnNewAccount;
|
||||
type Event = ();
|
||||
type TransferPayment = ();
|
||||
|
||||
@@ -93,6 +93,7 @@ impl pallet_transaction_payment::Trait for Test {
|
||||
impl Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = ();
|
||||
type DustRemoval = ();
|
||||
|
||||
@@ -122,6 +122,7 @@ impl frame_system::Trait for Test {
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = Contract;
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = MetaEvent;
|
||||
type DustRemoval = ();
|
||||
|
||||
@@ -1205,6 +1205,7 @@ mod tests {
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = ();
|
||||
type TransferPayment = ();
|
||||
|
||||
@@ -824,6 +824,7 @@ mod tests {
|
||||
type Balance = u64;
|
||||
type OnNewAccount = ();
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type Event = Event;
|
||||
type TransferPayment = ();
|
||||
type DustRemoval = ();
|
||||
|
||||
@@ -65,6 +65,7 @@ impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnNewAccount = ();
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type Event = Event;
|
||||
type TransferPayment = ();
|
||||
type DustRemoval = ();
|
||||
|
||||
@@ -695,6 +695,7 @@ mod tests {
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = ();
|
||||
type TransferPayment = ();
|
||||
@@ -706,6 +707,7 @@ mod tests {
|
||||
impl Trait for Test {
|
||||
type Event = ();
|
||||
}
|
||||
type System = frame_system::Module<Test>;
|
||||
type Example = Module<Test>;
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
|
||||
@@ -425,6 +425,7 @@ mod tests {
|
||||
impl pallet_balances::Trait for Runtime {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = MetaEvent;
|
||||
type DustRemoval = ();
|
||||
|
||||
@@ -921,6 +921,7 @@ mod tests {
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = ();
|
||||
type TransferPayment = ();
|
||||
@@ -950,6 +951,7 @@ mod tests {
|
||||
type RegistrarOrigin = EnsureSignedBy<One, u64>;
|
||||
type ForceOrigin = EnsureSignedBy<Two, u64>;
|
||||
}
|
||||
type System = frame_system::Module<Test>;
|
||||
type Balances = pallet_balances::Module<Test>;
|
||||
type Identity = Module<Test>;
|
||||
|
||||
|
||||
@@ -294,6 +294,7 @@ mod tests {
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = ();
|
||||
type TransferPayment = ();
|
||||
@@ -319,6 +320,7 @@ mod tests {
|
||||
type MinLength = MinLength;
|
||||
type MaxLength = MaxLength;
|
||||
}
|
||||
type System = frame_system::Module<Test>;
|
||||
type Balances = pallet_balances::Module<Test>;
|
||||
type Nicks = Module<Test>;
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ impl frame_system::Trait for Test {
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = ();
|
||||
type TransferPayment = ();
|
||||
@@ -118,13 +119,16 @@ impl Trait for Test {
|
||||
type KickOrigin = EnsureSignedBy<KickOrigin, u64>;
|
||||
type MembershipInitialized = TestChangeMembers;
|
||||
type MembershipChanged = TestChangeMembers;
|
||||
type Currency = pallet_balances::Module<Self>;
|
||||
type Currency = Balances;
|
||||
type CandidateDeposit = CandidateDeposit;
|
||||
type Period = Period;
|
||||
type Score = u64;
|
||||
type ScoreOrigin = EnsureSignedBy<ScoreOrigin, u64>;
|
||||
}
|
||||
|
||||
type System = frame_system::Module<Test>;
|
||||
type Balances = pallet_balances::Module<Test>;
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mockup.
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
|
||||
@@ -146,6 +146,7 @@ parameter_types! {
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = Balance;
|
||||
type OnFreeBalanceZero = Staking;
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = ();
|
||||
type TransferPayment = ();
|
||||
|
||||
@@ -67,10 +67,17 @@ pub trait Contains<T: Ord> {
|
||||
/// The account with the given id was killed.
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
pub trait OnFreeBalanceZero<AccountId> {
|
||||
/// The account was the given id was killed.
|
||||
/// The account with the given id was killed.
|
||||
fn on_free_balance_zero(who: &AccountId);
|
||||
}
|
||||
|
||||
/// The account with the given id was reaped.
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
pub trait OnReapAccount<AccountId> {
|
||||
/// The account with the given id was reaped.
|
||||
fn on_reap_account(who: &AccountId);
|
||||
}
|
||||
|
||||
/// Outcome of a balance update.
|
||||
pub enum UpdateBalanceOutcome {
|
||||
/// Account balance was simply updated.
|
||||
|
||||
@@ -113,7 +113,7 @@ use sp_runtime::{
|
||||
use sp_core::storage::well_known_keys;
|
||||
use frame_support::{
|
||||
decl_module, decl_event, decl_storage, decl_error, storage, Parameter,
|
||||
traits::{Contains, Get, ModuleToIndex},
|
||||
traits::{Contains, Get, ModuleToIndex, OnReapAccount},
|
||||
weights::{Weight, DispatchInfo, DispatchClass, SimpleDispatchInfo},
|
||||
};
|
||||
use codec::{Encode, Decode};
|
||||
@@ -789,6 +789,13 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> OnReapAccount<T::AccountId> for Module<T> {
|
||||
/// Remove the nonce for the account. Account is considered fully removed from the system.
|
||||
fn on_reap_account(who: &T::AccountId) {
|
||||
<AccountNonce<T>>::remove(who);
|
||||
}
|
||||
}
|
||||
|
||||
/// resource limit check.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
|
||||
pub struct CheckWeight<T: Trait + Send + Sync>(PhantomData<T>);
|
||||
|
||||
@@ -311,6 +311,7 @@ mod tests {
|
||||
impl pallet_balances::Trait for Runtime {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = ();
|
||||
type TransferPayment = ();
|
||||
|
||||
@@ -766,6 +766,7 @@ mod tests {
|
||||
type Balance = u64;
|
||||
type OnNewAccount = ();
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type Event = ();
|
||||
type TransferPayment = ();
|
||||
type DustRemoval = ();
|
||||
|
||||
@@ -698,6 +698,7 @@ mod tests {
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = ();
|
||||
type OnReapAccount = System;
|
||||
type OnNewAccount = ();
|
||||
type Event = TestEvent;
|
||||
type TransferPayment = ();
|
||||
@@ -719,6 +720,7 @@ mod tests {
|
||||
type MultisigDepositFactor = MultisigDepositFactor;
|
||||
type MaxSignatories = MaxSignatories;
|
||||
}
|
||||
type System = frame_system::Module<Test>;
|
||||
type Balances = pallet_balances::Module<Test>;
|
||||
type Utility = Module<Test>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user