frame_system/extensions/
check_spec_version.rs1use crate::{Config, Pallet};
19use codec::{Decode, Encode};
20use scale_info::TypeInfo;
21use sp_runtime::{
22 traits::{DispatchInfoOf, SignedExtension},
23 transaction_validity::TransactionValidityError,
24};
25
26#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
33#[scale_info(skip_type_params(T))]
34pub struct CheckSpecVersion<T: Config + Send + Sync>(core::marker::PhantomData<T>);
35
36impl<T: Config + Send + Sync> core::fmt::Debug for CheckSpecVersion<T> {
37 #[cfg(feature = "std")]
38 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
39 write!(f, "CheckSpecVersion")
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> CheckSpecVersion<T> {
49 pub fn new() -> Self {
51 Self(core::marker::PhantomData)
52 }
53}
54
55impl<T: Config + Send + Sync> SignedExtension for CheckSpecVersion<T> {
56 type AccountId = T::AccountId;
57 type Call = <T as Config>::RuntimeCall;
58 type AdditionalSigned = u32;
59 type Pre = ();
60 const IDENTIFIER: &'static str = "CheckSpecVersion";
61
62 fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
63 Ok(<Pallet<T>>::runtime_version().spec_version)
64 }
65
66 fn pre_dispatch(
67 self,
68 who: &Self::AccountId,
69 call: &Self::Call,
70 info: &DispatchInfoOf<Self::Call>,
71 len: usize,
72 ) -> Result<Self::Pre, TransactionValidityError> {
73 self.validate(who, call, info, len).map(|_| ())
74 }
75}