Skip to content

Commit f7baa84

Browse files
authored
[FRAME] pallet_asset_tx_payment: replace AssetId bound from Copy to Clone (#7194)
closes #6911
1 parent 64abc74 commit f7baa84

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

prdoc/pr_7194.prdoc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: '[FRAME] `pallet_asset_tx_payment`: replace `AssetId` bound from `Copy` to `Clone`'
5+
6+
doc:
7+
- audience: Runtime Dev
8+
description: |
9+
`OnChargeAssetTransaction`'s associated type `AssetId` is bounded by `Copy` which makes it impossible
10+
to use `staging_xcm::v4::Location` as `AssetId`. This PR bounds `AssetId` to `Clone` instead, which is
11+
more lenient.
12+
13+
crates:
14+
- name: pallet-asset-tx-payment
15+
bump: minor

substrate/frame/transaction-payment/asset-tx-payment/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ where
202202
debug_assert!(self.tip <= fee, "tip should be included in the computed fee");
203203
if fee.is_zero() {
204204
Ok((fee, InitialPayment::Nothing))
205-
} else if let Some(asset_id) = self.asset_id {
205+
} else if let Some(asset_id) = self.asset_id.clone() {
206206
T::OnChargeAssetTransaction::withdraw_fee(
207207
who,
208208
call,
@@ -233,7 +233,7 @@ where
233233
debug_assert!(self.tip <= fee, "tip should be included in the computed fee");
234234
if fee.is_zero() {
235235
Ok(())
236-
} else if let Some(asset_id) = self.asset_id {
236+
} else if let Some(asset_id) = self.asset_id.clone() {
237237
T::OnChargeAssetTransaction::can_withdraw_fee(
238238
who,
239239
call,
@@ -358,7 +358,7 @@ where
358358
tip,
359359
who,
360360
initial_payment,
361-
asset_id: self.asset_id,
361+
asset_id: self.asset_id.clone(),
362362
weight: self.weight(call),
363363
})
364364
},

substrate/frame/transaction-payment/asset-tx-payment/src/payment.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub trait OnChargeAssetTransaction<T: Config> {
4040
/// The underlying integer type in which fees are calculated.
4141
type Balance: Balance;
4242
/// The type used to identify the assets used for transaction payment.
43-
type AssetId: FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo;
43+
type AssetId: FullCodec + Clone + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo;
4444
/// The type used to store the intermediate values between pre- and post-dispatch.
4545
type LiquidityInfo;
4646

@@ -112,7 +112,7 @@ where
112112
T: Config,
113113
CON: ConversionToAssetBalance<BalanceOf<T>, AssetIdOf<T>, AssetBalanceOf<T>>,
114114
HC: HandleCredit<T::AccountId, T::Fungibles>,
115-
AssetIdOf<T>: FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo,
115+
AssetIdOf<T>: FullCodec + Clone + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo,
116116
{
117117
type Balance = BalanceOf<T>;
118118
type AssetId = AssetIdOf<T>;
@@ -133,11 +133,14 @@ where
133133
// less than one (e.g. 0.5) but gets rounded down by integer division we introduce a minimum
134134
// fee.
135135
let min_converted_fee = if fee.is_zero() { Zero::zero() } else { One::one() };
136-
let converted_fee = CON::to_asset_balance(fee, asset_id)
136+
let converted_fee = CON::to_asset_balance(fee, asset_id.clone())
137137
.map_err(|_| TransactionValidityError::from(InvalidTransaction::Payment))?
138138
.max(min_converted_fee);
139-
let can_withdraw =
140-
<T::Fungibles as Inspect<T::AccountId>>::can_withdraw(asset_id, who, converted_fee);
139+
let can_withdraw = <T::Fungibles as Inspect<T::AccountId>>::can_withdraw(
140+
asset_id.clone(),
141+
who,
142+
converted_fee,
143+
);
141144
if can_withdraw != WithdrawConsequence::Success {
142145
return Err(InvalidTransaction::Payment.into())
143146
}
@@ -167,7 +170,7 @@ where
167170
// less than one (e.g. 0.5) but gets rounded down by integer division we introduce a minimum
168171
// fee.
169172
let min_converted_fee = if fee.is_zero() { Zero::zero() } else { One::one() };
170-
let converted_fee = CON::to_asset_balance(fee, asset_id)
173+
let converted_fee = CON::to_asset_balance(fee, asset_id.clone())
171174
.map_err(|_| TransactionValidityError::from(InvalidTransaction::Payment))?
172175
.max(min_converted_fee);
173176
let can_withdraw =

0 commit comments

Comments
 (0)