mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Add Event to Pallet Transaction Payment (#11618)
* add Event to Pallet Transaction Payment * Fix tests in Pallet Balance * Fix tests in Pallet Balance/Executive/Asset-tx-payment. * Fix * fmt * Fix * Fix * Update Cargo.lock * Fix tests in executor * Update frame/transaction-payment/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * update the name of the event and fmt. Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
@@ -158,6 +158,7 @@ mod tests;
|
||||
mod benchmarking;
|
||||
mod tests_composite;
|
||||
mod tests_local;
|
||||
#[cfg(test)]
|
||||
mod tests_reentrancy;
|
||||
pub mod weights;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ frame_support::construct_runtime!(
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -77,6 +77,7 @@ impl frame_system::Config for Test {
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Test {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Pallet<Test>, ()>;
|
||||
type OperationalFeeMultiplier = ConstU8<5>;
|
||||
type WeightToFee = IdentityFee<u64>;
|
||||
|
||||
@@ -41,7 +41,7 @@ frame_support::construct_runtime!(
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -78,6 +78,7 @@ impl frame_system::Config for Test {
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Test {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Pallet<Test>, ()>;
|
||||
type OperationalFeeMultiplier = ConstU8<5>;
|
||||
type WeightToFee = IdentityFee<u64>;
|
||||
|
||||
@@ -19,13 +19,11 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::{self as pallet_balances, Config, Pallet};
|
||||
use crate::{self as pallet_balances, Config};
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{ConstU32, ConstU64, ConstU8, StorageMapShim},
|
||||
weights::IdentityFee,
|
||||
traits::{ConstU32, ConstU64, StorageMapShim},
|
||||
};
|
||||
use pallet_transaction_payment::CurrencyAdapter;
|
||||
use sp_core::H256;
|
||||
use sp_io;
|
||||
use sp_runtime::{testing::Header, traits::IdentityLookup};
|
||||
@@ -83,14 +81,6 @@ impl frame_system::Config for Test {
|
||||
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Test {
|
||||
type OnChargeTransaction = CurrencyAdapter<Pallet<Test>, ()>;
|
||||
type OperationalFeeMultiplier = ConstU8<5>;
|
||||
type WeightToFee = IdentityFee<u64>;
|
||||
type LengthToFee = IdentityFee<u64>;
|
||||
type FeeMultiplierUpdate = ();
|
||||
}
|
||||
|
||||
pub struct OnDustRemoval;
|
||||
impl OnUnbalanced<NegativeImbalance<Test>> for OnDustRemoval {
|
||||
fn on_nonzero_unbalanced(amount: NegativeImbalance<Test>) {
|
||||
|
||||
@@ -722,7 +722,7 @@ mod tests {
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||
Custom: custom::{Pallet, Call, ValidateUnsigned, Inherent},
|
||||
}
|
||||
);
|
||||
@@ -783,6 +783,7 @@ mod tests {
|
||||
pub const TransactionByteFee: Balance = 0;
|
||||
}
|
||||
impl pallet_transaction_payment::Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
|
||||
type OperationalFeeMultiplier = ConstU8<5>;
|
||||
type WeightToFee = IdentityFee<Balance>;
|
||||
|
||||
@@ -48,7 +48,7 @@ frame_support::construct_runtime!(
|
||||
{
|
||||
System: system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>},
|
||||
Authorship: pallet_authorship::{Pallet, Call, Storage},
|
||||
AssetTxPayment: pallet_asset_tx_payment::{Pallet},
|
||||
@@ -143,6 +143,7 @@ impl WeightToFeeT for TransactionByteFee {
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
|
||||
type WeightToFee = WeightToFee;
|
||||
type LengthToFee = TransactionByteFee;
|
||||
|
||||
@@ -249,6 +249,9 @@ pub mod pallet {
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
|
||||
/// Handler for withdrawing, refunding and depositing the transaction fee.
|
||||
/// Transaction fees are withdrawn before the transaction is executed.
|
||||
/// After the transaction was executed the transaction weight can be
|
||||
@@ -321,6 +324,14 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// A transaction fee `actual_fee`, of which `tip` was added to the minimum inclusion fee,
|
||||
/// has been paid by `who`.
|
||||
TransactionFeePaid { who: T::AccountId, actual_fee: BalanceOf<T>, tip: BalanceOf<T> },
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn on_finalize(_: T::BlockNumber) {
|
||||
@@ -734,6 +745,7 @@ where
|
||||
T::OnChargeTransaction::correct_and_deposit_fee(
|
||||
&who, info, post_info, actual_fee, tip, imbalance,
|
||||
)?;
|
||||
Pallet::<T>::deposit_event(Event::<T>::TransactionFeePaid { who, actual_fee, tip });
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -790,7 +802,7 @@ mod tests {
|
||||
{
|
||||
System: system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -899,6 +911,7 @@ mod tests {
|
||||
}
|
||||
|
||||
impl Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>;
|
||||
type OperationalFeeMultiplier = OperationalFeeMultiplier;
|
||||
type WeightToFee = WeightToFee;
|
||||
@@ -1407,8 +1420,14 @@ mod tests {
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Balances::total_balance(&user), 0);
|
||||
// No events for such a scenario
|
||||
assert_eq!(System::events().len(), 0);
|
||||
// TransactionFeePaid Event
|
||||
System::assert_has_event(Event::TransactionPayment(
|
||||
pallet_transaction_payment::Event::TransactionFeePaid {
|
||||
who: user,
|
||||
actual_fee: 0,
|
||||
tip: 0,
|
||||
},
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user