topsoil_core/system/extensions/
check_tx_version.rs1use crate::system::{Config, Pallet};
8use codec::{Decode, DecodeWithMemTracking, Encode};
9use scale_info::TypeInfo;
10use subsoil::runtime::{
11 traits::TransactionExtension, transaction_validity::TransactionValidityError,
12};
13
14#[derive(Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)]
21#[scale_info(skip_type_params(T))]
22pub struct CheckTxVersion<T: Config + Send + Sync>(core::marker::PhantomData<T>);
23
24impl<T: Config + Send + Sync> core::fmt::Debug for CheckTxVersion<T> {
25 #[cfg(feature = "std")]
26 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
27 write!(f, "CheckTxVersion")
28 }
29
30 #[cfg(not(feature = "std"))]
31 fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
32 Ok(())
33 }
34}
35
36impl<T: Config + Send + Sync> CheckTxVersion<T> {
37 pub fn new() -> Self {
39 Self(core::marker::PhantomData)
40 }
41}
42
43impl<T: Config + Send + Sync> TransactionExtension<<T as Config>::RuntimeCall>
44 for CheckTxVersion<T>
45{
46 const IDENTIFIER: &'static str = "CheckTxVersion";
47 type Implicit = u32;
48 fn implicit(&self) -> Result<Self::Implicit, TransactionValidityError> {
49 Ok(<Pallet<T>>::runtime_version().transaction_version)
50 }
51 type Val = ();
52 type Pre = ();
53 fn weight(&self, _: &<T as Config>::RuntimeCall) -> subsoil::weights::Weight {
54 <T::ExtensionsWeightInfo as super::WeightInfo>::check_tx_version()
55 }
56 subsoil::impl_tx_ext_default!(<T as Config>::RuntimeCall; validate prepare);
57}