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

Commit 3e0554a

Browse files
authored
Add Event to Pallet Asset-Tx-Payment (#11690)
* Add Event to Pallet Asset-Tx-Payment * add asset_id into the Event Co-authored-by: parity-processbot <>
1 parent 494a288 commit 3e0554a

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

bin/node/runtime/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ impl pallet_transaction_payment::Config for Runtime {
456456
}
457457

458458
impl pallet_asset_tx_payment::Config for Runtime {
459+
type Event = Event;
459460
type Fungibles = Assets;
460461
type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
461462
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ pub mod pallet {
113113

114114
#[pallet::config]
115115
pub trait Config: frame_system::Config + pallet_transaction_payment::Config {
116+
/// The overarching event type.
117+
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
116118
/// The fungibles instance used to pay for transactions in assets.
117119
type Fungibles: Balanced<Self::AccountId>;
118120
/// The actual transaction charging logic that charges the fees.
@@ -122,6 +124,19 @@ pub mod pallet {
122124
#[pallet::pallet]
123125
#[pallet::generate_store(pub(super) trait Store)]
124126
pub struct Pallet<T>(_);
127+
128+
#[pallet::event]
129+
#[pallet::generate_deposit(pub(super) fn deposit_event)]
130+
pub enum Event<T: Config> {
131+
/// A transaction fee `actual_fee`, of which `tip` was added to the minimum inclusion fee,
132+
/// has been paid by `who` in an asset `asset_id`.
133+
AssetTxFeePaid {
134+
who: T::AccountId,
135+
actual_fee: BalanceOf<T>,
136+
tip: BalanceOf<T>,
137+
asset_id: Option<ChargeAssetIdOf<T>>,
138+
},
139+
}
125140
}
126141

127142
/// Require the transactor pay for themselves and maybe include a tip to gain additional priority
@@ -213,6 +228,8 @@ where
213228
Self::AccountId,
214229
// imbalance resulting from withdrawing the fee
215230
InitialPayment<T>,
231+
// asset_id for the transaction payment
232+
Option<ChargeAssetIdOf<T>>,
216233
);
217234

218235
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {
@@ -240,7 +257,7 @@ where
240257
len: usize,
241258
) -> Result<Self::Pre, TransactionValidityError> {
242259
let (_fee, initial_payment) = self.withdraw_fee(who, call, info, len)?;
243-
Ok((self.tip, who.clone(), initial_payment))
260+
Ok((self.tip, who.clone(), initial_payment, self.asset_id))
244261
}
245262

246263
fn post_dispatch(
@@ -250,7 +267,7 @@ where
250267
len: usize,
251268
result: &DispatchResult,
252269
) -> Result<(), TransactionValidityError> {
253-
if let Some((tip, who, initial_payment)) = pre {
270+
if let Some((tip, who, initial_payment, asset_id)) = pre {
254271
match initial_payment {
255272
InitialPayment::Native(already_withdrawn) => {
256273
pallet_transaction_payment::ChargeTransactionPayment::<T>::post_dispatch(
@@ -273,6 +290,12 @@ where
273290
tip.into(),
274291
already_withdrawn.into(),
275292
)?;
293+
Pallet::<T>::deposit_event(Event::<T>::AssetTxFeePaid {
294+
who,
295+
actual_fee,
296+
tip,
297+
asset_id,
298+
});
276299
},
277300
InitialPayment::Nothing => {
278301
// `actual_fee` should be zero here for any signed extrinsic. It would be

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ frame_support::construct_runtime!(
5151
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
5252
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>},
5353
Authorship: pallet_authorship::{Pallet, Call, Storage},
54-
AssetTxPayment: pallet_asset_tx_payment::{Pallet},
54+
AssetTxPayment: pallet_asset_tx_payment::{Pallet, Event<T>},
5555
}
5656
);
5757

@@ -198,6 +198,7 @@ impl HandleCredit<AccountId, Assets> for CreditToBlockAuthor {
198198
}
199199

200200
impl Config for Runtime {
201+
type Event = Event;
201202
type Fungibles = Assets;
202203
type OnChargeAssetTransaction = FungiblesAdapter<
203204
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
@@ -663,7 +664,7 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() {
663664
.unwrap();
664665
// `Pays::No` implies no pre-dispatch fees
665666
assert_eq!(Assets::balance(asset_id, caller), balance);
666-
let (_tip, _who, initial_payment) = &pre;
667+
let (_tip, _who, initial_payment, _asset_id) = &pre;
667668
let not_paying = match initial_payment {
668669
&InitialPayment::Nothing => true,
669670
_ => false,

0 commit comments

Comments
 (0)