mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Fee and tip represented as asset ID inside AssetTxFeePaid (#13083)
* fee & tip in the asset ID Balance type * docs * rewrite * update runtime config * docs
This commit is contained in:
@@ -134,8 +134,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>>,
|
||||
},
|
||||
}
|
||||
@@ -284,18 +284,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,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -58,6 +58,8 @@ pub trait OnChargeAssetTransaction<T: Config> {
|
||||
/// the corrected amount.
|
||||
///
|
||||
/// Note: The `fee` already includes the `tip`.
|
||||
///
|
||||
/// Returns the fee and tip in the asset used for payment as (fee, tip).
|
||||
fn correct_and_deposit_fee(
|
||||
who: &T::AccountId,
|
||||
dispatch_info: &DispatchInfoOf<T::RuntimeCall>,
|
||||
@@ -65,7 +67,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>;
|
||||
}
|
||||
|
||||
/// Allows specifying what to do with the withdrawn asset fees.
|
||||
@@ -132,19 +134,24 @@ where
|
||||
/// Since the predicted fee might have been too high, parts of the fee may be refunded.
|
||||
///
|
||||
/// Note: The `corrected_fee` already includes the `tip`.
|
||||
///
|
||||
/// Returns the fee and tip in the asset used for payment as (fee, tip).
|
||||
fn correct_and_deposit_fee(
|
||||
who: &T::AccountId,
|
||||
_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() })?;
|
||||
|
||||
// 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
|
||||
@@ -152,6 +159,6 @@ where
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user