diff --git a/polkadot/runtime/parachains/src/lib.rs b/polkadot/runtime/parachains/src/lib.rs index 382e6a645d..833ff6ae47 100644 --- a/polkadot/runtime/parachains/src/lib.rs +++ b/polkadot/runtime/parachains/src/lib.rs @@ -22,11 +22,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -use sp_std::result; -use sp_runtime::traits::BadOrigin; -use primitives::v1::Id as ParaId; -use codec::{Decode, Encode}; - pub mod configuration; pub mod inclusion; pub mod inclusion_inherent; @@ -35,6 +30,7 @@ pub mod paras; pub mod router; pub mod scheduler; pub mod validity; +pub mod origin; pub mod runtime_api_impl; @@ -43,21 +39,4 @@ mod util; #[cfg(test)] mod mock; -/// Origin for the parachains. -#[derive(PartialEq, Eq, Clone, Encode, Decode)] -#[cfg_attr(feature = "std", derive(Debug))] -pub enum Origin { - /// It comes from a parachain. - Parachain(ParaId), -} - -/// Ensure that the origin `o` represents a parachain. -/// Returns `Ok` with the parachain ID that effected the extrinsic or an `Err` otherwise. -pub fn ensure_parachain(o: OuterOrigin) -> result::Result - where OuterOrigin: Into> -{ - match o.into() { - Ok(Origin::Parachain(id)) => Ok(id), - _ => Err(BadOrigin), - } -} +pub use origin::{Origin, ensure_parachain}; diff --git a/polkadot/runtime/parachains/src/origin.rs b/polkadot/runtime/parachains/src/origin.rs new file mode 100644 index 0000000000..79eb44e71c --- /dev/null +++ b/polkadot/runtime/parachains/src/origin.rs @@ -0,0 +1,54 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Declaration of the parachain specific origin and a pallet that hosts it. + +use sp_std::result; +use sp_runtime::traits::BadOrigin; +use primitives::v1::Id as ParaId; +use codec::{Decode, Encode}; + +/// Origin for the parachains. +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub enum Origin { + /// It comes from a parachain. + Parachain(ParaId), +} + +/// Ensure that the origin `o` represents a parachain. +/// Returns `Ok` with the parachain ID that effected the extrinsic or an `Err` otherwise. +pub fn ensure_parachain(o: OuterOrigin) -> result::Result + where OuterOrigin: Into> +{ + match o.into() { + Ok(Origin::Parachain(id)) => Ok(id), + _ => Err(BadOrigin), + } +} + +/// The origin module. +pub trait Trait: frame_system::Trait {} + +frame_support::decl_module! { + /// There is no way to register an origin type in `construct_runtime` without a pallet the origin + /// belongs to. + /// + /// This module fulfills only the single purpose of housing the `Origin` in `construct_runtime`. + /// + // ideally, though, the `construct_runtime` should support a free-standing origin. + pub struct Module for enum Call where origin: ::Origin {} +} diff --git a/polkadot/runtime/rococo-v1/src/lib.rs b/polkadot/runtime/rococo-v1/src/lib.rs index 4a6d8d1d69..96e1215c1e 100644 --- a/polkadot/runtime/rococo-v1/src/lib.rs +++ b/polkadot/runtime/rococo-v1/src/lib.rs @@ -63,6 +63,7 @@ use pallet_session::historical as session_historical; use frame_system::EnsureRoot; use runtime_common::paras_sudo_wrapper as paras_sudo_wrapper; +use runtime_parachains::origin as parachains_origin; use runtime_parachains::configuration as parachains_configuration; use runtime_parachains::inclusion as parachains_inclusion; use runtime_parachains::inclusion_inherent as parachains_inclusion_inherent; @@ -366,6 +367,7 @@ construct_runtime! { AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config}, // Parachains modules. + ParachainOrigin: parachains_origin::{Module, Origin}, Config: parachains_configuration::{Module, Call, Storage}, Inclusion: parachains_inclusion::{Module, Call, Storage, Event}, InclusionInherent: parachains_inclusion_inherent::{Module, Call, Storage}, @@ -718,6 +720,8 @@ impl pallet_authorship::Trait for Runtime { type EventHandler = (Staking, ImOnline); } +impl parachains_origin::Trait for Runtime { } + impl parachains_configuration::Trait for Runtime { } impl parachains_inclusion::Trait for Runtime {