Skip to content

Commit

Permalink
Remove deprecated pallet_balances's set_balance_deprecated and `t…
Browse files Browse the repository at this point in the history
…ransfer` dispatchables (paritytech#1226)

* remove deprecated dispatchables

* update test

* update tests

* update tests

* add prdocs

* add prdoc

* Update docs/prdoc/pr_1226.prdoc

Co-authored-by: Chevdor <chevdor@users.noreply.github.com>

* move prdoc file

---------

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Chevdor <chevdor@users.noreply.github.com>
  • Loading branch information
4 people authored Sep 6, 2023
1 parent 608455e commit 7df8c6e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 76 deletions.
6 changes: 5 additions & 1 deletion substrate/frame/asset-conversion/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,11 @@ fn cannot_block_pool_creation() {
let pool_account =
AssetConversion::get_pool_account(&AssetConversion::get_pool_id(token_2, token_1));
// And transfers the ED to that pool account
assert_ok!(Balances::transfer(RuntimeOrigin::signed(attacker), pool_account, ed));
assert_ok!(Balances::transfer_allow_death(
RuntimeOrigin::signed(attacker),
pool_account,
ed
));
// Then, the attacker creates 14 tokens and sends one of each to the pool account
for i in 10..25 {
create_tokens(attacker, vec![NativeOrAssetId::Asset(i)]);
Expand Down
63 changes: 0 additions & 63 deletions substrate/frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,53 +563,6 @@ pub mod pallet {
Ok(())
}

/// Set the regular balance of a given account; it also takes a reserved balance but this
/// must be the same as the account's current reserved balance.
///
/// The dispatch origin for this call is `root`.
///
/// WARNING: This call is DEPRECATED! Use `force_set_balance` instead.
#[pallet::call_index(1)]
#[pallet::weight(
T::WeightInfo::force_set_balance_creating() // Creates a new account.
.max(T::WeightInfo::force_set_balance_killing()) // Kills an existing account.
)]
pub fn set_balance_deprecated(
origin: OriginFor<T>,
who: AccountIdLookupOf<T>,
#[pallet::compact] new_free: T::Balance,
#[pallet::compact] old_reserved: T::Balance,
) -> DispatchResult {
ensure_root(origin)?;
let who = T::Lookup::lookup(who)?;
let existential_deposit = Self::ed();

let wipeout = new_free < existential_deposit;
let new_free = if wipeout { Zero::zero() } else { new_free };

// First we try to modify the account's balance to the forced balance.
let old_free = Self::try_mutate_account_handling_dust(
&who,
|account, _is_new| -> Result<T::Balance, DispatchError> {
let old_free = account.free;
ensure!(account.reserved == old_reserved, TokenError::Unsupported);
account.free = new_free;
Ok(old_free)
},
)?;

// This will adjust the total issuance, which was not done by the `mutate_account`
// above.
if new_free > old_free {
mem::drop(PositiveImbalance::<T, I>::new(new_free - old_free));
} else if new_free < old_free {
mem::drop(NegativeImbalance::<T, I>::new(old_free - new_free));
}

Self::deposit_event(Event::BalanceSet { who, free: new_free });
Ok(())
}

/// Exactly as `transfer_allow_death`, except the origin must be root and the source account
/// may be specified.
#[pallet::call_index(2)]
Expand Down Expand Up @@ -730,22 +683,6 @@ pub mod pallet {
}
}

/// Alias for `transfer_allow_death`, provided only for name-wise compatibility.
///
/// WARNING: DEPRECATED! Will be released in approximately 3 months.
#[pallet::call_index(7)]
#[pallet::weight(T::WeightInfo::transfer_allow_death())]
pub fn transfer(
origin: OriginFor<T>,
dest: AccountIdLookupOf<T>,
#[pallet::compact] value: T::Balance,
) -> DispatchResult {
let source = ensure_signed(origin)?;
let dest = T::Lookup::lookup(dest)?;
<Self as fungible::Mutate<_>>::transfer(&source, &dest, value, Expendable)?;
Ok(())
}

/// Set the regular balance of a given account.
///
/// The dispatch origin for this call is `root`.
Expand Down
5 changes: 4 additions & 1 deletion substrate/frame/safe-mode/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
match self {
ProxyType::Any => true,
ProxyType::JustTransfer => {
matches!(c, RuntimeCall::Balances(pallet_balances::Call::transfer { .. }))
matches!(
c,
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. })
)
},
ProxyType::JustUtility => matches!(c, RuntimeCall::Utility { .. }),
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/safe-mode/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ fn fails_when_explicit_origin_required() {
}

fn call_transfer() -> RuntimeCall {
RuntimeCall::Balances(pallet_balances::Call::transfer { dest: 1, value: 1 })
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { dest: 1, value: 1 })
}

fn signed(who: u64) -> RuntimeOrigin {
Expand Down
5 changes: 4 additions & 1 deletion substrate/frame/tx-pause/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
match self {
ProxyType::Any => true,
ProxyType::JustTransfer => {
matches!(c, RuntimeCall::Balances(pallet_balances::Call::transfer { .. }))
matches!(
c,
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. })
)
},
ProxyType::JustUtility => matches!(c, RuntimeCall::Utility { .. }),
}
Expand Down
18 changes: 9 additions & 9 deletions substrate/frame/tx-pause/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn can_pause_specific_call() {

assert_ok!(TxPause::pause(
RuntimeOrigin::signed(mock::PauseOrigin::get()),
full_name::<Test>(b"Balances", b"transfer")
full_name::<Test>(b"Balances", b"transfer_allow_death")
));

assert_err!(
Expand Down Expand Up @@ -69,7 +69,7 @@ fn can_unpause_specific_call() {
new_test_ext().execute_with(|| {
assert_ok!(TxPause::pause(
RuntimeOrigin::signed(mock::PauseOrigin::get()),
full_name::<Test>(b"Balances", b"transfer"),
full_name::<Test>(b"Balances", b"transfer_allow_death"),
));
assert_err!(
call_transfer(2, 1).dispatch(RuntimeOrigin::signed(2)),
Expand All @@ -78,7 +78,7 @@ fn can_unpause_specific_call() {

assert_ok!(TxPause::unpause(
RuntimeOrigin::signed(mock::UnpauseOrigin::get()),
full_name::<Test>(b"Balances", b"transfer"),
full_name::<Test>(b"Balances", b"transfer_allow_death"),
));
assert_ok!(call_transfer(4, 1).dispatch(RuntimeOrigin::signed(0)));
});
Expand All @@ -92,7 +92,7 @@ fn can_filter_balance_in_batch_when_paused() {

assert_ok!(TxPause::pause(
RuntimeOrigin::signed(mock::PauseOrigin::get()),
full_name::<Test>(b"Balances", b"transfer"),
full_name::<Test>(b"Balances", b"transfer_allow_death"),
));

assert_ok!(batch_call.clone().dispatch(RuntimeOrigin::signed(0)));
Expand All @@ -111,7 +111,7 @@ fn can_filter_balance_in_proxy_when_paused() {
new_test_ext().execute_with(|| {
assert_ok!(TxPause::pause(
RuntimeOrigin::signed(mock::PauseOrigin::get()),
full_name::<Test>(b"Balances", b"transfer"),
full_name::<Test>(b"Balances", b"transfer_allow_death"),
));

assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::JustTransfer, 0));
Expand Down Expand Up @@ -152,7 +152,7 @@ fn fails_to_pause_unpausable_call_when_other_call_is_paused() {

assert_ok!(TxPause::pause(
RuntimeOrigin::signed(mock::PauseOrigin::get()),
full_name::<Test>(b"Balances", b"transfer"),
full_name::<Test>(b"Balances", b"transfer_allow_death"),
));

assert_ok!(call_transfer_keep_alive(3, 1).dispatch(RuntimeOrigin::signed(3)));
Expand Down Expand Up @@ -181,13 +181,13 @@ fn fails_to_pause_already_paused_pallet() {
new_test_ext().execute_with(|| {
assert_ok!(TxPause::pause(
RuntimeOrigin::signed(mock::PauseOrigin::get()),
full_name::<Test>(b"Balances", b"transfer"),
full_name::<Test>(b"Balances", b"transfer_allow_death"),
));

assert_noop!(
TxPause::pause(
RuntimeOrigin::signed(mock::PauseOrigin::get()),
full_name::<Test>(b"Balances", b"transfer"),
full_name::<Test>(b"Balances", b"transfer_allow_death"),
),
Error::<Test>::IsPaused
);
Expand All @@ -208,7 +208,7 @@ fn fails_to_unpause_not_paused_pallet() {
}

pub fn call_transfer(dest: u64, value: u64) -> RuntimeCall {
RuntimeCall::Balances(pallet_balances::Call::transfer { dest, value })
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { dest, value })
}

pub fn call_transfer_keep_alive(dest: u64, value: u64) -> RuntimeCall {
Expand Down

0 comments on commit 7df8c6e

Please sign in to comment.