Skip to content

Commit 25883cc

Browse files
Szegooltfschoen
authored andcommitted
Fee and tip represented as asset ID inside AssetTxFeePaid (paritytech#13083)
* fee & tip in the asset ID Balance type * docs * rewrite * update runtime config * docs
1 parent 3c2409c commit 25883cc

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ pub mod pallet {
134134
/// has been paid by `who` in an asset `asset_id`.
135135
AssetTxFeePaid {
136136
who: T::AccountId,
137-
actual_fee: BalanceOf<T>,
138-
tip: BalanceOf<T>,
137+
actual_fee: AssetBalanceOf<T>,
138+
tip: AssetBalanceOf<T>,
139139
asset_id: Option<ChargeAssetIdOf<T>>,
140140
},
141141
}
@@ -284,18 +284,20 @@ where
284284
let actual_fee = pallet_transaction_payment::Pallet::<T>::compute_actual_fee(
285285
len as u32, info, post_info, tip,
286286
);
287-
T::OnChargeAssetTransaction::correct_and_deposit_fee(
288-
&who,
289-
info,
290-
post_info,
291-
actual_fee.into(),
292-
tip.into(),
293-
already_withdrawn.into(),
294-
)?;
287+
288+
let (converted_fee, converted_tip) =
289+
T::OnChargeAssetTransaction::correct_and_deposit_fee(
290+
&who,
291+
info,
292+
post_info,
293+
actual_fee.into(),
294+
tip.into(),
295+
already_withdrawn.into(),
296+
)?;
295297
Pallet::<T>::deposit_event(Event::<T>::AssetTxFeePaid {
296298
who,
297-
actual_fee,
298-
tip,
299+
actual_fee: converted_fee,
300+
tip: converted_tip,
299301
asset_id,
300302
});
301303
},

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ pub trait OnChargeAssetTransaction<T: Config> {
5858
/// the corrected amount.
5959
///
6060
/// Note: The `fee` already includes the `tip`.
61+
///
62+
/// Returns the fee and tip in the asset used for payment as (fee, tip).
6163
fn correct_and_deposit_fee(
6264
who: &T::AccountId,
6365
dispatch_info: &DispatchInfoOf<T::RuntimeCall>,
6466
post_info: &PostDispatchInfoOf<T::RuntimeCall>,
6567
corrected_fee: Self::Balance,
6668
tip: Self::Balance,
6769
already_withdrawn: Self::LiquidityInfo,
68-
) -> Result<(), TransactionValidityError>;
70+
) -> Result<(AssetBalanceOf<T>, AssetBalanceOf<T>), TransactionValidityError>;
6971
}
7072

7173
/// Allows specifying what to do with the withdrawn asset fees.
@@ -132,26 +134,31 @@ where
132134
/// Since the predicted fee might have been too high, parts of the fee may be refunded.
133135
///
134136
/// Note: The `corrected_fee` already includes the `tip`.
137+
///
138+
/// Returns the fee and tip in the asset used for payment as (fee, tip).
135139
fn correct_and_deposit_fee(
136140
who: &T::AccountId,
137141
_dispatch_info: &DispatchInfoOf<T::RuntimeCall>,
138142
_post_info: &PostDispatchInfoOf<T::RuntimeCall>,
139143
corrected_fee: Self::Balance,
140-
_tip: Self::Balance,
144+
tip: Self::Balance,
141145
paid: Self::LiquidityInfo,
142-
) -> Result<(), TransactionValidityError> {
146+
) -> Result<(AssetBalanceOf<T>, AssetBalanceOf<T>), TransactionValidityError> {
143147
let min_converted_fee = if corrected_fee.is_zero() { Zero::zero() } else { One::one() };
144-
// Convert the corrected fee into the asset used for payment.
148+
// Convert the corrected fee and tip into the asset used for payment.
145149
let converted_fee = CON::to_asset_balance(corrected_fee, paid.asset())
146150
.map_err(|_| -> TransactionValidityError { InvalidTransaction::Payment.into() })?
147151
.max(min_converted_fee);
152+
let converted_tip = CON::to_asset_balance(tip, paid.asset())
153+
.map_err(|_| -> TransactionValidityError { InvalidTransaction::Payment.into() })?;
154+
148155
// Calculate how much refund we should return.
149156
let (final_fee, refund) = paid.split(converted_fee);
150157
// Refund to the account that paid the fees. If this fails, the account might have dropped
151158
// below the existential balance. In that case we don't refund anything.
152159
let _ = <T::Fungibles as Balanced<T::AccountId>>::resolve(who, refund);
153160
// Handle the final fee, e.g. by transferring to the block author or burning.
154161
HC::handle_credit(final_fee);
155-
Ok(())
162+
Ok((converted_fee, converted_tip))
156163
}
157164
}

0 commit comments

Comments
 (0)