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