mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 05:07:55 +00:00
Use pallet-sudo extension CheckOnylSudoAccount (#1850)
This commit is contained in:
@@ -19,6 +19,7 @@ members = [
|
||||
"pallets/parachain-system",
|
||||
"pallets/parachain-system/proc-macro",
|
||||
"pallets/session-benchmarking",
|
||||
"pallets/solo-to-para",
|
||||
"pallets/xcm",
|
||||
"pallets/xcmp-queue",
|
||||
"parachain-template/node",
|
||||
|
||||
@@ -16,24 +16,12 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use cumulus_pallet_parachain_system as parachain_system;
|
||||
use frame_support::{
|
||||
dispatch::{DispatchInfo, DispatchResult},
|
||||
pallet_prelude::*,
|
||||
};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
pub use pallet::*;
|
||||
use polkadot_primitives::v2::PersistedValidationData;
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
traits::{DispatchInfoOf, Dispatchable, SignedExtension},
|
||||
transaction_validity::{
|
||||
InvalidTransaction, TransactionLongevity, TransactionPriority, TransactionValidity,
|
||||
TransactionValidityError, ValidTransaction,
|
||||
},
|
||||
};
|
||||
use sp_std::{prelude::*, vec::Vec};
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
@@ -110,76 +98,4 @@ pub mod pallet {
|
||||
crate::Pallet::<T>::set_pending_custom_validation_head_data();
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure that signed transactions are only valid if they are signed by root.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo, Default)]
|
||||
#[scale_info(skip_type_params(T))]
|
||||
pub struct CheckSudo<T: Config + Send + Sync>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Config + Send + Sync> CheckSudo<T> {
|
||||
pub fn new() -> Self {
|
||||
Self(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config + Send + Sync> sp_std::fmt::Debug for CheckSudo<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
||||
write!(f, "CheckSudo")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config + Send + Sync> SignedExtension for CheckSudo<T>
|
||||
where
|
||||
<T as frame_system::Config>::RuntimeCall: Dispatchable<Info = DispatchInfo>,
|
||||
{
|
||||
type AccountId = T::AccountId;
|
||||
type Call = <T as frame_system::Config>::RuntimeCall;
|
||||
type AdditionalSigned = ();
|
||||
type Pre = ();
|
||||
const IDENTIFIER: &'static str = "CheckSudo";
|
||||
|
||||
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
self,
|
||||
who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
Ok(self.validate(who, call, info, len).map(|_| ())?)
|
||||
}
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
who: &Self::AccountId,
|
||||
_call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
_len: usize,
|
||||
) -> TransactionValidity {
|
||||
let root_account = match pallet_sudo::Pallet::<T>::key() {
|
||||
Some(account) => account,
|
||||
None => return Err(InvalidTransaction::BadSigner.into()),
|
||||
};
|
||||
|
||||
if *who == root_account {
|
||||
Ok(ValidTransaction {
|
||||
priority: info.weight.ref_time() as TransactionPriority,
|
||||
longevity: TransactionLongevity::max_value(),
|
||||
propagate: true,
|
||||
..Default::default()
|
||||
})
|
||||
} else {
|
||||
Err(InvalidTransaction::BadSigner.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ pub type SignedExtra = (
|
||||
frame_system::CheckGenesis<Runtime>,
|
||||
frame_system::CheckEra<Runtime>,
|
||||
frame_system::CheckNonce<Runtime>,
|
||||
cumulus_pallet_solo_to_para::CheckSudo<Runtime>,
|
||||
pallet_sudo::CheckOnlySudoAccount<Runtime>,
|
||||
);
|
||||
/// Unchecked extrinsic type as expected by this runtime.
|
||||
pub type UncheckedExtrinsic =
|
||||
|
||||
Reference in New Issue
Block a user