mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 18:11:10 +00:00
Introduce in-origin filtering (#6318)
* impl filter in origin * remove IsCallable usage. Breaking: utility::batch(root, calls) no longer bypass BasicCallFilter * rename BasicCallFilter -> BaseCallFilter * refactor code * Apply suggestions from code review Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * remove forgotten temporar comment * better add suggestion in another PR * refactor: use Clone instead of mem::replace * fix tests * fix tests * fix tests * fix benchmarks * Make root bypass filter in utility::batch * fix unused imports Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
97cac4ce8b
commit
c2ad27271b
@@ -61,6 +61,7 @@ frame_support::parameter_types! {
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Runtime;
|
||||
impl system::Trait for Runtime {
|
||||
type BaseCallFilter = ();
|
||||
type Origin = Origin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
|
||||
@@ -51,6 +51,7 @@ impl Dispatchable for Call {
|
||||
pub struct Test;
|
||||
|
||||
impl frame_system::Trait for Test {
|
||||
type BaseCallFilter = ();
|
||||
type Origin = Origin;
|
||||
type Index = AccountIndex;
|
||||
type BlockNumber = BlockNumber;
|
||||
|
||||
@@ -123,7 +123,7 @@ use frame_support::{
|
||||
storage,
|
||||
traits::{
|
||||
Contains, Get, ModuleToIndex, OnNewAccount, OnKilledAccount, IsDeadAccount, Happened,
|
||||
StoredMap, EnsureOrigin,
|
||||
StoredMap, EnsureOrigin, OriginTrait, Filter,
|
||||
},
|
||||
weights::{
|
||||
Weight, RuntimeDbWeight, DispatchInfo, PostDispatchInfo, DispatchClass,
|
||||
@@ -149,11 +149,15 @@ pub fn extrinsics_data_root<H: Hash>(xts: Vec<Vec<u8>>) -> H::Output {
|
||||
}
|
||||
|
||||
pub trait Trait: 'static + Eq + Clone {
|
||||
/// The aggregated `Origin` type used by dispatchable calls.
|
||||
/// The basic call filter to use in Origin.
|
||||
type BaseCallFilter: Filter<Self::Call>;
|
||||
|
||||
/// The `Origin` type used by dispatchable calls.
|
||||
type Origin:
|
||||
Into<Result<RawOrigin<Self::AccountId>, Self::Origin>>
|
||||
+ From<RawOrigin<Self::AccountId>>
|
||||
+ Clone;
|
||||
+ Clone
|
||||
+ OriginTrait<Call = Self::Call>;
|
||||
|
||||
/// The aggregated `Call` type.
|
||||
type Call: Dispatchable + Debug;
|
||||
@@ -1890,7 +1894,7 @@ pub(crate) mod tests {
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup, SignedExtension}, testing::Header, DispatchError};
|
||||
use frame_support::{
|
||||
impl_outer_origin, parameter_types, assert_ok, assert_noop, assert_err,
|
||||
impl_outer_origin, parameter_types, assert_ok, assert_noop,
|
||||
weights::{WithPostDispatchInfo, Pays},
|
||||
};
|
||||
|
||||
@@ -1937,7 +1941,7 @@ pub(crate) mod tests {
|
||||
pub struct Call;
|
||||
|
||||
impl Dispatchable for Call {
|
||||
type Origin = ();
|
||||
type Origin = Origin;
|
||||
type Trait = ();
|
||||
type Info = DispatchInfo;
|
||||
type PostInfo = PostDispatchInfo;
|
||||
@@ -1948,6 +1952,7 @@ pub(crate) mod tests {
|
||||
}
|
||||
|
||||
impl Trait for Test {
|
||||
type BaseCallFilter = ();
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
type Index = u64;
|
||||
@@ -1997,7 +2002,7 @@ pub(crate) mod tests {
|
||||
fn origin_works() {
|
||||
let o = Origin::from(RawOrigin::<u64>::Signed(1u64));
|
||||
let x: Result<RawOrigin<u64>, Origin> = o.into();
|
||||
assert_eq!(x, Ok(RawOrigin::<u64>::Signed(1u64)));
|
||||
assert_eq!(x.unwrap(), RawOrigin::<u64>::Signed(1u64));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2719,8 +2724,8 @@ pub(crate) mod tests {
|
||||
EnsureOneOf::<u64, EnsureRoot<u64>, EnsureSigned<u64>>::try_origin(o.into())
|
||||
}
|
||||
|
||||
assert_ok!(ensure_root_or_signed(RawOrigin::Root), Either::Left(()));
|
||||
assert_ok!(ensure_root_or_signed(RawOrigin::Signed(0)), Either::Right(0));
|
||||
assert_err!(ensure_root_or_signed(RawOrigin::None), Origin::from(RawOrigin::None));
|
||||
assert_eq!(ensure_root_or_signed(RawOrigin::Root).unwrap(), Either::Left(()));
|
||||
assert_eq!(ensure_root_or_signed(RawOrigin::Signed(0)).unwrap(), Either::Right(0));
|
||||
assert!(ensure_root_or_signed(RawOrigin::None).is_err())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user