#![cfg_attr(not(feature = "std"), no_std)]
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use frame_support::{
dispatch::GetDispatchInfo,
pallet_prelude::*,
traits::{EnsureOrigin, StorageVersion, UnfilteredDispatchable},
Parameter,
};
use frame_system::pallet_prelude::*;
use sp_runtime::DispatchResult;
use sp_std::prelude::Box;
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);
#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type RuntimeCall: Parameter + UnfilteredDispatchable<RuntimeOrigin = Self::RuntimeOrigin> + GetDispatchInfo;
type ExternalOrigin: EnsureOrigin<Self::RuntimeOrigin>;
}
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[allow(clippy::boxed_local)]
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight({
let dispatch_info = call.get_dispatch_info();
(
dispatch_info.weight.saturating_add(Weight::from_parts(10_000, 0)),
dispatch_info.class,
)
})]
pub fn apply(origin: OriginFor<T>, call: Box<<T as Config>::RuntimeCall>) -> DispatchResultWithPostInfo {
T::ExternalOrigin::ensure_origin(origin)?;
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
Self::deposit_event(Event::RootOp(res.map(|_| ()).map_err(|e| e.error)));
Ok(().into())
}
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
RootOp(DispatchResult),
}
}