Skip to content
Snippets Groups Projects
Unverified Commit f7baa84f authored by Dastan's avatar Dastan Committed by GitHub
Browse files

[FRAME] `pallet_asset_tx_payment`: replace `AssetId` bound from `Copy` to `Clone` (#7194)

closes https://github.com/paritytech/polkadot-sdk/issues/6911
parent 64abc745
No related merge requests found
Pipeline #512180 waiting for manual action with stages
in 50 minutes and 16 seconds
# 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
......@@ -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,
......@@ -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,
......@@ -358,7 +358,7 @@ where
tip,
who,
initial_payment,
asset_id: self.asset_id,
asset_id: self.asset_id.clone(),
weight: self.weight(call),
})
},
......
......@@ -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;
......@@ -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>;
......@@ -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())
}
......@@ -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 =
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment