mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 01:01:04 +00:00
Implement transfer_all in Balances Pallet (#9018)
* transfer_all * benchmark * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * update * add note * typo Co-authored-by: Parity Bot <admin@parity.io> Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
@@ -369,6 +369,39 @@ pub mod pallet {
|
||||
<Self as Currency<_>>::transfer(&transactor, &dest, value, KeepAlive)?;
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
/// Transfer the entire transferable balance from the caller account.
|
||||
///
|
||||
/// NOTE: This function only attempts to transfer _transferable_ balances. This means that
|
||||
/// any locked, reserved, or existential deposits (when `keep_alive` is `true`), will not be
|
||||
/// transferred by this function. To ensure that this function results in a killed account,
|
||||
/// you might need to prepare the account by removing any reference counters, storage
|
||||
/// deposits, etc...
|
||||
///
|
||||
/// The dispatch origin of this call must be Signed.
|
||||
///
|
||||
/// - `dest`: The recipient of the transfer.
|
||||
/// - `keep_alive`: A boolean to determine if the `transfer_all` operation should send all
|
||||
/// of the funds the account has, causing the sender account to be killed (false), or
|
||||
/// transfer everything except at least the existential deposit, which will guarantee to
|
||||
/// keep the sender account alive (true).
|
||||
/// # <weight>
|
||||
/// - O(1). Just like transfer, but reading the user's transferable balance first.
|
||||
/// #</weight>
|
||||
#[pallet::weight(T::WeightInfo::transfer_all())]
|
||||
pub fn transfer_all(
|
||||
origin: OriginFor<T>,
|
||||
dest: <T::Lookup as StaticLookup>::Source,
|
||||
keep_alive: bool,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
use fungible::Inspect;
|
||||
let transactor = ensure_signed(origin)?;
|
||||
let reducible_balance = Self::reducible_balance(&transactor, keep_alive);
|
||||
let dest = T::Lookup::lookup(dest)?;
|
||||
let keep_alive = if keep_alive { KeepAlive } else { AllowDeath };
|
||||
<Self as Currency<_>>::transfer(&transactor, &dest, reducible_balance, keep_alive.into())?;
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
@@ -1696,7 +1729,7 @@ impl<T: Config<I>, I: 'static> NamedReservableCurrency<T::AccountId> for Pallet<
|
||||
/// Is a no-op if value to be reserved is zero.
|
||||
fn reserve_named(id: &Self::ReserveIdentifier, who: &T::AccountId, value: Self::Balance) -> DispatchResult {
|
||||
if value.is_zero() { return Ok(()) }
|
||||
|
||||
|
||||
Reserves::<T, I>::try_mutate(who, |reserves| -> DispatchResult {
|
||||
match reserves.binary_search_by_key(id, |data| data.id) {
|
||||
Ok(index) => {
|
||||
|
||||
Reference in New Issue
Block a user