mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 13:51:11 +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
@@ -1550,6 +1550,63 @@ pub trait EnsureOrigin<OuterOrigin> {
|
||||
fn successful_origin() -> OuterOrigin;
|
||||
}
|
||||
|
||||
/// Type that can be dispatched with an origin but without checking the origin filter.
|
||||
///
|
||||
/// Implemented for pallet dispatchable type by `decl_module` and for runtime dispatchable by
|
||||
/// `construct_runtime` and `impl_outer_dispatch`.
|
||||
pub trait UnfilteredDispatchable {
|
||||
/// The origin type of the runtime, (i.e. `frame_system::Trait::Origin`).
|
||||
type Origin;
|
||||
|
||||
/// Dispatch this call but do not check the filter in origin.
|
||||
fn dispatch_bypass_filter(self, origin: Self::Origin) -> crate::dispatch::DispatchResultWithPostInfo;
|
||||
}
|
||||
|
||||
/// Methods available on `frame_system::Trait::Origin`.
|
||||
pub trait OriginTrait: Sized {
|
||||
/// Runtime call type, as in `frame_system::Trait::Call`
|
||||
type Call;
|
||||
|
||||
/// The caller origin, overarching type of all pallets origins.
|
||||
type PalletsOrigin;
|
||||
|
||||
/// Add a filter to the origin.
|
||||
fn add_filter(&mut self, filter: impl Fn(&Self::Call) -> bool + 'static);
|
||||
|
||||
/// Reset origin filters to default one, i.e `frame_system::Trait::BaseCallFilter`.
|
||||
fn reset_filter(&mut self);
|
||||
|
||||
/// Replace the caller with caller from the other origin
|
||||
fn set_caller_from(&mut self, other: impl Into<Self>);
|
||||
|
||||
/// Filter the call, if false then call is filtered out.
|
||||
fn filter_call(&self, call: &Self::Call) -> bool;
|
||||
}
|
||||
|
||||
/// Trait to be used when types are exactly same.
|
||||
///
|
||||
/// This allow to convert back and forth from type, a reference and a mutable reference.
|
||||
pub trait IsType<T>: Into<T> + From<T> {
|
||||
/// Cast reference.
|
||||
fn from_ref(t: &T) -> &Self;
|
||||
|
||||
/// Cast reference.
|
||||
fn into_ref(&self) -> &T;
|
||||
|
||||
/// Cast mutable reference.
|
||||
fn from_mut(t: &mut T) -> &mut Self;
|
||||
|
||||
/// Cast mutable reference.
|
||||
fn into_mut(&mut self) -> &mut T;
|
||||
}
|
||||
|
||||
impl<T> IsType<T> for T {
|
||||
fn from_ref(t: &T) -> &Self { t }
|
||||
fn into_ref(&self) -> &T { self }
|
||||
fn from_mut(t: &mut T) -> &mut Self { t }
|
||||
fn into_mut(&mut self) -> &mut T { self }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user