Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions frame/support/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ macro_rules! impl_outer_origin {
impl $crate::traits::OriginTrait for $name {
type Call = <$runtime as $system::Trait>::Call;
type PalletsOrigin = $caller_name;
type AccountId = <$runtime as $system::Trait>::AccountId;

fn add_filter(&mut self, filter: impl Fn(&Self::Call) -> bool + 'static) {
let f = self.filter.clone();
Expand Down Expand Up @@ -279,6 +280,20 @@ macro_rules! impl_outer_origin {
}
}

impl $crate::traits::SystemOrigin for $name {
type AccountId = <$runtime as $system::Trait>::AccountId;

fn none() -> Self {
$system::RawOrigin::None.into()
}
fn root() -> Self {
$system::RawOrigin::Root.into()
}
fn signed(by: <$runtime as $system::Trait>::AccountId) -> Self {
$system::RawOrigin::Signed(by).into()
}
}

impl From<$system::Origin<$runtime>> for $caller_name {
fn from(x: $system::Origin<$runtime>) -> Self {
$caller_name::system(x)
Expand Down
16 changes: 16 additions & 0 deletions frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,19 @@ pub trait UnfilteredDispatchable {
fn dispatch_bypass_filter(self, origin: Self::Origin) -> crate::dispatch::DispatchResultWithPostInfo;
}

/// Basic origin construction and AccountId type.
pub trait SystemOrigin {
/// The type of account identifiers used by the system.
type AccountId;

/// Create with system none origin and `frame-system::Trait::BaseCallFilter`.
fn none() -> Self;
/// Create with system root origin and no filter.
fn root() -> Self;
/// Create with system signed origin and `frame-system::Trait::BaseCallFilter`.
fn signed(by: Self::AccountId) -> Self;
}

/// Methods available on `frame_system::Trait::Origin`.
pub trait OriginTrait: Sized {
/// Runtime call type, as in `frame_system::Trait::Call`
Expand All @@ -1621,6 +1634,9 @@ pub trait OriginTrait: Sized {
/// The caller origin, overarching type of all pallets origins.
type PalletsOrigin;

/// The AccountId used across the system.
type AccountId;

/// Add a filter to the origin.
fn add_filter(&mut self, filter: impl Fn(&Self::Call) -> bool + 'static);

Expand Down