mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 23:37:56 +00:00
Root origin use no filter by default. Scheduler and Democracy dispatch without asserting BaseCallFilter (#6408)
* make system root origin build runtime origin with no filter * additional doc
This commit is contained in:
committed by
GitHub
parent
2645659ab2
commit
780f8e09d7
@@ -163,8 +163,8 @@ macro_rules! impl_outer_origin {
|
||||
Modules { };
|
||||
$( $module:ident $( < $generic:ident > )? $( { $generic_instance:ident } )? ,)*
|
||||
) => {
|
||||
// WARNING: All instance must hold the filter `frame_system::Trait::BaseCallFilter`.
|
||||
// One can use `OriginTrait::reset_filter` to do so.
|
||||
// WARNING: All instance must hold the filter `frame_system::Trait::BaseCallFilter`, except
|
||||
// when caller is system Root. One can use `OriginTrait::reset_filter` to do so.
|
||||
#[derive(Clone)]
|
||||
pub struct $name {
|
||||
caller: $caller_name,
|
||||
@@ -241,28 +241,40 @@ macro_rules! impl_outer_origin {
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl $name {
|
||||
/// Create with system none origin and `frame-system::Trait::BaseCallFilter`.
|
||||
pub fn none() -> Self {
|
||||
$system::RawOrigin::None.into()
|
||||
}
|
||||
/// Create with system root origin and no filter.
|
||||
pub fn root() -> Self {
|
||||
$system::RawOrigin::Root.into()
|
||||
}
|
||||
/// Create with system signed origin and `frame-system::Trait::BaseCallFilter`.
|
||||
pub fn signed(by: <$runtime as $system::Trait>::AccountId) -> Self {
|
||||
$system::RawOrigin::Signed(by).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<$system::Origin<$runtime>> for $name {
|
||||
/// Convert to runtime origin:
|
||||
/// * root origin is built with no filter
|
||||
/// * others use `frame-system::Trait::BaseCallFilter`
|
||||
fn from(x: $system::Origin<$runtime>) -> Self {
|
||||
let mut o = $name {
|
||||
caller: $caller_name::system(x),
|
||||
filter: $crate::sp_std::rc::Rc::new(Box::new(|_| true)),
|
||||
};
|
||||
$crate::traits::OriginTrait::reset_filter(&mut o);
|
||||
|
||||
// Root has no filter
|
||||
if !matches!(o.caller, $caller_name::system($system::Origin::<$runtime>::Root)) {
|
||||
$crate::traits::OriginTrait::reset_filter(&mut o);
|
||||
}
|
||||
|
||||
o
|
||||
}
|
||||
}
|
||||
impl Into<$crate::sp_std::result::Result<$system::Origin<$runtime>, $name>> for $name {
|
||||
/// NOTE: converting to pallet origin loses the origin filter information.
|
||||
fn into(self) -> $crate::sp_std::result::Result<$system::Origin<$runtime>, Self> {
|
||||
if let $caller_name::system(l) = self.caller {
|
||||
Ok(l)
|
||||
@@ -272,6 +284,8 @@ macro_rules! impl_outer_origin {
|
||||
}
|
||||
}
|
||||
impl From<Option<<$runtime as $system::Trait>::AccountId>> for $name {
|
||||
/// Convert to runtime origin with caller being system signed or none and use filter
|
||||
/// `frame-system::Trait::BaseCallFilter`.
|
||||
fn from(x: Option<<$runtime as $system::Trait>::AccountId>) -> Self {
|
||||
<$system::Origin<$runtime>>::from(x).into()
|
||||
}
|
||||
@@ -279,6 +293,7 @@ macro_rules! impl_outer_origin {
|
||||
$(
|
||||
$crate::paste::item! {
|
||||
impl From<$module::Origin < $( $generic )? $(, $module::$generic_instance )? > > for $name {
|
||||
/// Convert to runtime origin using `frame-system::Trait::BaseCallFilter`.
|
||||
fn from(x: $module::Origin < $( $generic )? $(, $module::$generic_instance )? >) -> Self {
|
||||
let mut o = $name {
|
||||
caller: $caller_name::[< $module $( _ $generic_instance )? >](x),
|
||||
@@ -294,6 +309,7 @@ macro_rules! impl_outer_origin {
|
||||
$name,
|
||||
>>
|
||||
for $name {
|
||||
/// NOTE: converting to pallet origin loses the origin filter information.
|
||||
fn into(self) -> $crate::sp_std::result::Result<
|
||||
$module::Origin < $( $generic )? $(, $module::$generic_instance )? >,
|
||||
Self,
|
||||
@@ -402,7 +418,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_default_filter() {
|
||||
assert_eq!(OriginWithSystem::root().filter_call(&0), true);
|
||||
assert_eq!(OriginWithSystem::root().filter_call(&1), false);
|
||||
assert_eq!(OriginWithSystem::root().filter_call(&1), true);
|
||||
assert_eq!(OriginWithSystem::none().filter_call(&0), true);
|
||||
assert_eq!(OriginWithSystem::none().filter_call(&1), false);
|
||||
assert_eq!(OriginWithSystem::signed(0).filter_call(&0), true);
|
||||
|
||||
Reference in New Issue
Block a user