Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fee and tip represented as asset ID inside AssetTxFeePaid #13083

Merged
merged 7 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions frame/transaction-payment/asset-tx-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ pub mod pallet {
/// has been paid by `who` in an asset `asset_id`.
AssetTxFeePaid {
who: T::AccountId,
actual_fee: BalanceOf<T>,
tip: BalanceOf<T>,
actual_fee: AssetBalanceOf<T>,
tip: AssetBalanceOf<T>,
asset_id: Option<ChargeAssetIdOf<T>>,
},
}
Expand Down Expand Up @@ -282,18 +282,20 @@ where
let actual_fee = pallet_transaction_payment::Pallet::<T>::compute_actual_fee(
len as u32, info, post_info, tip,
);
T::OnChargeAssetTransaction::correct_and_deposit_fee(
&who,
info,
post_info,
actual_fee.into(),
tip.into(),
already_withdrawn.into(),
)?;

let (converted_fee, converted_tip) =
T::OnChargeAssetTransaction::correct_and_deposit_fee(
&who,
info,
post_info,
actual_fee.into(),
tip.into(),
already_withdrawn.into(),
)?;
Pallet::<T>::deposit_event(Event::<T>::AssetTxFeePaid {
who,
actual_fee,
tip,
actual_fee: converted_fee,
tip: converted_tip,
asset_id,
});
},
Expand Down
13 changes: 8 additions & 5 deletions frame/transaction-payment/asset-tx-payment/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub trait OnChargeAssetTransaction<T: Config> {
corrected_fee: Self::Balance,
tip: Self::Balance,
already_withdrawn: Self::LiquidityInfo,
) -> Result<(), TransactionValidityError>;
) -> Result<(AssetBalanceOf<T>, AssetBalanceOf<T>), TransactionValidityError>;
Szegoo marked this conversation as resolved.
Show resolved Hide resolved
}

/// Allows specifying what to do with the withdrawn asset fees.
Expand Down Expand Up @@ -145,21 +145,24 @@ where
_dispatch_info: &DispatchInfoOf<T::RuntimeCall>,
_post_info: &PostDispatchInfoOf<T::RuntimeCall>,
corrected_fee: Self::Balance,
_tip: Self::Balance,
tip: Self::Balance,
paid: Self::LiquidityInfo,
) -> Result<(), TransactionValidityError> {
) -> Result<(AssetBalanceOf<T>, AssetBalanceOf<T>), TransactionValidityError> {
let min_converted_fee = if corrected_fee.is_zero() { Zero::zero() } else { One::one() };
// Convert the corrected fee into the asset used for payment.
// Convert the corrected fee and tip into the asset used for payment.
let converted_fee = CON::to_asset_balance(corrected_fee, paid.asset())
.map_err(|_| -> TransactionValidityError { InvalidTransaction::Payment.into() })?
.max(min_converted_fee);
let converted_tip = CON::to_asset_balance(tip, paid.asset())
.map_err(|_| -> TransactionValidityError { InvalidTransaction::Payment.into() })?;

Szegoo marked this conversation as resolved.
Show resolved Hide resolved
// Calculate how much refund we should return.
let (final_fee, refund) = paid.split(converted_fee);
// Refund to the account that paid the fees. If this fails, the account might have dropped
// below the existential balance. In that case we don't refund anything.
let _ = <T::Fungibles as Balanced<T::AccountId>>::resolve(who, refund);
// Handle the final fee, e.g. by transferring to the block author or burning.
HC::handle_credit(final_fee);
Ok(())
Ok((converted_fee, converted_tip))
}
}