Skip to content

Commit

Permalink
[FRAME] pallet_asset_tx_payment: replace AssetId bound from `Copy…
Browse files Browse the repository at this point in the history
…` to `Clone` (#7194)

closes #6911
  • Loading branch information
dastansam authored Jan 16, 2025
1 parent 64abc74 commit f7baa84
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
15 changes: 15 additions & 0 deletions prdoc/pr_7194.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: '[FRAME] `pallet_asset_tx_payment`: replace `AssetId` bound from `Copy` to `Clone`'

doc:
- audience: Runtime Dev
description: |
`OnChargeAssetTransaction`'s associated type `AssetId` is bounded by `Copy` which makes it impossible
to use `staging_xcm::v4::Location` as `AssetId`. This PR bounds `AssetId` to `Clone` instead, which is
more lenient.

crates:
- name: pallet-asset-tx-payment
bump: minor
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ where
debug_assert!(self.tip <= fee, "tip should be included in the computed fee");
if fee.is_zero() {
Ok((fee, InitialPayment::Nothing))
} else if let Some(asset_id) = self.asset_id {
} else if let Some(asset_id) = self.asset_id.clone() {
T::OnChargeAssetTransaction::withdraw_fee(
who,
call,
Expand Down Expand Up @@ -233,7 +233,7 @@ where
debug_assert!(self.tip <= fee, "tip should be included in the computed fee");
if fee.is_zero() {
Ok(())
} else if let Some(asset_id) = self.asset_id {
} else if let Some(asset_id) = self.asset_id.clone() {
T::OnChargeAssetTransaction::can_withdraw_fee(
who,
call,
Expand Down Expand Up @@ -358,7 +358,7 @@ where
tip,
who,
initial_payment,
asset_id: self.asset_id,
asset_id: self.asset_id.clone(),
weight: self.weight(call),
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub trait OnChargeAssetTransaction<T: Config> {
/// The underlying integer type in which fees are calculated.
type Balance: Balance;
/// The type used to identify the assets used for transaction payment.
type AssetId: FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo;
type AssetId: FullCodec + Clone + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo;
/// The type used to store the intermediate values between pre- and post-dispatch.
type LiquidityInfo;

Expand Down Expand Up @@ -112,7 +112,7 @@ where
T: Config,
CON: ConversionToAssetBalance<BalanceOf<T>, AssetIdOf<T>, AssetBalanceOf<T>>,
HC: HandleCredit<T::AccountId, T::Fungibles>,
AssetIdOf<T>: FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo,
AssetIdOf<T>: FullCodec + Clone + MaybeSerializeDeserialize + Debug + Default + Eq + TypeInfo,
{
type Balance = BalanceOf<T>;
type AssetId = AssetIdOf<T>;
Expand All @@ -133,11 +133,14 @@ where
// less than one (e.g. 0.5) but gets rounded down by integer division we introduce a minimum
// fee.
let min_converted_fee = if fee.is_zero() { Zero::zero() } else { One::one() };
let converted_fee = CON::to_asset_balance(fee, asset_id)
let converted_fee = CON::to_asset_balance(fee, asset_id.clone())
.map_err(|_| TransactionValidityError::from(InvalidTransaction::Payment))?
.max(min_converted_fee);
let can_withdraw =
<T::Fungibles as Inspect<T::AccountId>>::can_withdraw(asset_id, who, converted_fee);
let can_withdraw = <T::Fungibles as Inspect<T::AccountId>>::can_withdraw(
asset_id.clone(),
who,
converted_fee,
);
if can_withdraw != WithdrawConsequence::Success {
return Err(InvalidTransaction::Payment.into())
}
Expand Down Expand Up @@ -167,7 +170,7 @@ where
// less than one (e.g. 0.5) but gets rounded down by integer division we introduce a minimum
// fee.
let min_converted_fee = if fee.is_zero() { Zero::zero() } else { One::one() };
let converted_fee = CON::to_asset_balance(fee, asset_id)
let converted_fee = CON::to_asset_balance(fee, asset_id.clone())
.map_err(|_| TransactionValidityError::from(InvalidTransaction::Payment))?
.max(min_converted_fee);
let can_withdraw =
Expand Down

0 comments on commit f7baa84

Please sign in to comment.