mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 01:21:01 +00:00
This PR reverts #2280 which introduced `TransactionExtension` to replace `SignedExtension`. As a result of the discussion [here](https://github.com/paritytech/polkadot-sdk/pull/3623#issuecomment-1986789700), the changes will be reverted for now with plans to reintroduce the concept in the future. --------- Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
This commit is contained in:
@@ -20,14 +20,10 @@ use codec::{Decode, Encode};
|
||||
use frame_support::{dispatch::DispatchInfo, ensure};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
impl_tx_ext_default,
|
||||
traits::{
|
||||
AsSystemOriginSigner, DispatchInfoOf, Dispatchable, TransactionExtension,
|
||||
TransactionExtensionBase,
|
||||
},
|
||||
traits::{DispatchInfoOf, Dispatchable, SignedExtension},
|
||||
transaction_validity::{
|
||||
InvalidTransaction, TransactionPriority, TransactionValidityError, UnknownTransaction,
|
||||
ValidTransaction,
|
||||
InvalidTransaction, TransactionPriority, TransactionValidity, TransactionValidityError,
|
||||
UnknownTransaction, ValidTransaction,
|
||||
},
|
||||
};
|
||||
use sp_std::{fmt, marker::PhantomData};
|
||||
@@ -63,61 +59,49 @@ impl<T: Config + Send + Sync> fmt::Debug for CheckOnlySudoAccount<T> {
|
||||
}
|
||||
|
||||
impl<T: Config + Send + Sync> CheckOnlySudoAccount<T> {
|
||||
/// Creates new `TransactionExtension` to check sudo key.
|
||||
/// Creates new `SignedExtension` to check sudo key.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config + Send + Sync> TransactionExtensionBase for CheckOnlySudoAccount<T> {
|
||||
const IDENTIFIER: &'static str = "CheckOnlySudoAccount";
|
||||
type Implicit = ();
|
||||
|
||||
fn weight(&self) -> frame_support::weights::Weight {
|
||||
use crate::weights::WeightInfo;
|
||||
T::WeightInfo::check_only_sudo_account()
|
||||
}
|
||||
}
|
||||
impl<T: Config + Send + Sync, Context>
|
||||
TransactionExtension<<T as frame_system::Config>::RuntimeCall, Context> for CheckOnlySudoAccount<T>
|
||||
impl<T: Config + Send + Sync> SignedExtension for CheckOnlySudoAccount<T>
|
||||
where
|
||||
<T as frame_system::Config>::RuntimeCall: Dispatchable<Info = DispatchInfo>,
|
||||
<<T as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin:
|
||||
AsSystemOriginSigner<T::AccountId> + Clone,
|
||||
<T as Config>::RuntimeCall: Dispatchable<Info = DispatchInfo>,
|
||||
{
|
||||
const IDENTIFIER: &'static str = "CheckOnlySudoAccount";
|
||||
type AccountId = T::AccountId;
|
||||
type Call = <T as Config>::RuntimeCall;
|
||||
type AdditionalSigned = ();
|
||||
type Pre = ();
|
||||
type Val = ();
|
||||
|
||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
origin: <<T as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin,
|
||||
_call: &<T as frame_system::Config>::RuntimeCall,
|
||||
info: &DispatchInfoOf<<T as frame_system::Config>::RuntimeCall>,
|
||||
who: &Self::AccountId,
|
||||
_call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
_len: usize,
|
||||
_context: &mut Context,
|
||||
_self_implicit: Self::Implicit,
|
||||
_inherited_implication: &impl Encode,
|
||||
) -> Result<
|
||||
(
|
||||
ValidTransaction,
|
||||
Self::Val,
|
||||
<<T as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin,
|
||||
),
|
||||
TransactionValidityError,
|
||||
> {
|
||||
let who = origin.as_system_origin_signer().ok_or(InvalidTransaction::BadSigner)?;
|
||||
) -> TransactionValidity {
|
||||
let sudo_key: T::AccountId = Key::<T>::get().ok_or(UnknownTransaction::CannotLookup)?;
|
||||
ensure!(*who == sudo_key, InvalidTransaction::BadSigner);
|
||||
|
||||
Ok((
|
||||
ValidTransaction {
|
||||
priority: info.weight.ref_time() as TransactionPriority,
|
||||
..Default::default()
|
||||
},
|
||||
(),
|
||||
origin,
|
||||
))
|
||||
Ok(ValidTransaction {
|
||||
priority: info.weight.ref_time() as TransactionPriority,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
impl_tx_ext_default!(<T as frame_system::Config>::RuntimeCall; Context; prepare);
|
||||
fn pre_dispatch(
|
||||
self,
|
||||
who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
self.validate(who, call, info, len).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user