Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make impl_outer_event! aware of required generic parameters
  • Loading branch information
bkchr committed Sep 12, 2018
commit a3c1192e4e4e3240a8c91add4f053408b4f41188
16 changes: 8 additions & 8 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ pub type Contract = contract::Module<Runtime>;
impl_outer_event! {
pub enum Event for Runtime {
//consensus,
balances,
balances<T>,
//timetstamp,
session,
staking,
democracy,
council,
council_voting,
council_motions,
treasury
session<T>,
staking<T>,
democracy<T>,
council<T>,
council_voting<T>,
council_motions<T>,
treasury<T>,
}
}

Expand Down
4 changes: 2 additions & 2 deletions srml/council/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mod tests {

impl_outer_event! {
pub enum Event for Test {
balances, democracy, seats, voting, motions
balances<T>, democracy<T>, seats<T>, voting<T>, motions<T>,
}
}

Expand Down Expand Up @@ -235,4 +235,4 @@ mod tests {
pub type Council = seats::Module<Test>;
pub type CouncilVoting = voting::Module<Test>;
pub type CouncilMotions = motions::Module<Test>;
}
}
2 changes: 1 addition & 1 deletion srml/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ mod tests {

impl_outer_event!{
pub enum MetaEvent for Runtime {
balances
balances<T>,
}
}

Expand Down
113 changes: 103 additions & 10 deletions srml/support/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,79 @@ macro_rules! __events_to_json {

#[macro_export]
macro_rules! impl_outer_event {
($(#[$attr:meta])* pub enum $name:ident for $runtime:ident { $( $module:ident ),* }) => {
(
$(#[$attr:meta])*
pub enum $name:ident for $runtime:ident {
$module:ident<T>,
$( $rest:tt $( <$t:ident> )*, )*
}
) => {
impl_outer_event!(
$( #[$attr] )*;
$name;
$runtime;
Modules { $( $rest $(<$t>)*, )* };
$module::Event<$runtime>,;
);
};
(
$(#[$attr:meta])*
pub enum $name:ident for $runtime:ident {
$module:ident,
$( $rest:tt $( <$t:ident> )*, )*
}
) => {
impl_outer_event!(
$( #[$attr] )*;
$name;
$runtime;
Modules { $( $rest $(<$t>)*, )* };
$module::Event,;
);
};
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
Modules {
$module:ident<T>,
$( $rest:tt $( <$t:ident> )*, )*
};
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
) => {
impl_outer_event!(
$( #[$attr] )*;
$name;
$runtime;
Modules { $( $rest $(<$t>)*, )* };
$( $module_name::Event $( <$generic_param> )*, )* $module::Event<$runtime>,;
);
};
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
Modules {
$module:ident,
$( $rest:tt, )*
};
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
) => {
impl_outer_event!(
$( #[$attr] )*;
$name;
$runtime;
Modules { $( $rest, )* };
$( $module_name::Event $( <$generic_param> )*, )* $module::Event,;
);
};
(
$(#[$attr:meta])*;
$name:ident;
$runtime:ident;
Modules {};
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
) => {
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
Expand All @@ -279,7 +351,7 @@ macro_rules! impl_outer_event {
pub enum $name {
system(system::Event),
$(
$module($module::Event<$runtime>),
$module_name( $module_name::Event $( <$generic_param> )* ),
)*
}
impl From<system::Event> for $name {
Expand All @@ -288,13 +360,17 @@ macro_rules! impl_outer_event {
}
}
$(
impl From<$module::Event<$runtime>> for $name {
fn from(x: $module::Event<$runtime>) -> Self {
$name::$module(x)
impl From<$module_name::Event $( <$generic_param> )*> for $name {
fn from(x: $module_name::Event $( <$generic_param> )*) -> Self {
$name::$module_name(x)
}
}
)*
__impl_outer_event_json_metadata!($runtime; $name; $( $module )*);
__impl_outer_event_json_metadata!(
$runtime;
$name;
$( $module_name::Event $( <$generic_param> )*, )*;
);
}
}

Expand All @@ -304,7 +380,7 @@ macro_rules! __impl_outer_event_json_metadata {
(
$runtime:ident;
$event_name:ident;
$( $module:ident )*
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
) => {
impl $runtime {
#[allow(dead_code)]
Expand All @@ -313,8 +389,8 @@ macro_rules! __impl_outer_event_json_metadata {
("system", system::Event::event_json_metadata)
$(
, (
stringify!($module),
$module::Event::<$runtime>::event_json_metadata
stringify!($module_name),
$module_name::Event $( ::<$generic_param> )*::event_json_metadata
)
)*
];
Expand Down Expand Up @@ -393,12 +469,22 @@ mod tests {
);
}

mod event_module3 {
decl_event!(
pub enum Event {
HiEvent,
}
);
}

#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Deserialize, Serialize)]
pub struct TestRuntime;

impl_outer_event! {
pub enum TestEvent for TestRuntime {
event_module, event_module2
event_module<T>,
event_module2<T>,
event_module3,
}
}

Expand Down Expand Up @@ -435,6 +521,13 @@ mod tests {
" }"
)
),
("event_module3",
concat!(
"{",
r#" "HiEvent": { "params": null, "description": [ ] }"#,
" }"
)
),
]
);

Expand Down
3 changes: 2 additions & 1 deletion srml/support/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ mod tests {

impl_outer_event! {
pub enum TestEvent for TestRuntime {
event_module, event_module2
event_module<T>,
event_module2<T>,
}
}

Expand Down