Skip to content

Commit 68ab943

Browse files
juangiriniggwpezKiChjangchevdor
authored
Remove deprecated pallet_balances's set_balance_deprecated and transfer dispatchables (#1226)
* remove deprecated dispatchables * update test * update tests * update tests * add prdocs * add prdoc * Update docs/prdoc/pr_1226.prdoc Co-authored-by: Chevdor <[email protected]> * move prdoc file --------- Co-authored-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Keith Yeung <[email protected]> Co-authored-by: Chevdor <[email protected]>
1 parent 50de035 commit 68ab943

File tree

7 files changed

+40
-76
lines changed

7 files changed

+40
-76
lines changed

prdoc/pr_1226.prdoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
title: Removed deprecated `Balances::transfer` and `Balances::set_balance_deprecated` functions.
2+
3+
doc:
4+
- audience: Builder
5+
description: The Balances pallet's dispatchables `set_balance_deprecated` and `transfer` were deprecated in [paritytech/substrate#12951](https://github.com/paritytech/substrate/pull/12951) and have now been removed.
6+
notes:
7+
- Use `set_balance_deprecated` instead `force_set_balance` and `transfer_allow_death` instead of `transfer`.
8+
9+
migrations:
10+
db: []
11+
12+
runtime: []
13+
14+
crates:
15+
- name: pallet-balances
16+
17+
host_functions: []

substrate/frame/asset-conversion/src/tests.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,11 @@ fn cannot_block_pool_creation() {
13891389
let pool_account =
13901390
AssetConversion::get_pool_account(&AssetConversion::get_pool_id(token_2, token_1));
13911391
// And transfers the ED to that pool account
1392-
assert_ok!(Balances::transfer(RuntimeOrigin::signed(attacker), pool_account, ed));
1392+
assert_ok!(Balances::transfer_allow_death(
1393+
RuntimeOrigin::signed(attacker),
1394+
pool_account,
1395+
ed
1396+
));
13931397
// Then, the attacker creates 14 tokens and sends one of each to the pool account
13941398
for i in 10..25 {
13951399
create_tokens(attacker, vec![NativeOrAssetId::Asset(i)]);

substrate/frame/balances/src/lib.rs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -563,53 +563,6 @@ pub mod pallet {
563563
Ok(())
564564
}
565565

566-
/// Set the regular balance of a given account; it also takes a reserved balance but this
567-
/// must be the same as the account's current reserved balance.
568-
///
569-
/// The dispatch origin for this call is `root`.
570-
///
571-
/// WARNING: This call is DEPRECATED! Use `force_set_balance` instead.
572-
#[pallet::call_index(1)]
573-
#[pallet::weight(
574-
T::WeightInfo::force_set_balance_creating() // Creates a new account.
575-
.max(T::WeightInfo::force_set_balance_killing()) // Kills an existing account.
576-
)]
577-
pub fn set_balance_deprecated(
578-
origin: OriginFor<T>,
579-
who: AccountIdLookupOf<T>,
580-
#[pallet::compact] new_free: T::Balance,
581-
#[pallet::compact] old_reserved: T::Balance,
582-
) -> DispatchResult {
583-
ensure_root(origin)?;
584-
let who = T::Lookup::lookup(who)?;
585-
let existential_deposit = Self::ed();
586-
587-
let wipeout = new_free < existential_deposit;
588-
let new_free = if wipeout { Zero::zero() } else { new_free };
589-
590-
// First we try to modify the account's balance to the forced balance.
591-
let old_free = Self::try_mutate_account_handling_dust(
592-
&who,
593-
|account, _is_new| -> Result<T::Balance, DispatchError> {
594-
let old_free = account.free;
595-
ensure!(account.reserved == old_reserved, TokenError::Unsupported);
596-
account.free = new_free;
597-
Ok(old_free)
598-
},
599-
)?;
600-
601-
// This will adjust the total issuance, which was not done by the `mutate_account`
602-
// above.
603-
if new_free > old_free {
604-
mem::drop(PositiveImbalance::<T, I>::new(new_free - old_free));
605-
} else if new_free < old_free {
606-
mem::drop(NegativeImbalance::<T, I>::new(old_free - new_free));
607-
}
608-
609-
Self::deposit_event(Event::BalanceSet { who, free: new_free });
610-
Ok(())
611-
}
612-
613566
/// Exactly as `transfer_allow_death`, except the origin must be root and the source account
614567
/// may be specified.
615568
#[pallet::call_index(2)]
@@ -730,22 +683,6 @@ pub mod pallet {
730683
}
731684
}
732685

