Skip to content

Commit bf8525b

Browse files
authored
Rename pallet trait Trait to Config (#7599)
* rename Trait to Config * add test asserting using Trait is still valid. * fix ui tests
1 parent f7ef725 commit bf8525b

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

src/lib.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
//! chance to be included by the transaction queue.
2626
//!
2727
//! Additionally, this module allows one to configure:
28-
//! - The mapping between one unit of weight to one unit of fee via [`Trait::WeightToFee`].
28+
//! - The mapping between one unit of weight to one unit of fee via [`Config::WeightToFee`].
2929
//! - A means of updating the fee for the next block, via defining a multiplier, based on the
3030
//! final state of the chain at the end of the previous block. This can be configured via
31-
//! [`Trait::FeeMultiplierUpdate`]
32-
//! - How the fees are paid via [`Trait::OnChargeTransaction`].
31+
//! [`Config::FeeMultiplierUpdate`]
32+
//! - How the fees are paid via [`Config::OnChargeTransaction`].
3333
3434
#![cfg_attr(not(feature = "std"), no_std)]
3535

@@ -63,7 +63,7 @@ pub use payment::*;
6363
pub type Multiplier = FixedU128;
6464

6565
type BalanceOf<T> =
66-
<<T as Trait>::OnChargeTransaction as OnChargeTransaction<T>>::Balance;
66+
<<T as Config>::OnChargeTransaction as OnChargeTransaction<T>>::Balance;
6767

6868
/// A struct to update the weight multiplier per block. It implements `Convert<Multiplier,
6969
/// Multiplier>`, meaning that it can convert the previous multiplier to the next one. This should
@@ -135,7 +135,7 @@ impl MultiplierUpdate for () {
135135
}
136136

137137
impl<T, S, V, M> MultiplierUpdate for TargetedFeeAdjustment<T, S, V, M>
138-
where T: frame_system::Trait, S: Get<Perquintill>, V: Get<Multiplier>, M: Get<Multiplier>,
138+
where T: frame_system::Config, S: Get<Perquintill>, V: Get<Multiplier>, M: Get<Multiplier>,
139139
{
140140
fn min() -> Multiplier {
141141
M::get()
@@ -149,7 +149,7 @@ impl<T, S, V, M> MultiplierUpdate for TargetedFeeAdjustment<T, S, V, M>
149149
}
150150

151151
impl<T, S, V, M> Convert<Multiplier, Multiplier> for TargetedFeeAdjustment<T, S, V, M>
152-
where T: frame_system::Trait, S: Get<Perquintill>, V: Get<Multiplier>, M: Get<Multiplier>,
152+
where T: frame_system::Config, S: Get<Perquintill>, V: Get<Multiplier>, M: Get<Multiplier>,
153153
{
154154
fn convert(previous: Multiplier) -> Multiplier {
155155
// Defensive only. The multiplier in storage should always be at most positive. Nonetheless
@@ -160,8 +160,8 @@ impl<T, S, V, M> Convert<Multiplier, Multiplier> for TargetedFeeAdjustment<T, S,
160160

161161
// the computed ratio is only among the normal class.
162162
let normal_max_weight =
163-
<T as frame_system::Trait>::AvailableBlockRatio::get() *
164-
<T as frame_system::Trait>::MaximumBlockWeight::get();
163+
<T as frame_system::Config>::AvailableBlockRatio::get() *
164+
<T as frame_system::Config>::MaximumBlockWeight::get();
165165
let normal_block_weight =
166166
<frame_system::Module<T>>::block_weight()
167167
.get(frame_support::weights::DispatchClass::Normal)
@@ -213,7 +213,7 @@ impl Default for Releases {
213213
}
214214
}
215215

216-
pub trait Trait: frame_system::Trait {
216+
pub trait Config: frame_system::Config {
217217
/// Handler for withdrawing, refunding and depositing the transaction fee.
218218
/// Transaction fees are withdrawn before the transaction is executed.
219219
/// After the transaction was executed the transaction weight can be
@@ -233,15 +233,15 @@ pub trait Trait: frame_system::Trait {
233233
}
234234

235235
decl_storage! {
236-
trait Store for Module<T: Trait> as TransactionPayment {
236+
trait Store for Module<T: Config> as TransactionPayment {
237237
pub NextFeeMultiplier get(fn next_fee_multiplier): Multiplier = Multiplier::saturating_from_integer(1);
238238

239239
StorageVersion build(|_: &GenesisConfig| Releases::V2): Releases;
240240
}
241241
}
242242

243243
decl_module! {
244-
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
244+
pub struct Module<T: Config> for enum Call where origin: T::Origin {
245245
/// The fee to be paid for making a transaction; the per-byte portion.
246246
const TransactionByteFee: BalanceOf<T> = T::TransactionByteFee::get();
247247

@@ -263,7 +263,7 @@ decl_module! {
263263
assert!(
264264
<Multiplier as sp_runtime::traits::Bounded>::max_value() >=
265265
Multiplier::checked_from_integer(
266-
<T as frame_system::Trait>::MaximumBlockWeight::get().try_into().unwrap()
266+
<T as frame_system::Config>::MaximumBlockWeight::get().try_into().unwrap()
267267
).unwrap(),
268268
);
269269

@@ -296,7 +296,7 @@ decl_module! {
296296
}
297297
}
298298

299-
impl<T: Trait> Module<T> where
299+
impl<T: Config> Module<T> where
300300
BalanceOf<T>: FixedPointOperand
301301
{
302302
/// Query the data that we know about the fee of a given `call`.
@@ -407,13 +407,13 @@ impl<T: Trait> Module<T> where
407407
fn weight_to_fee(weight: Weight) -> BalanceOf<T> {
408408
// cap the weight to the maximum defined in runtime, otherwise it will be the
409409
// `Bounded` maximum of its data type, which is not desired.
410-
let capped_weight = weight.min(<T as frame_system::Trait>::MaximumBlockWeight::get());
410+
let capped_weight = weight.min(<T as frame_system::Config>::MaximumBlockWeight::get());
411411
T::WeightToFee::calc(&capped_weight)
412412
}
413413
}
414414

415415
impl<T> Convert<Weight, BalanceOf<T>> for Module<T> where
416-
T: Trait,
416+
T: Config,
417417
BalanceOf<T>: FixedPointOperand,
418418
{
419419
/// Compute the fee for the specified weight.
@@ -429,9 +429,9 @@ impl<T> Convert<Weight, BalanceOf<T>> for Module<T> where
429429
/// Require the transactor pay for themselves and maybe include a tip to gain additional priority
430430
/// in the queue.
431431
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
432-
pub struct ChargeTransactionPayment<T: Trait + Send + Sync>(#[codec(compact)] BalanceOf<T>);
432+
pub struct ChargeTransactionPayment<T: Config + Send + Sync>(#[codec(compact)] BalanceOf<T>);
433433

434-
impl<T: Trait + Send + Sync> ChargeTransactionPayment<T> where
434+
impl<T: Config + Send + Sync> ChargeTransactionPayment<T> where
435435
T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>,
436436
BalanceOf<T>: Send + Sync + FixedPointOperand,
437437
{
@@ -449,14 +449,14 @@ impl<T: Trait + Send + Sync> ChargeTransactionPayment<T> where
449449
) -> Result<
450450
(
451451
BalanceOf<T>,
452-
<<T as Trait>::OnChargeTransaction as OnChargeTransaction<T>>::LiquidityInfo,
452+
<<T as Config>::OnChargeTransaction as OnChargeTransaction<T>>::LiquidityInfo,
453453
),
454454
TransactionValidityError,
455455
> {
456456
let tip = self.0;
457457
let fee = Module::<T>::compute_fee(len as u32, info, tip);
458458

459-
<<T as Trait>::OnChargeTransaction as OnChargeTransaction<T>>::withdraw_fee(who, call, info, fee, tip)
459+
<<T as Config>::OnChargeTransaction as OnChargeTransaction<T>>::withdraw_fee(who, call, info, fee, tip)
460460
.map(|i| (fee, i))
461461
}
462462

@@ -478,7 +478,7 @@ impl<T: Trait + Send + Sync> ChargeTransactionPayment<T> where
478478
}
479479
}
480480

481-
impl<T: Trait + Send + Sync> sp_std::fmt::Debug for ChargeTransactionPayment<T> {
481+
impl<T: Config + Send + Sync> sp_std::fmt::Debug for ChargeTransactionPayment<T> {
482482
#[cfg(feature = "std")]
483483
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
484484
write!(f, "ChargeTransactionPayment<{:?}>", self.0)
@@ -489,7 +489,7 @@ impl<T: Trait + Send + Sync> sp_std::fmt::Debug for ChargeTransactionPayment<T>
489489
}
490490
}
491491

492-
impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T> where
492+
impl<T: Config + Send + Sync> SignedExtension for ChargeTransactionPayment<T> where
493493
BalanceOf<T>: Send + Sync + From<u64> + FixedPointOperand,
494494
T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>,
495495
{
@@ -503,7 +503,7 @@ impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T> whe
503503
// who paid the fee
504504
Self::AccountId,
505505
// imbalance resulting from withdrawing the fee
506-
<<T as Trait>::OnChargeTransaction as OnChargeTransaction<T>>::LiquidityInfo,
506+
<<T as Config>::OnChargeTransaction as OnChargeTransaction<T>>::LiquidityInfo,
507507
);
508508
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> { Ok(()) }
509509

@@ -573,7 +573,7 @@ mod tests {
573573
};
574574
use smallvec::smallvec;
575575

576-
const CALL: &<Runtime as frame_system::Trait>::Call =
576+
const CALL: &<Runtime as frame_system::Config>::Call =
577577
&Call::Balances(BalancesCall::transfer(2, 69));
578578

579579
impl_outer_dispatch! {
@@ -608,7 +608,7 @@ mod tests {
608608
pub static WeightToFee: u64 = 1;
609609
}
610610

611-
impl frame_system::Trait for Runtime {
611+
impl frame_system::Config for Runtime {
612612
type BaseCallFilter = ();
613613
type Origin = Origin;
614614
type Index = u64;
@@ -640,7 +640,7 @@ mod tests {
640640
pub const ExistentialDeposit: u64 = 1;
641641
}
642642

643-
impl pallet_balances::Trait for Runtime {
643+
impl pallet_balances::Config for Runtime {
644644
type Balance = u64;
645645
type Event = Event;
646646
type DustRemoval = ();
@@ -663,7 +663,7 @@ mod tests {
663663
}
664664
}
665665

666-
impl Trait for Runtime {
666+
impl Config for Runtime {
667667
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
668668
type TransactionByteFee = TransactionByteFee;
669669
type WeightToFee = WeightToFee;
@@ -841,7 +841,7 @@ mod tests {
841841
// fee will be proportional to what is the actual maximum weight in the runtime.
842842
assert_eq!(
843843
Balances::free_balance(&1),
844-
(10000 - <Runtime as frame_system::Trait>::MaximumBlockWeight::get()) as u64
844+
(10000 - <Runtime as frame_system::Config>::MaximumBlockWeight::get()) as u64
845845
);
846846
});
847847
}

src/payment.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///! Traits and default implementation for paying transaction fees.
2-
use crate::Trait;
2+
use crate::Config;
33
use codec::FullCodec;
44
use frame_support::{
55
traits::{Currency, ExistenceRequirement, Get, Imbalance, OnUnbalanced, WithdrawReasons},
@@ -12,10 +12,10 @@ use sp_runtime::{
1212
use sp_std::{fmt::Debug, marker::PhantomData};
1313

1414
type NegativeImbalanceOf<C, T> =
15-
<C as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
15+
<C as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
1616

1717
/// Handle withdrawing, refunding and depositing of transaction fees.
18-
pub trait OnChargeTransaction<T: Trait> {
18+
pub trait OnChargeTransaction<T: Config> {
1919
/// The underlying integer type in which fees are calculated.
2020
type Balance: AtLeast32BitUnsigned + FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default;
2121
type LiquidityInfo: Default;
@@ -55,17 +55,17 @@ pub struct CurrencyAdapter<C, OU>(PhantomData<(C, OU)>);
5555
/// Default implementation for a Currency and an OnUnbalanced handler.
5656
impl<T, C, OU> OnChargeTransaction<T> for CurrencyAdapter<C, OU>
5757
where
58-
T: Trait,
59-
T::TransactionByteFee: Get<<C as Currency<<T as frame_system::Trait>::AccountId>>::Balance>,
60-
C: Currency<<T as frame_system::Trait>::AccountId>,
58+
T: Config,
59+
T::TransactionByteFee: Get<<C as Currency<<T as frame_system::Config>::AccountId>>::Balance>,
60+
C: Currency<<T as frame_system::Config>::AccountId>,
6161
C::PositiveImbalance:
62-
Imbalance<<C as Currency<<T as frame_system::Trait>::AccountId>>::Balance, Opposite = C::NegativeImbalance>,
62+
Imbalance<<C as Currency<<T as frame_system::Config>::AccountId>>::Balance, Opposite = C::NegativeImbalance>,
6363
C::NegativeImbalance:
64-
Imbalance<<C as Currency<<T as frame_system::Trait>::AccountId>>::Balance, Opposite = C::PositiveImbalance>,
64+
Imbalance<<C as Currency<<T as frame_system::Config>::AccountId>>::Balance, Opposite = C::PositiveImbalance>,
6565
OU: OnUnbalanced<NegativeImbalanceOf<C, T>>,
6666
{
6767
type LiquidityInfo = Option<NegativeImbalanceOf<C, T>>;
68-
type Balance = <C as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
68+
type Balance = <C as Currency<<T as frame_system::Config>::AccountId>>::Balance;
6969

7070
/// Withdraw the predicted fee from the transaction origin.
7171
///

0 commit comments

Comments
 (0)