Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions runtime/parachains/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@
use sp_std::result;
use sp_runtime::traits::BadOrigin;
use primitives::v1::Id as ParaId;
use parity_scale_codec::{Decode, Encode};

/// Origin for the parachains.
#[derive(PartialEq, Eq, Clone, Encode, Decode, sp_core::RuntimeDebug)]
pub enum Origin {
/// It comes from a parachain.
Parachain(ParaId),
}
pub use pallet::*;

/// Ensure that the origin `o` represents a parachain.
/// Returns `Ok` with the parachain ID that effected the extrinsic or an `Err` otherwise.
Expand All @@ -39,17 +33,31 @@ pub fn ensure_parachain<OuterOrigin>(o: OuterOrigin) -> result::Result<ParaId, B
}
}

/// The origin module.
pub trait Config: frame_system::Config {}

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<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin {}
/// 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.
#[frame_support::pallet]
pub mod pallet {
use frame_support::pallet_prelude::*;
use super::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config {}

/// Origin for the parachains.
#[pallet::origin]
#[derive(PartialEq, Eq, Clone, Encode, Decode, sp_core::RuntimeDebug)]
pub enum Origin {
/// It comes from a parachain.
Parachain(ParaId),
}
}

impl From<u32> for Origin {
Expand Down