#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::{
decl_event, decl_module, traits::EnsureOrigin, weights::GetDispatchInfo, Parameter,
};
use sp_runtime::{traits::Dispatchable, DispatchResult};
use sp_std::prelude::Box;
pub trait Config: frame_system::Config {
type Event: From<Event> + Into<<Self as frame_system::Config>::Event>;
type Call: Parameter + Dispatchable<Origin = Self::Origin> + GetDispatchInfo;
type ExternalOrigin: EnsureOrigin<Self::Origin>;
}
decl_event!(
pub enum Event {
RootOp(DispatchResult),
}
);
decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
fn deposit_event() = default;
#[weight = (call.get_dispatch_info().weight + 10_000, call.get_dispatch_info().class)]
pub fn apply(origin, call: Box<<T as Config>::Call>) {
T::ExternalOrigin::ensure_origin(origin)?;
let res = call.dispatch(frame_system::RawOrigin::Root.into());
Self::deposit_event(Event::RootOp(res.map(|_| ()).map_err(|e| e.error)));
}
}
}