BREAKING: Rename Origin (#12258)

* BREAKING: Rename Origin

* more renaming

* a bit more renaming

* fix

* more fixing

* fix in frame_support

* even more fixes

* fix

* small fix

* ...

* update .stderr

* docs

* update docs

* update docs

* docs
This commit is contained in:
Sergej Sakac
2022-09-21 00:13:09 +02:00
committed by GitHub
parent 986d20b352
commit e4b6f4a66d
221 changed files with 5233 additions and 4200 deletions
@@ -162,12 +162,12 @@ pub fn expand_outer_dispatch(
}
}
impl #scrate::dispatch::Dispatchable for RuntimeCall {
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Config = RuntimeCall;
type Info = #scrate::dispatch::DispatchInfo;
type PostInfo = #scrate::dispatch::PostDispatchInfo;
fn dispatch(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo {
if !<Self::Origin as #scrate::traits::OriginTrait>::filter_call(&origin, &self) {
fn dispatch(self, origin: RuntimeOrigin) -> #scrate::dispatch::DispatchResultWithPostInfo {
if !<Self::RuntimeOrigin as #scrate::traits::OriginTrait>::filter_call(&origin, &self) {
return #scrate::sp_std::result::Result::Err(
#system_path::Error::<#runtime>::CallFiltered.into()
);
@@ -177,8 +177,8 @@ pub fn expand_outer_dispatch(
}
}
impl #scrate::traits::UnfilteredDispatchable for RuntimeCall {
type Origin = Origin;
fn dispatch_bypass_filter(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo {
type RuntimeOrigin = RuntimeOrigin;
fn dispatch_bypass_filter(self, origin: RuntimeOrigin) -> #scrate::dispatch::DispatchResultWithPostInfo {
match self {
#(
#pallet_attrs
@@ -103,13 +103,13 @@ pub fn expand_outer_origin(
///
#[doc = #doc_string]
#[derive(Clone)]
pub struct Origin {
pub struct RuntimeOrigin {
caller: OriginCaller,
filter: #scrate::sp_std::rc::Rc<Box<dyn Fn(&<#runtime as #system_path::Config>::RuntimeCall) -> bool>>,
}
#[cfg(not(feature = "std"))]
impl #scrate::sp_std::fmt::Debug for Origin {
impl #scrate::sp_std::fmt::Debug for RuntimeOrigin {
fn fmt(
&self,
fmt: &mut #scrate::sp_std::fmt::Formatter,
@@ -119,7 +119,7 @@ pub fn expand_outer_origin(
}
#[cfg(feature = "std")]
impl #scrate::sp_std::fmt::Debug for Origin {
impl #scrate::sp_std::fmt::Debug for RuntimeOrigin {
fn fmt(
&self,
fmt: &mut #scrate::sp_std::fmt::Formatter,
@@ -131,7 +131,7 @@ pub fn expand_outer_origin(
}
}
impl #scrate::traits::OriginTrait for Origin {
impl #scrate::traits::OriginTrait for RuntimeOrigin {
type Call = <#runtime as #system_path::Config>::RuntimeCall;
type PalletsOrigin = OriginCaller;
type AccountId = <#runtime as #system_path::Config>::AccountId;
@@ -214,21 +214,21 @@ pub fn expand_outer_origin(
// For backwards compatibility and ease of accessing these functions.
#[allow(dead_code)]
impl Origin {
impl RuntimeOrigin {
#[doc = #doc_string_none_origin]
pub fn none() -> Self {
<Origin as #scrate::traits::OriginTrait>::none()
<RuntimeOrigin as #scrate::traits::OriginTrait>::none()
}
#[doc = #doc_string_root_origin]
pub fn root() -> Self {
<Origin as #scrate::traits::OriginTrait>::root()
<RuntimeOrigin as #scrate::traits::OriginTrait>::root()
}
#[doc = #doc_string_signed_origin]
pub fn signed(by: <#runtime as #system_path::Config>::AccountId) -> Self {
<Origin as #scrate::traits::OriginTrait>::signed(by)
<RuntimeOrigin as #scrate::traits::OriginTrait>::signed(by)
}
}
@@ -251,7 +251,7 @@ pub fn expand_outer_origin(
}
}
impl From<#system_path::Origin<#runtime>> for Origin {
impl From<#system_path::Origin<#runtime>> for RuntimeOrigin {
#[doc = #doc_string_runtime_origin]
fn from(x: #system_path::Origin<#runtime>) -> Self {
@@ -260,9 +260,9 @@ pub fn expand_outer_origin(
}
}
impl From<OriginCaller> for Origin {
impl From<OriginCaller> for RuntimeOrigin {
fn from(x: OriginCaller) -> Self {
let mut o = Origin {
let mut o = RuntimeOrigin {
caller: x,
filter: #scrate::sp_std::rc::Rc::new(Box::new(|_| true)),
};
@@ -273,9 +273,9 @@ pub fn expand_outer_origin(
}
}
impl From<Origin> for #scrate::sp_std::result::Result<#system_path::Origin<#runtime>, Origin> {
impl From<RuntimeOrigin> for #scrate::sp_std::result::Result<#system_path::Origin<#runtime>, RuntimeOrigin> {
/// NOTE: converting to pallet origin loses the origin filter information.
fn from(val: Origin) -> Self {
fn from(val: RuntimeOrigin) -> Self {
if let OriginCaller::system(l) = val.caller {
Ok(l)
} else {
@@ -283,7 +283,7 @@ pub fn expand_outer_origin(
}
}
}
impl From<Option<<#runtime as #system_path::Config>::AccountId>> for Origin {
impl From<Option<<#runtime as #system_path::Config>::AccountId>> for RuntimeOrigin {
#[doc = #doc_string_runtime_origin_with_caller]
fn from(x: Option<<#runtime as #system_path::Config>::AccountId>) -> Self {
<#system_path::Origin<#runtime>>::from(x).into()
@@ -374,7 +374,7 @@ fn expand_origin_pallet_conversions(
}
#attr
impl From<#pallet_origin> for Origin {
impl From<#pallet_origin> for RuntimeOrigin {
#[doc = #doc_string]
fn from(x: #pallet_origin) -> Self {
let x: OriginCaller = x.into();
@@ -383,9 +383,9 @@ fn expand_origin_pallet_conversions(
}
#attr
impl From<Origin> for #scrate::sp_std::result::Result<#pallet_origin, Origin> {
impl From<RuntimeOrigin> for #scrate::sp_std::result::Result<#pallet_origin, RuntimeOrigin> {
/// NOTE: converting to pallet origin loses the origin filter information.
fn from(val: Origin) -> Self {
fn from(val: RuntimeOrigin) -> Self {
if let OriginCaller::#variant_name(l) = val.caller {
Ok(l)
} else {
@@ -278,10 +278,10 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
for #call_ident<#type_use_gen>
#where_clause
{
type Origin = #frame_system::pallet_prelude::OriginFor<T>;
type RuntimeOrigin = #frame_system::pallet_prelude::OriginFor<T>;
fn dispatch_bypass_filter(
self,
origin: Self::Origin
origin: Self::RuntimeOrigin
) -> #frame_support::dispatch::DispatchResultWithPostInfo {
match self {
#(
@@ -119,7 +119,7 @@ impl Def {
let g = genesis_build::GenesisBuildDef::try_from(span, index, item)?;
genesis_build = Some(g);
},
Some(PalletAttr::Origin(_)) if origin.is_none() =>
Some(PalletAttr::RuntimeOrigin(_)) if origin.is_none() =>
origin = Some(origin::OriginDef::try_from(index, item)?),
Some(PalletAttr::Inherent(_)) if inherent.is_none() =>
inherent = Some(inherent::InherentDef::try_from(index, item)?),
@@ -394,7 +394,7 @@ enum PalletAttr {
RuntimeCall(proc_macro2::Span),
Error(proc_macro2::Span),
RuntimeEvent(proc_macro2::Span),
Origin(proc_macro2::Span),
RuntimeOrigin(proc_macro2::Span),
Inherent(proc_macro2::Span),
Storage(proc_macro2::Span),
GenesisConfig(proc_macro2::Span),
@@ -413,7 +413,7 @@ impl PalletAttr {
Self::RuntimeCall(span) => *span,
Self::Error(span) => *span,
Self::RuntimeEvent(span) => *span,
Self::Origin(span) => *span,
Self::RuntimeOrigin(span) => *span,
Self::Inherent(span) => *span,
Self::Storage(span) => *span,
Self::GenesisConfig(span) => *span,
@@ -447,7 +447,7 @@ impl syn::parse::Parse for PalletAttr {
} else if lookahead.peek(keyword::event) {
Ok(PalletAttr::RuntimeEvent(content.parse::<keyword::event>()?.span()))
} else if lookahead.peek(keyword::origin) {
Ok(PalletAttr::Origin(content.parse::<keyword::origin>()?.span()))
Ok(PalletAttr::RuntimeOrigin(content.parse::<keyword::origin>()?.span()))
} else if lookahead.peek(keyword::inherent) {
Ok(PalletAttr::Inherent(content.parse::<keyword::inherent>()?.span()))
} else if lookahead.peek(keyword::storage) {
+19 -19
View File
@@ -650,7 +650,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
/// # use frame_support::dispatch;
/// # use frame_system::{Config, ensure_signed};
/// decl_module! {
/// pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
///
/// // Private functions are dispatchable, but not available to other
/// // FRAME pallets.
@@ -677,7 +677,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
/// * `Module`: The struct generated by the macro, with type `Config`.
/// * `Call`: The enum generated for every pallet, which implements
/// [`Callable`](./dispatch/trait.Callable.html).
/// * `origin`: Alias of `T::Origin`.
/// * `origin`: Alias of `T::RuntimeOrigin`.
/// * `Result`: The expected return type from pallet functions.
///
/// The first parameter of dispatchable functions must always be `origin`.
@@ -693,7 +693,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
/// # use frame_support::dispatch;
/// # use frame_system::{Config, ensure_signed};
/// decl_module! {
/// pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
/// #[weight = 0]
/// fn my_long_function(origin) -> dispatch::DispatchResult {
/// // Your implementation
@@ -728,7 +728,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
/// # use frame_support::{weights::Weight, dispatch::{DispatchResultWithPostInfo, WithPostDispatchInfo}};
/// # use frame_system::{Config, ensure_signed};
/// decl_module! {
/// pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
/// #[weight = 1_000_000]
/// fn my_long_function(origin, do_expensive_calc: bool) -> DispatchResultWithPostInfo {
/// ensure_signed(origin).map_err(|e| e.with_weight(Weight::from_ref_time(100_000)))?;
@@ -758,7 +758,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
/// # use frame_support::transactional;
/// # use frame_system::Config;
/// decl_module! {
/// pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
/// #[weight = 0]
/// #[transactional]
/// fn my_short_function(origin) {
@@ -779,7 +779,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
/// # use frame_support::dispatch;
/// # use frame_system::{Config, ensure_signed, ensure_root};
/// decl_module! {
/// pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
/// #[weight = 0]
/// fn my_privileged_function(origin) -> dispatch::DispatchResult {
/// ensure_root(origin)?;
@@ -819,7 +819,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
/// pub trait Config<I: Instance=DefaultInstance>: frame_system::Config {}
///
/// decl_module! {
/// pub struct Module<T: Config<I>, I: Instance = DefaultInstance> for enum Call where origin: T::Origin {
/// pub struct Module<T: Config<I>, I: Instance = DefaultInstance> for enum Call where origin: T::RuntimeOrigin {
/// // Your implementation
/// }
/// }
@@ -831,7 +831,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
///
/// ## Where clause
///
/// Besides the default `origin: T::Origin`, you can also pass other bounds to the module
/// Besides the default `origin: T::RuntimeOrigin`, you can also pass other bounds to the module
/// declaration. This where bound will be replicated to all types generated by this macro. The
/// chaining of multiple trait bounds with `+` is not supported. If multiple bounds for one type are
/// required, it needs to be split up into multiple bounds.
@@ -844,7 +844,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
/// pub trait Config: system::Config where Self::AccountId: From<u32> {}
///
/// decl_module! {
/// pub struct Module<T: Config> for enum Call where origin: T::Origin, T::AccountId: From<u32> {
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, T::AccountId: From<u32> {
/// // Your implementation
/// }
/// }
@@ -1885,7 +1885,7 @@ macro_rules! decl_module {
)
);
};
// Ignore any ident which is not `origin` with type `T::Origin`.
// Ignore any ident which is not `origin` with type `T::RuntimeOrigin`.
(@normalize
$(#[$attr:meta])*
pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(<I>, I: $instantiable:path $(= $module_default_instance:path)?)?>
@@ -1906,7 +1906,7 @@ macro_rules! decl_module {
$(#[weight = $weight:expr])?
$(#[$fn_attr:meta])*
$fn_vis:vis fn $fn_name:ident(
$origin:ident : T::Origin $( , $( #[$codec_attr:ident] )* $param_name:ident : $param:ty )* $(,)?
$origin:ident : T::RuntimeOrigin $( , $( #[$codec_attr:ident] )* $param_name:ident : $param:ty )* $(,)?
) $( -> $result:ty )* { $( $impl:tt )* }
$($rest:tt)*
) => {
@@ -2906,8 +2906,8 @@ macro_rules! decl_module {
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::traits::UnfilteredDispatchable
for $call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
{
type Origin = $origin_type;
fn dispatch_bypass_filter(self, _origin: Self::Origin) -> $crate::dispatch::DispatchResultWithPostInfo {
type RuntimeOrigin = $origin_type;
fn dispatch_bypass_filter(self, _origin: Self::RuntimeOrigin) -> $crate::dispatch::DispatchResultWithPostInfo {
match self {
$(
$call_type::$fn_name { $( $param_name ),* } => {
@@ -3200,7 +3200,7 @@ mod tests {
type AccountId;
type RuntimeCall;
type BaseCallFilter;
type Origin: crate::traits::OriginTrait<Call = Self::RuntimeCall>;
type RuntimeOrigin: crate::traits::OriginTrait<Call = Self::RuntimeCall>;
type BlockNumber: Into<u32>;
type PalletInfo: crate::traits::PalletInfo;
type DbWeight: Get<RuntimeDbWeight>;
@@ -3212,7 +3212,7 @@ mod tests {
}
decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system = system, T::AccountId: From<u32> {
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system = system, T::AccountId: From<u32> {
/// Hi, this is a comment.
#[weight = 0]
fn aux_0(_origin) -> DispatchResult { unreachable!() }
@@ -3347,7 +3347,7 @@ mod tests {
}
impl system::Config for TraitImpl {
type Origin = OuterOrigin;
type RuntimeOrigin = OuterOrigin;
type AccountId = u32;
type RuntimeCall = ();
type BaseCallFilter = frame_support::traits::Everything;
@@ -3500,7 +3500,7 @@ mod weight_tests {
use sp_weights::RuntimeDbWeight;
pub trait Config: 'static {
type Origin;
type RuntimeOrigin;
type Balance;
type BlockNumber;
type DbWeight: Get<RuntimeDbWeight>;
@@ -3517,7 +3517,7 @@ mod weight_tests {
}
impl Config for TraitImpl {
type Origin = u32;
type RuntimeOrigin = u32;
type BlockNumber = u32;
type Balance = u32;
type DbWeight = DbWeight;
@@ -3525,7 +3525,7 @@ mod weight_tests {
}
decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {
// no arguments, fixed weight
#[weight = 1000]
fn f00(_origin) { unimplemented!(); }
+1 -1
View File
@@ -51,7 +51,7 @@ pub use sp_runtime::traits::{BadOrigin, LookupError};
/// // exported in the metadata.
///
/// decl_module! {
/// pub struct Module<T: Config> for enum Call where origin: T::Origin {
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
/// type Error = MyError<T>;
///
/// #[weight = 0]
+3 -3
View File
@@ -845,7 +845,7 @@ pub mod tests {
pub trait Config: 'static {
type BlockNumber: Codec + EncodeLike + Default + TypeInfo;
type Origin;
type RuntimeOrigin;
type PalletInfo: crate::traits::PalletInfo;
type DbWeight: crate::traits::Get<crate::weights::RuntimeDbWeight>;
}
@@ -856,7 +856,7 @@ pub mod tests {
use super::Config;
decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {}
}
}
@@ -888,7 +888,7 @@ pub mod tests {
impl Config for Test {
type BlockNumber = u32;
type Origin = u32;
type RuntimeOrigin = u32;
type PalletInfo = PanicPalletInfo;
type DbWeight = ();
}
@@ -512,14 +512,14 @@ mod test_iterators {
use codec::{Decode, Encode};
pub trait Config: 'static {
type Origin;
type RuntimeOrigin;
type BlockNumber;
type PalletInfo: crate::traits::PalletInfo;
type DbWeight: crate::traits::Get<crate::weights::RuntimeDbWeight>;
}
crate::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {}
}
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
@@ -354,14 +354,14 @@ mod test_iterators {
use codec::{Decode, Encode};
pub trait Config: 'static {
type Origin;
type RuntimeOrigin;
type BlockNumber;
type PalletInfo: crate::traits::PalletInfo;
type DbWeight: crate::traits::Get<crate::weights::RuntimeDbWeight>;
}
crate::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {}
}
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
@@ -47,21 +47,21 @@ mod tests {
struct Runtime;
pub trait Config: 'static {
type Origin;
type RuntimeOrigin;
type BlockNumber;
type PalletInfo: crate::traits::PalletInfo;
type DbWeight: crate::traits::Get<crate::weights::RuntimeDbWeight>;
}
impl Config for Runtime {
type Origin = u32;
type RuntimeOrigin = u32;
type BlockNumber = u32;
type PalletInfo = crate::tests::PanicPalletInfo;
type DbWeight = ();
}
decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {}
}
crate::decl_storage! {
@@ -460,14 +460,14 @@ mod test_iterators {
use codec::{Decode, Encode};
pub trait Config: 'static {
type Origin;
type RuntimeOrigin;
type BlockNumber;
type PalletInfo: crate::traits::PalletInfo;
type DbWeight: crate::traits::Get<crate::weights::RuntimeDbWeight>;
}
crate::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {}
}
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
@@ -229,14 +229,14 @@ impl<
/// Implemented for pallet dispatchable type by `decl_module` and for runtime dispatchable by
/// `construct_runtime`.
pub trait UnfilteredDispatchable {
/// The origin type of the runtime, (i.e. `frame_system::Config::Origin`).
type Origin;
/// The origin type of the runtime, (i.e. `frame_system::Config::RuntimeOrigin`).
type RuntimeOrigin;
/// Dispatch this call but do not check the filter in origin.
fn dispatch_bypass_filter(self, origin: Self::Origin) -> DispatchResultWithPostInfo;
fn dispatch_bypass_filter(self, origin: Self::RuntimeOrigin) -> DispatchResultWithPostInfo;
}
/// Methods available on `frame_system::Config::Origin`.
/// Methods available on `frame_system::Config::RuntimeOrigin`.
pub trait OriginTrait: Sized {
/// Runtime call type, as in `frame_system::Config::Call`
type Call;
+14 -14
View File
@@ -132,7 +132,7 @@ pub mod v1 {
use super::*;
/// A type that can be used as a scheduler.
pub trait Anon<BlockNumber, Call, Origin> {
pub trait Anon<BlockNumber, Call, RuntimeOrigin> {
/// An address which can be used for removing a scheduled task.
type Address: Codec + Clone + Eq + EncodeLike + Debug + TypeInfo + MaxEncodedLen;
@@ -143,7 +143,7 @@ pub mod v1 {
when: DispatchTime<BlockNumber>,
maybe_periodic: Option<Period<BlockNumber>>,
priority: Priority,
origin: Origin,
origin: RuntimeOrigin,
call: Call,
) -> Result<Self::Address, DispatchError>;
@@ -177,7 +177,7 @@ pub mod v1 {
}
/// A type that can be used as a scheduler.
pub trait Named<BlockNumber, Call, Origin> {
pub trait Named<BlockNumber, Call, RuntimeOrigin> {
/// An address which can be used for removing a scheduled task.
type Address: Codec + Clone + Eq + EncodeLike + sp_std::fmt::Debug + MaxEncodedLen;
@@ -189,7 +189,7 @@ pub mod v1 {
when: DispatchTime<BlockNumber>,
maybe_periodic: Option<Period<BlockNumber>>,
priority: Priority,
origin: Origin,
origin: RuntimeOrigin,
call: Call,
) -> Result<Self::Address, ()>;
@@ -215,9 +215,9 @@ pub mod v1 {
fn next_dispatch_time(id: Vec<u8>) -> Result<BlockNumber, ()>;
}
impl<T, BlockNumber, Call, Origin> Anon<BlockNumber, Call, Origin> for T
impl<T, BlockNumber, Call, RuntimeOrigin> Anon<BlockNumber, Call, RuntimeOrigin> for T
where
T: v2::Anon<BlockNumber, Call, Origin>,
T: v2::Anon<BlockNumber, Call, RuntimeOrigin>,
{
type Address = T::Address;
@@ -225,7 +225,7 @@ pub mod v1 {
when: DispatchTime<BlockNumber>,
maybe_periodic: Option<Period<BlockNumber>>,
priority: Priority,
origin: Origin,
origin: RuntimeOrigin,
call: Call,
) -> Result<Self::Address, DispatchError> {
let c = MaybeHashed::<Call, T::Hash>::Value(call);
@@ -248,9 +248,9 @@ pub mod v1 {
}
}
impl<T, BlockNumber, Call, Origin> Named<BlockNumber, Call, Origin> for T
impl<T, BlockNumber, Call, RuntimeOrigin> Named<BlockNumber, Call, RuntimeOrigin> for T
where
T: v2::Named<BlockNumber, Call, Origin>,
T: v2::Named<BlockNumber, Call, RuntimeOrigin>,
{
type Address = T::Address;
@@ -259,7 +259,7 @@ pub mod v1 {
when: DispatchTime<BlockNumber>,
maybe_periodic: Option<Period<BlockNumber>>,
priority: Priority,
origin: Origin,
origin: RuntimeOrigin,
call: Call,
) -> Result<Self::Address, ()> {
let c = MaybeHashed::<Call, T::Hash>::Value(call);
@@ -287,7 +287,7 @@ pub mod v2 {
use super::*;
/// A type that can be used as a scheduler.
pub trait Anon<BlockNumber, Call, Origin> {
pub trait Anon<BlockNumber, Call, RuntimeOrigin> {
/// An address which can be used for removing a scheduled task.
type Address: Codec + Clone + Eq + EncodeLike + Debug + TypeInfo + MaxEncodedLen;
/// A means of expressing a call by the hash of its encoded data.
@@ -300,7 +300,7 @@ pub mod v2 {
when: DispatchTime<BlockNumber>,
maybe_periodic: Option<Period<BlockNumber>>,
priority: Priority,
origin: Origin,
origin: RuntimeOrigin,
call: MaybeHashed<Call, Self::Hash>,
) -> Result<Self::Address, DispatchError>;
@@ -334,7 +334,7 @@ pub mod v2 {
}
/// A type that can be used as a scheduler.
pub trait Named<BlockNumber, Call, Origin> {
pub trait Named<BlockNumber, Call, RuntimeOrigin> {
/// An address which can be used for removing a scheduled task.
type Address: Codec + Clone + Eq + EncodeLike + sp_std::fmt::Debug + MaxEncodedLen;
/// A means of expressing a call by the hash of its encoded data.
@@ -348,7 +348,7 @@ pub mod v2 {
when: DispatchTime<BlockNumber>,
maybe_periodic: Option<Period<BlockNumber>>,
priority: Priority,
origin: Origin,
origin: RuntimeOrigin,
call: MaybeHashed<Call, Self::Hash>,
) -> Result<Self::Address, ()>;
@@ -65,7 +65,7 @@ impl frame_system::Config for Runtime {
type BlockHashCount = ConstU64<2400>;
type Version = Version;
type AccountData = ();
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type RuntimeEvent = RuntimeEvent;
+2 -2
View File
@@ -25,7 +25,7 @@
/// The configuration trait
pub trait Config: 'static {
/// The runtime origin type.
type Origin: codec::Codec + codec::EncodeLike + Default + scale_info::TypeInfo;
type RuntimeOrigin: codec::Codec + codec::EncodeLike + Default + scale_info::TypeInfo;
/// The block number type.
type BlockNumber: codec::Codec + codec::EncodeLike + Default + scale_info::TypeInfo;
/// The information about the pallet setup in the runtime.
@@ -36,7 +36,7 @@ pub trait Config: 'static {
frame_support::decl_module! {
/// Some test module
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {}
}
/// A PalletInfo implementation which just panics.
@@ -49,7 +49,7 @@ mod module1 {
frame_support::decl_module! {
pub struct Module<T: Config<I>, I: Instance = DefaultInstance> for enum Call
where origin: <T as system::Config>::Origin, system=system
where origin: <T as system::Config>::RuntimeOrigin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
@@ -89,7 +89,7 @@ mod module2 {
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call
where origin: <T as system::Config>::Origin, system=system
where origin: <T as system::Config>::RuntimeOrigin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
@@ -134,7 +134,7 @@ mod nested {
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call
where origin: <T as system::Config>::Origin, system=system
where origin: <T as system::Config>::RuntimeOrigin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
@@ -180,7 +180,7 @@ pub mod module3 {
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call
where origin: <T as system::Config>::Origin, system=system
where origin: <T as system::Config>::RuntimeOrigin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
@@ -247,7 +247,7 @@ fn test_pub() -> AccountId {
impl system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Hash = H256;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type RuntimeEvent = RuntimeEvent;
@@ -12,7 +12,7 @@ impl test_pallet::Config for Runtime {}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -8,7 +8,7 @@ mod pallet_old {
}
decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {}
}
}
@@ -46,7 +46,7 @@ impl pallet::Config for Runtime {}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -21,7 +21,7 @@ impl pallet::Config for Runtime {}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -21,7 +21,7 @@ impl pallet::Config for Runtime {}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -21,7 +21,7 @@ impl pallet::Config for Runtime {}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -21,7 +21,7 @@ impl pallet::Config for Runtime {}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -21,7 +21,7 @@ impl pallet::Config for Runtime {}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -46,39 +46,6 @@ help: if you import `Origin`, refer to it directly
58 - }
|
error[E0412]: cannot find type `Origin` in module `pallet`
--> tests/construct_runtime_ui/undefined_origin_part.rs:49:1
|
49 | / construct_runtime! {
50 | | pub enum Runtime where
51 | | Block = Block,
52 | | NodeBlock = Block,
... |
57 | | }
58 | | }
| |_^ not found in `pallet`
|
= note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
|
1 | use crate::Origin;
|
1 | use frame_system::Origin;
|
help: if you import `Origin`, refer to it directly
|
49 - construct_runtime! {
50 - pub enum Runtime where
51 - Block = Block,
52 - NodeBlock = Block,
53 - UncheckedExtrinsic = UncheckedExtrinsic
54 - {
55 - System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
56 - Pallet: pallet::{Pallet, Origin},
57 - }
58 - }
|
error[E0282]: type annotations needed
--> tests/construct_runtime_ui/undefined_origin_part.rs:49:1
|
@@ -21,7 +21,7 @@ impl pallet::Config for Runtime {}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -1,5 +1,5 @@
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {
fn integrity_test() {}
fn integrity_test() {}
@@ -2,7 +2,7 @@ error: `integrity_test` can only be passed once as input.
--> tests/decl_module_ui/reserved_keyword_two_times_integrity_test.rs:1:1
|
1 | / frame_support::decl_module! {
2 | | pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
2 | | pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {
3 | | fn integrity_test() {}
4 | |
5 | | fn integrity_test() {}
@@ -1,5 +1,5 @@
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {
fn on_initialize() -> Weight {
0
}
@@ -2,7 +2,7 @@ error: `on_initialize` can only be passed once as input.
--> $DIR/reserved_keyword_two_times_on_initialize.rs:1:1
|
1 | / frame_support::decl_module! {
2 | | pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
2 | | pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {
3 | | fn on_initialize() -> Weight {
4 | | 0
... |
@@ -23,7 +23,7 @@ mod tests {
use sp_io::TestExternalities;
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
pub trait Config: frame_support_test::Config {
@@ -94,7 +94,7 @@ mod tests {
struct TraitImpl {}
impl frame_support_test::Config for TraitImpl {
type Origin = u32;
type RuntimeOrigin = u32;
type BlockNumber = u32;
type PalletInfo = frame_support_test::PanicPalletInfo;
type DbWeight = ();
@@ -617,7 +617,7 @@ mod test2 {
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
type PairOf<T> = (T, T);
@@ -639,7 +639,7 @@ mod test2 {
struct TraitImpl {}
impl frame_support_test::Config for TraitImpl {
type Origin = u32;
type RuntimeOrigin = u32;
type BlockNumber = u32;
type PalletInfo = frame_support_test::PanicPalletInfo;
type DbWeight = ();
@@ -695,7 +695,7 @@ mod test3 {
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
frame_support::decl_storage! {
trait Store for Module<T: Config> as Test {
@@ -708,7 +708,7 @@ mod test3 {
struct TraitImpl {}
impl frame_support_test::Config for TraitImpl {
type Origin = u32;
type RuntimeOrigin = u32;
type BlockNumber = u32;
type PalletInfo = frame_support_test::PanicPalletInfo;
type DbWeight = ();
@@ -726,7 +726,7 @@ mod test_append_and_len {
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
#[derive(PartialEq, Eq, Clone, Encode, Decode, scale_info::TypeInfo)]
@@ -753,7 +753,7 @@ mod test_append_and_len {
struct Test {}
impl frame_support_test::Config for Test {
type Origin = u32;
type RuntimeOrigin = u32;
type BlockNumber = u32;
type PalletInfo = frame_support_test::PanicPalletInfo;
type DbWeight = ();
@@ -18,7 +18,7 @@
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
frame_support::decl_storage!{
@@ -18,7 +18,7 @@
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
frame_support::decl_storage!{
@@ -18,7 +18,7 @@
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
frame_support::decl_storage!{
@@ -28,7 +28,7 @@ mod no_instance {
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
frame_support::decl_storage! {
@@ -53,7 +53,7 @@ mod instance {
frame_support::decl_module! {
pub struct Module<T: Config<I>, I: Instance = DefaultInstance>
for enum Call where origin: T::Origin, system=frame_support_test {}
for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
frame_support::decl_storage! {
@@ -18,7 +18,7 @@
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {}
}
frame_support::decl_storage! {
@@ -31,7 +31,7 @@ struct Test;
impl frame_support_test::Config for Test {
type BlockNumber = u32;
type Origin = ();
type RuntimeOrigin = ();
type PalletInfo = frame_support_test::PanicPalletInfo;
type DbWeight = ();
}
+12 -12
View File
@@ -51,14 +51,14 @@ mod module1 {
<Self as system::Config>::BlockNumber: From<u32>,
{
type RuntimeEvent: From<Event<Self, I>> + Into<<Self as system::Config>::RuntimeEvent>;
type Origin: From<Origin<Self, I>>;
type RuntimeOrigin: From<Origin<Self, I>>;
type SomeParameter: Get<u32>;
type GenericType: Default + Clone + Codec + EncodeLike + TypeInfo;
}
frame_support::decl_module! {
pub struct Module<T: Config<I>, I: Instance> for enum Call where
origin: <T as system::Config>::Origin,
origin: <T as system::Config>::RuntimeOrigin,
system = system,
T::BlockNumber: From<u32>
{
@@ -155,14 +155,14 @@ mod module2 {
pub trait Config<I = DefaultInstance>: system::Config {
type Amount: Parameter + Default;
type RuntimeEvent: From<Event<Self, I>> + Into<<Self as system::Config>::RuntimeEvent>;
type Origin: From<Origin<Self, I>>;
type RuntimeOrigin: From<Origin<Self, I>>;
}
impl<T: Config<I>, I: Instance> Currency for Module<T, I> {}
frame_support::decl_module! {
pub struct Module<T: Config<I>, I: Instance=DefaultInstance> for enum Call where
origin: <T as system::Config>::Origin,
origin: <T as system::Config>::RuntimeOrigin,
system = system
{
fn deposit_event() = default;
@@ -228,41 +228,41 @@ mod module3 {
}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: <T as system::Config>::Origin, system=system {}
pub struct Module<T: Config> for enum Call where origin: <T as system::Config>::RuntimeOrigin, system=system {}
}
}
impl module1::Config<module1::Instance1> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type SomeParameter = ConstU32<100>;
type GenericType = u32;
}
impl module1::Config<module1::Instance2> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type SomeParameter = ConstU32<100>;
type GenericType = u32;
}
impl module2::Config for Runtime {
type Amount = u16;
type RuntimeEvent = RuntimeEvent;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
}
impl module2::Config<module2::Instance1> for Runtime {
type Amount = u32;
type RuntimeEvent = RuntimeEvent;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
}
impl module2::Config<module2::Instance2> for Runtime {
type Amount = u32;
type RuntimeEvent = RuntimeEvent;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
}
impl module2::Config<module2::Instance3> for Runtime {
type Amount = u64;
type RuntimeEvent = RuntimeEvent;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
}
impl module3::Config for Runtime {
type Currency = Module2_2;
@@ -277,7 +277,7 @@ pub type Index = u64;
impl system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Hash = H256;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type RuntimeEvent = RuntimeEvent;
@@ -86,7 +86,7 @@ mod module {
pub trait Config: system::Config + TypeInfo {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=system {}
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=system {}
}
#[derive(Encode, Decode, Copy, Clone, Serialize, Deserialize)]
@@ -160,7 +160,7 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, RuntimeCall, Sign
impl system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Hash = H256;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type RuntimeEvent = RuntimeEvent;
+21 -21
View File
@@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! Origin tests for construct_runtime macro
//! RuntimeOrigin tests for construct_runtime macro
#![recursion_limit = "128"]
@@ -38,7 +38,7 @@ mod nested {
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call
where origin: <T as system::Config>::Origin, system=system
where origin: <T as system::Config>::RuntimeOrigin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
@@ -80,7 +80,7 @@ pub mod module {
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call
where origin: <T as system::Config>::Origin, system=system
where origin: <T as system::Config>::RuntimeOrigin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
@@ -146,7 +146,7 @@ impl Contains<RuntimeCall> for BaseCallFilter {
impl system::Config for RuntimeOriginTest {
type BaseCallFilter = BaseCallFilter;
type Hash = H256;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type BlockNumber = BlockNumber;
type AccountId = u32;
type RuntimeEvent = RuntimeEvent;
@@ -178,40 +178,40 @@ fn origin_default_filter() {
let accepted_call = nested::module::Call::fail {}.into();
let rejected_call = module::Call::fail {}.into();
assert_eq!(Origin::root().filter_call(&accepted_call), true);
assert_eq!(Origin::root().filter_call(&rejected_call), true);
assert_eq!(Origin::none().filter_call(&accepted_call), true);
assert_eq!(Origin::none().filter_call(&rejected_call), false);
assert_eq!(Origin::signed(0).filter_call(&accepted_call), true);
assert_eq!(Origin::signed(0).filter_call(&rejected_call), false);
assert_eq!(Origin::from(Some(0)).filter_call(&accepted_call), true);
assert_eq!(Origin::from(Some(0)).filter_call(&rejected_call), false);
assert_eq!(Origin::from(None).filter_call(&accepted_call), true);
assert_eq!(Origin::from(None).filter_call(&rejected_call), false);
assert_eq!(Origin::from(nested::module::Origin).filter_call(&accepted_call), true);
assert_eq!(Origin::from(nested::module::Origin).filter_call(&rejected_call), false);
assert_eq!(RuntimeOrigin::root().filter_call(&accepted_call), true);
assert_eq!(RuntimeOrigin::root().filter_call(&rejected_call), true);
assert_eq!(RuntimeOrigin::none().filter_call(&accepted_call), true);
assert_eq!(RuntimeOrigin::none().filter_call(&rejected_call), false);
assert_eq!(RuntimeOrigin::signed(0).filter_call(&accepted_call), true);
assert_eq!(RuntimeOrigin::signed(0).filter_call(&rejected_call), false);
assert_eq!(RuntimeOrigin::from(Some(0)).filter_call(&accepted_call), true);
assert_eq!(RuntimeOrigin::from(Some(0)).filter_call(&rejected_call), false);
assert_eq!(RuntimeOrigin::from(None).filter_call(&accepted_call), true);
assert_eq!(RuntimeOrigin::from(None).filter_call(&rejected_call), false);
assert_eq!(RuntimeOrigin::from(nested::module::Origin).filter_call(&accepted_call), true);
assert_eq!(RuntimeOrigin::from(nested::module::Origin).filter_call(&rejected_call), false);
let mut origin = Origin::from(Some(0));
let mut origin = RuntimeOrigin::from(Some(0));
origin.add_filter(|c| matches!(c, RuntimeCall::Module(_)));
assert_eq!(origin.filter_call(&accepted_call), false);
assert_eq!(origin.filter_call(&rejected_call), false);
// Now test for root origin and filters:
let mut origin = Origin::from(Some(0));
origin.set_caller_from(Origin::root());
let mut origin = RuntimeOrigin::from(Some(0));
origin.set_caller_from(RuntimeOrigin::root());
assert!(matches!(origin.caller, OriginCaller::system(system::RawOrigin::Root)));
// Root origin bypass all filter.
assert_eq!(origin.filter_call(&accepted_call), true);
assert_eq!(origin.filter_call(&rejected_call), true);
origin.set_caller_from(Origin::from(Some(0)));
origin.set_caller_from(RuntimeOrigin::from(Some(0)));
// Back to another signed origin, the filtered are now effective again
assert_eq!(origin.filter_call(&accepted_call), true);
assert_eq!(origin.filter_call(&rejected_call), false);
origin.set_caller_from(Origin::root());
origin.set_caller_from(RuntimeOrigin::root());
origin.reset_filter();
// Root origin bypass all filter, even when they are reset.
+6 -4
View File
@@ -552,8 +552,10 @@ pub mod pallet2 {
#[frame_support::pallet]
pub mod pallet3 {
#[pallet::config]
pub trait Config: frame_system::Config<Origin = <Self as Config>::Origin> {
type Origin;
pub trait Config:
frame_system::Config<RuntimeOrigin = <Self as Config>::RuntimeOrigin>
{
type RuntimeOrigin;
}
#[pallet::pallet]
@@ -578,7 +580,7 @@ frame_support::parameter_types!(
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -618,7 +620,7 @@ impl pallet4::Config for Runtime {}
#[cfg(feature = "frame-feature-testing")]
impl pallet3::Config for Runtime {
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
}
pub type Header = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
@@ -70,7 +70,7 @@ mod pallet_old {
);
decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
type Error = Error<T>;
fn deposit_event() = default;
const SomeConst: T::Balance = T::SomeConst::get();
@@ -226,7 +226,7 @@ pub mod pallet {
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -56,7 +56,7 @@ mod pallet_old {
decl_module! {
pub struct Module<T: Config<I>, I: Instance = DefaultInstance> for enum Call
where origin: T::Origin
where origin: T::RuntimeOrigin
{
type Error = Error<T, I>;
fn deposit_event() = default;
@@ -210,7 +210,7 @@ impl frame_system::Config for Runtime {
type BlockLength = ();
type DbWeight = ();
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -286,7 +286,7 @@ pub mod pallet2 {
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -43,7 +43,7 @@ frame_support::decl_error!(
);
frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Trait> for enum Call where origin: T::RuntimeOrigin {
fn deposit_event() = default;
type Error = Error<T>;
const Foo: u32 = u32::MAX;
@@ -126,7 +126,7 @@ mod tests {
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = sp_core::H256;
@@ -59,7 +59,7 @@ pub mod decl_pallet {
pub trait Config: frame_system::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
#[weight = 0]
pub fn set_value(_origin, value: u32) {
DeclValue::put(value);
@@ -86,7 +86,7 @@ impl frame_system::Config for Runtime {
type BlockLength = ();
type DbWeight = ();
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u32;
type RuntimeCall = RuntimeCall;
@@ -256,11 +256,11 @@ fn storage_layer_in_pallet_call() {
TestExternalities::default().execute_with(|| {
use sp_runtime::traits::Dispatchable;
let call1 = RuntimeCall::MyPallet(pallet::Call::set_value { value: 2 });
assert_ok!(call1.dispatch(Origin::signed(0)));
assert_ok!(call1.dispatch(RuntimeOrigin::signed(0)));
assert_eq!(Value::<Runtime>::get(), 2);
let call2 = RuntimeCall::MyPallet(pallet::Call::set_value { value: 1 });
assert_noop!(call2.dispatch(Origin::signed(0)), Error::<Runtime>::Revert);
assert_noop!(call2.dispatch(RuntimeOrigin::signed(0)), Error::<Runtime>::Revert);
});
}
@@ -271,12 +271,15 @@ fn storage_layer_in_decl_pallet_call() {
use sp_runtime::traits::Dispatchable;
let call1 = RuntimeCall::DeclPallet(decl_pallet::Call::set_value { value: 2 });
assert_ok!(call1.dispatch(Origin::signed(0)));
assert_ok!(call1.dispatch(RuntimeOrigin::signed(0)));
assert_eq!(decl_pallet::DeclValue::get(), 2);
let call2 = RuntimeCall::DeclPallet(decl_pallet::Call::set_value { value: 1 });
assert_noop!(call2.dispatch(Origin::signed(0)), "Revert!");
assert_noop!(call2.dispatch(RuntimeOrigin::signed(0)), "Revert!");
// Calling the function directly also works with storage layers.
assert_noop!(decl_pallet::Module::<Runtime>::set_value(Origin::signed(1), 1), "Revert!");
assert_noop!(
decl_pallet::Module::<Runtime>::set_value(RuntimeOrigin::signed(1), 1),
"Revert!"
);
});
}
@@ -31,7 +31,7 @@ use sp_std::result;
pub trait Config: frame_support_test::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=frame_support_test {
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=frame_support_test {
#[weight = 0]
#[transactional]
fn value_commits(_origin, v: u32) {
@@ -57,7 +57,7 @@ frame_support::decl_storage! {
struct Runtime;
impl frame_support_test::Config for Runtime {
type Origin = u32;
type RuntimeOrigin = u32;
type BlockNumber = u32;
type PalletInfo = frame_support_test::PanicPalletInfo;
type DbWeight = ();
+2 -2
View File
@@ -22,7 +22,7 @@ use frame_support::{
};
pub trait Config: 'static + Eq + Clone {
type Origin: Into<Result<RawOrigin<Self::AccountId>, Self::Origin>>
type RuntimeOrigin: Into<Result<RawOrigin<Self::AccountId>, Self::RuntimeOrigin>>
+ From<RawOrigin<Self::AccountId>>;
type BaseCallFilter: frame_support::traits::Contains<Self::RuntimeCall>;
@@ -36,7 +36,7 @@ pub trait Config: 'static + Eq + Clone {
}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {
pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, system=self {
#[weight = 0]
fn noop(_origin) {}
}