Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 1102f84

Browse files
bkchrgavofyork
authored andcommitted
Make impl_outer_event! aware of required generic parameters (#729)
1 parent b9849fe commit 1102f84

File tree

5 files changed

+116
-22
lines changed

5 files changed

+116
-22
lines changed

node/runtime/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ pub type Contract = contract::Module<Runtime>;
215215
impl_outer_event! {
216216
pub enum Event for Runtime {
217217
//consensus,
218-
balances,
218+
balances<T>,
219219
//timetstamp,
220-
session,
221-
staking,
222-
democracy,
223-
council,
224-
council_voting,
225-
council_motions,
226-
treasury
220+
session<T>,
221+
staking<T>,
222+
democracy<T>,
223+
council<T>,
224+
council_voting<T>,
225+
council_motions<T>,
226+
treasury<T>,
227227
}
228228
}
229229

srml/council/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ mod tests {
144144

145145
impl_outer_event! {
146146
pub enum Event for Test {
147-
balances, democracy, seats, voting, motions
147+
balances<T>, democracy<T>, seats<T>, voting<T>, motions<T>,
148148
}
149149
}
150150

@@ -235,4 +235,4 @@ mod tests {
235235
pub type Council = seats::Module<Test>;
236236
pub type CouncilVoting = voting::Module<Test>;
237237
pub type CouncilMotions = motions::Module<Test>;
238-
}
238+
}

srml/executive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ mod tests {
242242

243243
impl_outer_event!{
244244
pub enum MetaEvent for Runtime {
245-
balances
245+
balances<T>,
246246
}
247247
}
248248

srml/support/src/event.rs

Lines changed: 103 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,79 @@ macro_rules! __events_to_json {
270270

271271
#[macro_export]
272272
macro_rules! impl_outer_event {
273-
($(#[$attr:meta])* pub enum $name:ident for $runtime:ident { $( $module:ident ),* }) => {
273+
(
274+
$(#[$attr:meta])*
275+
pub enum $name:ident for $runtime:ident {
276+
$module:ident<T>,
277+
$( $rest:tt $( <$t:ident> )*, )*
278+
}
279+
) => {
280+
impl_outer_event!(
281+
$( #[$attr] )*;
282+
$name;
283+
$runtime;
284+
Modules { $( $rest $(<$t>)*, )* };
285+
$module::Event<$runtime>,;
286+
);
287+
};
288+
(
289+
$(#[$attr:meta])*
290+
pub enum $name:ident for $runtime:ident {
291+
$module:ident,
292+
$( $rest:tt $( <$t:ident> )*, )*
293+
}
294+
) => {
295+
impl_outer_event!(
296+
$( #[$attr] )*;
297+
$name;
298+
$runtime;
299+
Modules { $( $rest $(<$t>)*, )* };
300+
$module::Event,;
301+
);
302+
};
303+
(
304+
$(#[$attr:meta])*;
305+
$name:ident;
306+
$runtime:ident;
307+
Modules {
308+
$module:ident<T>,
309+
$( $rest:tt $( <$t:ident> )*, )*
310+
};
311+
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
312+
) => {
313+
impl_outer_event!(
314+
$( #[$attr] )*;
315+
$name;
316+
$runtime;
317+
Modules { $( $rest $(<$t>)*, )* };
318+
$( $module_name::Event $( <$generic_param> )*, )* $module::Event<$runtime>,;
319+
);
320+
};
321+
(
322+
$(#[$attr:meta])*;
323+
$name:ident;
324+
$runtime:ident;
325+
Modules {
326+
$module:ident,
327+
$( $rest:tt, )*
328+
};
329+
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
330+
) => {
331+
impl_outer_event!(
332+
$( #[$attr] )*;
333+
$name;
334+
$runtime;
335+
Modules { $( $rest, )* };
336+
$( $module_name::Event $( <$generic_param> )*, )* $module::Event,;
337+
);
338+
};
339+
(
340+
$(#[$attr:meta])*;
341+
$name:ident;
342+
$runtime:ident;
343+
Modules {};
344+
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
345+
) => {
274346
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
275347
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
276348
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
@@ -279,7 +351,7 @@ macro_rules! impl_outer_event {
279351
pub enum $name {
280352
system(system::Event),
281353
$(
282-
$module($module::Event<$runtime>),
354+
$module_name( $module_name::Event $( <$generic_param> )* ),
283355
)*
284356
}
285357
impl From<system::Event> for $name {
@@ -288,13 +360,17 @@ macro_rules! impl_outer_event {
288360
}
289361
}
290362
$(
291-
impl From<$module::Event<$runtime>> for $name {
292-
fn from(x: $module::Event<$runtime>) -> Self {
293-
$name::$module(x)
363+
impl From<$module_name::Event $( <$generic_param> )*> for $name {
364+
fn from(x: $module_name::Event $( <$generic_param> )*) -> Self {
365+
$name::$module_name(x)
294366
}
295367
}
296368
)*
297-
__impl_outer_event_json_metadata!($runtime; $name; $( $module )*);
369+
__impl_outer_event_json_metadata!(
370+
$runtime;
371+
$name;
372+
$( $module_name::Event $( <$generic_param> )*, )*;
373+
);
298374
}
299375
}
300376

@@ -304,7 +380,7 @@ macro_rules! __impl_outer_event_json_metadata {
304380
(
305381
$runtime:ident;
306382
$event_name:ident;
307-
$( $module:ident )*
383+
$( $module_name:ident::Event $( <$generic_param:ident> )*, )*;
308384
) => {
309385
impl $runtime {
310386
#[allow(dead_code)]
@@ -313,8 +389,8 @@ macro_rules! __impl_outer_event_json_metadata {
313389
("system", system::Event::event_json_metadata)
314390
$(
315391
, (
316-
stringify!($module),
317-
$module::Event::<$runtime>::event_json_metadata
392+
stringify!($module_name),
393+
$module_name::Event $( ::<$generic_param> )*::event_json_metadata
318394
)
319395
)*
320396
];
@@ -393,12 +469,22 @@ mod tests {
393469
);
394470
}
395471

472+
mod event_module3 {
473+
decl_event!(
474+
pub enum Event {
475+
HiEvent,
476+
}
477+
);
478+
}
479+
396480
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Deserialize, Serialize)]
397481
pub struct TestRuntime;
398482

399483
impl_outer_event! {
400484
pub enum TestEvent for TestRuntime {
401-
event_module, event_module2
485+
event_module<T>,
486+
event_module2<T>,
487+
event_module3,
402488
}
403489
}
404490

@@ -435,6 +521,13 @@ mod tests {
435521
" }"
436522
)
437523
),
524+
("event_module3",
525+
concat!(
526+
"{",
527+
r#" "HiEvent": { "params": null, "description": [ ] }"#,
528+
" }"
529+
)
530+
),
438531
]
439532
);
440533

srml/support/src/metadata.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ mod tests {
200200

201201
impl_outer_event! {
202202
pub enum TestEvent for TestRuntime {
203-
event_module, event_module2
203+
event_module<T>,
204+
event_module2<T>,
204205
}
205206
}
206207

0 commit comments

Comments
 (0)