733-
/// Alias for `transfer_allow_death`, provided only for name-wise compatibility.
734-
///
735-
/// WARNING: DEPRECATED! Will be released in approximately 3 months.
736-
#[pallet::call_index(7)]
737-
#[pallet::weight(T::WeightInfo::transfer_allow_death())]
738-
pub fn transfer(
739-
origin: OriginFor<T>,
740-
dest: AccountIdLookupOf<T>,
741-
#[pallet::compact] value: T::Balance,
742-
) -> DispatchResult {
743-
let source = ensure_signed(origin)?;
744-
let dest = T::Lookup::lookup(dest)?;
745-
<Self as fungible::Mutate<_>>::transfer(&source, &dest, value, Expendable)?;
746-
Ok(())
747-
}
748-
749686
/// Set the regular balance of a given account.
750687
///
751688
/// The dispatch origin for this call is `root`.

substrate/frame/safe-mode/src/mock.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
122122
match self {
123123
ProxyType::Any => true,
124124
ProxyType::JustTransfer => {
125-
matches!(c, RuntimeCall::Balances(pallet_balances::Call::transfer { .. }))
125+
matches!(
126+
c,
127+
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. })
128+
)
126129
},
127130
ProxyType::JustUtility => matches!(c, RuntimeCall::Utility { .. }),
128131
}

substrate/frame/safe-mode/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ fn fails_when_explicit_origin_required() {
605605
}
606606

607607
fn call_transfer() -> RuntimeCall {
608-
RuntimeCall::Balances(pallet_balances::Call::transfer { dest: 1, value: 1 })
608+
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { dest: 1, value: 1 })
609609
}
610610

611611
fn signed(who: u64) -> RuntimeOrigin {

substrate/frame/tx-pause/src/mock.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
120120
match self {
121121
ProxyType::Any => true,
122122
ProxyType::JustTransfer => {
123-
matches!(c, RuntimeCall::Balances(pallet_balances::Call::transfer { .. }))
123+
matches!(
124+
c,
125+
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. })
126+
)
124127
},
125128
ProxyType::JustUtility => matches!(c, RuntimeCall::Utility { .. }),
126129
}

substrate/frame/tx-pause/src/tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn can_pause_specific_call() {
3232

3333
assert_ok!(TxPause::pause(
3434
RuntimeOrigin::signed(mock::PauseOrigin::get()),
35-
full_name::<Test>(b"Balances", b"transfer")
35+
full_name::<Test>(b"Balances", b"transfer_allow_death")
3636
));
3737

3838
assert_err!(
@@ -69,7 +69,7 @@ fn can_unpause_specific_call() {
6969
new_test_ext().execute_with(|| {
7070
assert_ok!(TxPause::pause(
7171
RuntimeOrigin::signed(mock::PauseOrigin::get()),
72-
full_name::<Test>(b"Balances", b"transfer"),
72+
full_name::<Test>(b"Balances", b"transfer_allow_death"),
7373
));
7474
assert_err!(
7575
call_transfer(2, 1).dispatch(RuntimeOrigin::signed(2)),
@@ -78,7 +78,7 @@ fn can_unpause_specific_call() {
7878

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

9393
assert_ok!(TxPause::pause(
9494
RuntimeOrigin::signed(mock::PauseOrigin::get()),
95-
full_name::<Test>(b"Balances", b"transfer"),
95+
full_name::<Test>(b"Balances", b"transfer_allow_death"),
9696
));
9797

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

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

153153
assert_ok!(TxPause::pause(
154154
RuntimeOrigin::signed(mock::PauseOrigin::get()),
155-
full_name::<Test>(b"Balances", b"transfer"),
155+
full_name::<Test>(b"Balances", b"transfer_allow_death"),
156156
));
157157

158158
assert_ok!(call_transfer_keep_alive(3, 1).dispatch(RuntimeOrigin::signed(3)));
@@ -181,13 +181,13 @@ fn fails_to_pause_already_paused_pallet() {
181181
new_test_ext().execute_with(|| {
182182
assert_ok!(TxPause::pause(
183183
RuntimeOrigin::signed(mock::PauseOrigin::get()),
184-
full_name::<Test>(b"Balances", b"transfer"),
184+
full_name::<Test>(b"Balances", b"transfer_allow_death"),
185185
));
186186

187187
assert_noop!(
188188
TxPause::pause(
189189
RuntimeOrigin::signed(mock::PauseOrigin::get()),
190-
full_name::<Test>(b"Balances", b"transfer"),
190+
full_name::<Test>(b"Balances", b"transfer_allow_death"),
191191
),
192192
Error::<Test>::IsPaused
193193
);
@@ -208,7 +208,7 @@ fn fails_to_unpause_not_paused_pallet() {
208208
}
209209

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

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

0 commit comments

Comments
 (0)