use crate::{Call, Config}; use codec::{Decode, DecodeWithMemTracking, Encode}; use frame_support::dispatch::{DispatchInfo, PostDispatchInfo}; use frame_support::pallet_prelude::Weight; use frame_support::traits::IsSubType; use scale_info::TypeInfo; use sp_runtime::traits::{ DispatchInfoOf, DispatchOriginOf, Dispatchable, Implication, TransactionExtension, ValidateResult, }; use sp_runtime::transaction_validity::{ TransactionPriority, TransactionSource, TransactionValidityError, ValidTransaction, }; use sp_std::marker::PhantomData; use subtensor_macros::freeze_struct; pub type RuntimeCallFor = ::RuntimeCall; #[freeze_struct("d0d094192bd6390e")] #[derive(Default, Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)] pub struct DrandPriority(pub PhantomData); impl sp_std::fmt::Debug for DrandPriority { fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { write!(f, "DrandPriority") } } impl DrandPriority { pub fn new() -> Self { Self(PhantomData) } fn get_drand_priority() -> TransactionPriority { 10_000u64 } } impl TransactionExtension> for DrandPriority where ::RuntimeCall: Dispatchable, ::RuntimeCall: IsSubType>, { const IDENTIFIER: &'static str = "DrandPriority"; type Implicit = (); type Val = (); type Pre = (); fn weight(&self, _call: &RuntimeCallFor) -> Weight { // TODO: benchmark transaction extension Weight::zero() } fn validate( &self, origin: DispatchOriginOf>, call: &RuntimeCallFor, _info: &DispatchInfoOf>, _len: usize, _self_implicit: Self::Implicit, _inherited_implication: &impl Implication, _source: TransactionSource, ) -> ValidateResult> { match call.is_sub_type() { Some(Call::write_pulse { .. }) => { let validity = ValidTransaction { priority: Self::get_drand_priority(), ..Default::default() }; Ok((validity, (), origin)) } _ => Ok((Default::default(), (), origin)), } } fn prepare( self, _val: Self::Val, _origin: &DispatchOriginOf>, _call: &RuntimeCallFor, _info: &DispatchInfoOf>, _len: usize, ) -> Result { Ok(()) } }