frame_system/extensions/
check_tx_version.rs1use crate::{Config, Pallet};
19use codec::{Decode, DecodeWithMemTracking, Encode};
20use scale_info::TypeInfo;
21use sp_runtime::{
22 impl_tx_ext_default, traits::TransactionExtension,
23 transaction_validity::TransactionValidityError,
24};
25
26#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)]
33#[scale_info(skip_type_params(T))]
34pub struct CheckTxVersion<T: Config + Send + Sync>(core::marker::PhantomData<T>);
35
36impl<T: Config + Send + Sync> core::fmt::Debug for CheckTxVersion<T> {
37 #[cfg(feature = "std")]
38 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
39 write!(f, "CheckTxVersion")
40 }
41
42 #[cfg(not(feature = "std"))]
43 fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
44 Ok(())
45 }
46}
47
48impl<T: Config + Send + Sync> CheckTxVersion<T> {
49 pub fn new() -> Self {
51 Self(core::marker::PhantomData)
52 }
53}
54
55impl<T: Config + Send + Sync> TransactionExtension<<T as Config>::RuntimeCall>
56 for CheckTxVersion<T>
57{
58 const IDENTIFIER: &'static str = "CheckTxVersion";
59 type Implicit = u32;
60 fn implicit(&self) -> Result<Self::Implicit, TransactionValidityError> {
61 Ok(<Pallet<T>>::runtime_version().transaction_version)
62 }
63 type Val = ();
64 type Pre = ();
65 fn weight(&self, _: &<T as Config>::RuntimeCall) -> sp_weights::Weight {
66 <T::ExtensionsWeightInfo as super::WeightInfo>::check_tx_version()
67 }
68 impl_tx_ext_default!(<T as Config>::RuntimeCall; validate prepare);
69}