// Copyright 2019-2020 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // Substrate is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . use frame_support::codec::{Encode, Decode, EncodeLike}; pub trait Trait: 'static + Eq + Clone { type Origin: Into, Self::Origin>> + From>; type BlockNumber: Decode + Encode + EncodeLike + Clone + Default; type Hash; type AccountId: Encode + EncodeLike + Decode; type Event: From; type ModuleToIndex: frame_support::traits::ModuleToIndex; } frame_support::decl_module! { pub struct Module for enum Call where origin: T::Origin {} } impl Module { pub fn deposit_event(_event: impl Into) {} } frame_support::decl_event!( pub enum Event { ExtrinsicSuccess, ExtrinsicFailed, } ); frame_support::decl_error! { pub enum Error for Module { /// Test error documentation TestError, /// Error documentation /// with multiple lines AnotherError } } /// Origin for the system module. #[derive(PartialEq, Eq, Clone, sp_runtime::RuntimeDebug)] pub enum RawOrigin { Root, Signed(AccountId), None, } impl From> for RawOrigin { fn from(s: Option) -> RawOrigin { match s { Some(who) => RawOrigin::Signed(who), None => RawOrigin::None, } } } pub type Origin = RawOrigin<::AccountId>; #[allow(dead_code)] pub fn ensure_root(o: OuterOrigin) -> Result<(), &'static str> where OuterOrigin: Into, OuterOrigin>> { o.into().map(|_| ()).map_err(|_| "bad origin: expected to be a root origin") }