mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 04:27:57 +00:00
Make impl_outer_origin! support generic Origins (#732)
* Make `impl_outer_origin!` support generic `Origin`s * Support empty outer origin
This commit is contained in:
@@ -63,6 +63,8 @@ mod hashable;
|
||||
mod event;
|
||||
#[macro_use]
|
||||
pub mod metadata;
|
||||
#[macro_use]
|
||||
mod origin;
|
||||
|
||||
pub use self::storage::{StorageVec, StorageList, StorageValue, StorageMap};
|
||||
pub use self::hashable::Hashable;
|
||||
@@ -120,73 +122,3 @@ macro_rules! assert_ok {
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
pub enum Void {}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_outer_origin {
|
||||
($(#[$attr:meta])* pub enum $name:ident for $trait:ident where system = $system:ident { $( $module:ident ),* }) => {
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
$(#[$attr])*
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum $name {
|
||||
system($system::Origin<$trait>),
|
||||
$(
|
||||
$module($module::Origin),
|
||||
)*
|
||||
#[allow(dead_code)]
|
||||
Void($crate::Void)
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
impl $name {
|
||||
pub const INHERENT: Self = $name::system($system::RawOrigin::Inherent);
|
||||
pub const ROOT: Self = $name::system($system::RawOrigin::Root);
|
||||
pub fn signed(by: <$trait as $system::Trait>::AccountId) -> Self {
|
||||
$name::system($system::RawOrigin::Signed(by))
|
||||
}
|
||||
}
|
||||
impl From<$system::Origin<$trait>> for $name {
|
||||
fn from(x: $system::Origin<$trait>) -> Self {
|
||||
$name::system(x)
|
||||
}
|
||||
}
|
||||
impl Into<Option<$system::Origin<$trait>>> for $name {
|
||||
fn into(self) -> Option<$system::Origin<$trait>> {
|
||||
if let $name::system(l) = self {
|
||||
Some(l)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Option<<$trait as $system::Trait>::AccountId>> for $name {
|
||||
fn from(x: Option<<$trait as $system::Trait>::AccountId>) -> Self {
|
||||
<$system::Origin<$trait>>::from(x).into()
|
||||
}
|
||||
}
|
||||
$(
|
||||
impl From<$module::Origin> for $name {
|
||||
fn from(x: $module::Origin) -> Self {
|
||||
$name::$module(x)
|
||||
}
|
||||
}
|
||||
impl Into<Option<$module::Origin>> for $name {
|
||||
fn into(self) -> Option<$module::Origin> {
|
||||
if let $name::$module(l) = self {
|
||||
Some(l)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
($(#[$attr:meta])* pub enum $name:ident for $trait:ident { $( $module:ident ),* }) => {
|
||||
impl_outer_origin! {
|
||||
$(#[$attr])*
|
||||
pub enum $name for $trait where system = system {
|
||||
$( $module ),*
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user