From b0bc40bb41786aed12fd8218b287da660a8d3ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 11 Sep 2018 17:52:17 +0200 Subject: [PATCH 1/3] Improve and simplify `decl_event!` - RawEvent is not required anymore to be written in the defintion - Events with and without parameters are now supported everywhere --- srml/balances/src/lib.rs | 7 +++- srml/council/src/motions.rs | 4 +- srml/council/src/seats.rs | 4 +- srml/council/src/voting.rs | 4 +- srml/democracy/src/lib.rs | 5 ++- srml/example/src/lib.rs | 4 +- srml/session/src/lib.rs | 4 +- srml/staking/src/lib.rs | 5 ++- srml/support/src/event.rs | 77 +++++++++++++++--------------------- srml/support/src/metadata.rs | 6 +-- srml/treasury/src/lib.rs | 5 ++- 11 files changed, 54 insertions(+), 71 deletions(-) diff --git a/srml/balances/src/lib.rs b/srml/balances/src/lib.rs index c14cd6235787d..b27ecbc8f1bff 100644 --- a/srml/balances/src/lib.rs +++ b/srml/balances/src/lib.rs @@ -136,8 +136,11 @@ decl_module! { } decl_event!( - pub enum Event with RawEvent - where ::AccountId, ::AccountIndex, ::Balance { + pub enum Event where + AccountId = ::AccountId, + AccountIndex = ::AccountIndex, + Balance = ::Balance + { /// A new account was created. NewAccount(AccountId, AccountIndex, NewAccountOutcome), /// An account was reaped. diff --git a/srml/council/src/motions.rs b/srml/council/src/motions.rs index babbec78347b9..1e72e0154c367 100644 --- a/srml/council/src/motions.rs +++ b/srml/council/src/motions.rs @@ -49,8 +49,8 @@ pub enum Origin { /// Event for this module. decl_event!( - pub enum Event with RawEvent - where ::Hash, ::AccountId + pub enum Event + where Hash = ::Hash, AccountId = ::AccountId { /// A motion (given hash) has been proposed (by given account) with a threshold (given u32). Proposed(AccountId, ProposalIndex, Hash, u32), diff --git a/srml/council/src/seats.rs b/srml/council/src/seats.rs index 8941dbeccb919..ad5693f3e25ae 100644 --- a/srml/council/src/seats.rs +++ b/srml/council/src/seats.rs @@ -156,9 +156,7 @@ decl_storage! { decl_event!( /// An event in this module. - pub enum Event with RawEvent - where ::AccountId - { + pub enum Event where AccountId = ::AccountId { /// reaped voter, reaper VoterReaped(AccountId, AccountId), /// slashed reaper diff --git a/srml/council/src/voting.rs b/srml/council/src/voting.rs index 886adfc7bf664..4cafe03941331 100644 --- a/srml/council/src/voting.rs +++ b/srml/council/src/voting.rs @@ -55,9 +55,7 @@ decl_storage! { /// An event in this module. decl_event!( - pub enum Event with RawEvent - where ::Hash - { + pub enum Event where Hash = ::Hash { /// A voting tally has happened for a referendum cancelation vote. /// Last three are yes, no, abstain counts. TallyCancelation(Hash, u32, u32, u32), diff --git a/srml/democracy/src/lib.rs b/srml/democracy/src/lib.rs index f74f37094d8ae..3f5d56c0ca691 100644 --- a/srml/democracy/src/lib.rs +++ b/srml/democracy/src/lib.rs @@ -110,8 +110,9 @@ decl_storage! { decl_event!( /// An event in this module. - pub enum Event with RawEvent - where ::Balance, ::AccountId + pub enum Event where + Balance = ::Balance, + AccountId = ::AccountId { Tabled(PropIndex, Balance, Vec), Started(ReferendumIndex, VoteThreshold), diff --git a/srml/example/src/lib.rs b/srml/example/src/lib.rs index 77e77ef1ad4df..2918a74270422 100644 --- a/srml/example/src/lib.rs +++ b/srml/example/src/lib.rs @@ -121,9 +121,7 @@ decl_module! { /// circumstances that have happened that users, Dapps and/or chain explorers would find /// interesting and otherwise difficult to detect. decl_event!( - pub enum Event with RawEvent - where ::Balance - { + pub enum Event where B = ::Balance { // Just a normal `enum`, here's a dummy event to ensure it compiles. /// Dummy event, just here so there's a generic type that's used. Dummy(B), diff --git a/srml/session/src/lib.rs b/srml/session/src/lib.rs index 61cf47a095717..48f2bc331cd01 100644 --- a/srml/session/src/lib.rs +++ b/srml/session/src/lib.rs @@ -84,9 +84,7 @@ decl_module! { /// An event in this module. decl_event!( - pub enum Event with RawEvent - where ::BlockNumber - { + pub enum Event where BlockNumber = ::BlockNumber { /// New session has happened. Note that the argument is the session index, not the block /// number as the type might suggest. NewSession(BlockNumber), diff --git a/srml/staking/src/lib.rs b/srml/staking/src/lib.rs index 1e0ec4b7b2078..b4699ba9c2223 100644 --- a/srml/staking/src/lib.rs +++ b/srml/staking/src/lib.rs @@ -120,8 +120,9 @@ decl_module! { /// An event in this module. decl_event!( - pub enum Event with RawEvent - where ::Balance, ::AccountId + pub enum Event where + Balance = ::Balance, + AccountId = ::AccountId { /// All validators have been rewarded by the given balance. Reward(Balance), diff --git a/srml/support/src/event.rs b/srml/support/src/event.rs index a9767f51bf74e..5c9e641d55983 100644 --- a/srml/support/src/event.rs +++ b/srml/support/src/event.rs @@ -19,23 +19,22 @@ macro_rules! decl_event { ( $(#[$attr:meta])* - pub enum Event<$( $evt_generic_param:ident )*> with RawEvent<$( $generic_param:ident ),*> - where $( <$generic:ident as $trait:path>::$trait_type:ident),* { + pub enum Event<$evt_generic_param:ident> + where $($generic_param:ident = <$generic:ident as $trait:path>::$trait_type:ident),* + { $( - $(#[doc = $doc_attr:tt])* - $event:ident( $( $param:path ),* ), + $events:tt )* } ) => { - pub type Event<$( $evt_generic_param )*> = RawEvent<$( <$generic as $trait>::$trait_type ),*>; + pub type Event<$evt_generic_param> = RawEvent<$( <$generic as $trait>::$trait_type ),*>; // 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))] $(#[$attr])* pub enum RawEvent<$( $generic_param ),*> { $( - $( #[doc = $doc_attr] )* - $event($( $param ),*), + $events )* } impl<$( $generic_param ),*> From> for () { @@ -44,16 +43,7 @@ macro_rules! decl_event { impl<$( $generic_param ),*> RawEvent<$( $generic_param ),*> { #[allow(dead_code)] pub fn event_json_metadata() -> &'static str { - concat!( - "{", - __impl_event_json_metadata!(""; - $( - $event ( $( $param ),* ); - __function_doc_to_json!(""; $($doc_attr)*); - )* - ), - " }" - ) + concat!("{", __events_to_json!(""; $( $events )* ), " }") } } }; @@ -61,8 +51,7 @@ macro_rules! decl_event { $(#[$attr:meta])* pub enum Event { $( - $(#[doc = $doc_attr:tt])* - $event:ident, + $events:tt )* } ) => { @@ -72,8 +61,7 @@ macro_rules! decl_event { $(#[$attr])* pub enum Event { $( - $( #[doc = $doc_attr] )* - $event, + $events )* } impl From for () { @@ -82,16 +70,7 @@ macro_rules! decl_event { impl Event { #[allow(dead_code)] pub fn event_json_metadata() -> &'static str { - concat!( - "{", - __impl_event_json_metadata!(""; - $( - $event; - __function_doc_to_json!(""; $($doc_attr)*); - )* - ), - " }" - ) + concat!("{", __events_to_json!(""; $( $events )* ), " }") } } } @@ -99,29 +78,30 @@ macro_rules! decl_event { #[macro_export] #[doc(hidden)] -macro_rules! __impl_event_json_metadata { +macro_rules! __events_to_json { ( $prefix_str:expr; - $event:ident( $first_param:path $(, $param:path )* ); - $event_doc:expr; + $( #[doc = $doc_attr:tt] )* + $event:ident( $first_param:path $(, $param:path )* ), $( $rest:tt )* ) => { concat!($prefix_str, " ", "\"", stringify!($event), r#"": { "params": [ ""#, stringify!($first_param), "\"" $(, concat!(", \"", stringify!($param), "\"") )*, r#" ], "description": ["#, - $event_doc, " ] }", - __impl_event_json_metadata!(","; $( $rest )*) + __function_doc_to_json!(""; $( $doc_attr )*), " ] }", + __events_to_json!(","; $( $rest )*) ) }; ( $prefix_str:expr; - $event:ident; - $event_doc:expr; + $( #[doc = $doc_attr:tt] )* + $event:ident, $( $rest:tt )* ) => { concat!($prefix_str, " ", "\"", stringify!($event), - r#"": { "params": null, "description": ["#, $event_doc, " ] }", - __impl_event_json_metadata!(","; $( $rest )*) + r#"": { "params": null, "description": ["#, + __function_doc_to_json!(""; $( $doc_attr )*), " ] }", + __events_to_json!(","; $( $rest )*) ) }; ( @@ -223,11 +203,12 @@ mod tests { } decl_event!( - pub enum Event with RawEvent - where ::Balance + pub enum Event where Balance = ::Balance { /// Hi, I am a comment. TestEvent(Balance), + /// Dog + EventWithoutParams, } ); } @@ -243,8 +224,7 @@ mod tests { } decl_event!( - pub enum Event with RawEvent - where ::Balance + pub enum Event where Balance = ::Balance { TestEvent(Balance), } @@ -277,7 +257,14 @@ mod tests { const EXPECTED_METADATA: (&str, &[(&str, &str)]) = ( "TestEvent", &[ ("system", r#"{ "SystemEvent": { "params": null, "description": [ ] } }"#), - ("event_module", r#"{ "TestEvent": { "params": [ "Balance" ], "description": [ " Hi, I am a comment." ] } }"#), + ("event_module", + concat!( + "{", + r#" "TestEvent": { "params": [ "Balance" ], "description": [ " Hi, I am a comment." ] },"#, + r#" "EventWithoutParams": { "params": null, "description": [ " Dog" ] }"#, + " }" + ) + ), ("event_module2", r#"{ "TestEvent": { "params": [ "Balance" ], "description": [ ] } }"#), ] ); diff --git a/srml/support/src/metadata.rs b/srml/support/src/metadata.rs index 5fc57636c3f7a..34134c227ec40 100644 --- a/srml/support/src/metadata.rs +++ b/srml/support/src/metadata.rs @@ -151,8 +151,7 @@ mod tests { } decl_event!( - pub enum Event with RawEvent - where ::Balance + pub enum Event where Balance = ::Balance { /// Hi, I am a comment. TestEvent(Balance), @@ -179,8 +178,7 @@ mod tests { } decl_event!( - pub enum Event with RawEvent - where ::Balance + pub enum Event where Balance = ::Balance { TestEvent(Balance), } diff --git a/srml/treasury/src/lib.rs b/srml/treasury/src/lib.rs index 867cd631bcace..27bd5501dc966 100644 --- a/srml/treasury/src/lib.rs +++ b/srml/treasury/src/lib.rs @@ -136,8 +136,9 @@ decl_storage! { /// An event in this module. decl_event!( - pub enum Event with RawEvent - where ::Balance, ::AccountId + pub enum Event where + Balance = ::Balance, + AccountId = ::AccountId { /// New proposal. Proposed(ProposalIndex), From 683cb98f922212bfd953fe06571012208fe0fbfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 12 Sep 2018 10:34:48 +0200 Subject: [PATCH 2/3] Make `decl_event!` more flexible with the automatic naming of generic parameters The macro will now automatically derive the name of a generic parameter from the trait type name, if no explicit name is given. `where Balance = ::Balance` can be simplified to `where ::Balance`. --- srml/balances/src/lib.rs | 6 +- srml/council/src/motions.rs | 4 +- srml/council/src/seats.rs | 2 +- srml/council/src/voting.rs | 2 +- srml/democracy/src/lib.rs | 5 +- srml/session/src/lib.rs | 2 +- srml/staking/src/lib.rs | 5 +- srml/support/src/event.rs | 217 +++++++++++++++++++++++++++++++---- srml/support/src/metadata.rs | 4 +- srml/treasury/src/lib.rs | 5 +- 10 files changed, 205 insertions(+), 47 deletions(-) diff --git a/srml/balances/src/lib.rs b/srml/balances/src/lib.rs index b27ecbc8f1bff..ee4fb6ceaa97f 100644 --- a/srml/balances/src/lib.rs +++ b/srml/balances/src/lib.rs @@ -137,9 +137,9 @@ decl_module! { decl_event!( pub enum Event where - AccountId = ::AccountId, - AccountIndex = ::AccountIndex, - Balance = ::Balance + ::AccountId, + ::AccountIndex, + ::Balance { /// A new account was created. NewAccount(AccountId, AccountIndex, NewAccountOutcome), diff --git a/srml/council/src/motions.rs b/srml/council/src/motions.rs index 1e72e0154c367..4e34cd1518df2 100644 --- a/srml/council/src/motions.rs +++ b/srml/council/src/motions.rs @@ -49,9 +49,7 @@ pub enum Origin { /// Event for this module. decl_event!( - pub enum Event - where Hash = ::Hash, AccountId = ::AccountId - { + pub enum Event where ::Hash, ::AccountId { /// A motion (given hash) has been proposed (by given account) with a threshold (given u32). Proposed(AccountId, ProposalIndex, Hash, u32), /// A motion (given hash) has been voted on by given account, leaving diff --git a/srml/council/src/seats.rs b/srml/council/src/seats.rs index ad5693f3e25ae..145d440a8a455 100644 --- a/srml/council/src/seats.rs +++ b/srml/council/src/seats.rs @@ -156,7 +156,7 @@ decl_storage! { decl_event!( /// An event in this module. - pub enum Event where AccountId = ::AccountId { + pub enum Event where ::AccountId { /// reaped voter, reaper VoterReaped(AccountId, AccountId), /// slashed reaper diff --git a/srml/council/src/voting.rs b/srml/council/src/voting.rs index 4cafe03941331..c53b4005860ee 100644 --- a/srml/council/src/voting.rs +++ b/srml/council/src/voting.rs @@ -55,7 +55,7 @@ decl_storage! { /// An event in this module. decl_event!( - pub enum Event where Hash = ::Hash { + pub enum Event where ::Hash { /// A voting tally has happened for a referendum cancelation vote. /// Last three are yes, no, abstain counts. TallyCancelation(Hash, u32, u32, u32), diff --git a/srml/democracy/src/lib.rs b/srml/democracy/src/lib.rs index 3f5d56c0ca691..e8f67e05a4d99 100644 --- a/srml/democracy/src/lib.rs +++ b/srml/democracy/src/lib.rs @@ -110,10 +110,7 @@ decl_storage! { decl_event!( /// An event in this module. - pub enum Event where - Balance = ::Balance, - AccountId = ::AccountId - { + pub enum Event where ::Balance, ::AccountId { Tabled(PropIndex, Balance, Vec), Started(ReferendumIndex, VoteThreshold), Passed(ReferendumIndex), diff --git a/srml/session/src/lib.rs b/srml/session/src/lib.rs index 48f2bc331cd01..23cae40b5f40f 100644 --- a/srml/session/src/lib.rs +++ b/srml/session/src/lib.rs @@ -84,7 +84,7 @@ decl_module! { /// An event in this module. decl_event!( - pub enum Event where BlockNumber = ::BlockNumber { + pub enum Event where ::BlockNumber { /// New session has happened. Note that the argument is the session index, not the block /// number as the type might suggest. NewSession(BlockNumber), diff --git a/srml/staking/src/lib.rs b/srml/staking/src/lib.rs index b4699ba9c2223..5a7e151dffa23 100644 --- a/srml/staking/src/lib.rs +++ b/srml/staking/src/lib.rs @@ -120,10 +120,7 @@ decl_module! { /// An event in this module. decl_event!( - pub enum Event where - Balance = ::Balance, - AccountId = ::AccountId - { + pub enum Event where ::Balance, ::AccountId { /// All validators have been rewarded by the given balance. Reward(Balance), /// One validator (and their nominators) has been given a offline-warning (they're still diff --git a/srml/support/src/event.rs b/srml/support/src/event.rs index 5c9e641d55983..9b6e2f6d0b453 100644 --- a/srml/support/src/event.rs +++ b/srml/support/src/event.rs @@ -14,60 +14,217 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -/// Implement an `Event`/`RawEvent` for a module. +/// Implement the `Event` for a module. +/// +/// # Simple Event Example: +/// +/// ```rust +/// #[macro_use] +/// extern crate substrate_runtime_support; +/// extern crate substrate_codec as codec; +/// #[macro_use] +/// extern crate substrate_codec_derive; +/// #[macro_use] +/// extern crate serde_derive; +/// +/// decl_event!( +/// pub enum Event { +/// Success, +/// Failure(String), +/// } +/// ); +///# fn main() {} +/// ``` +/// +/// # Generic Event Example: +/// +/// ```rust +/// #[macro_use] +/// extern crate substrate_runtime_support; +/// extern crate substrate_codec as codec; +/// #[macro_use] +/// extern crate substrate_codec_derive; +/// #[macro_use] +/// extern crate serde_derive; +/// +/// trait Trait { +/// type Balance; +/// type Token; +/// } +/// +/// mod event1 { +/// // Event that specifies the generic parameter explicitly (`Balance`). +/// decl_event!( +/// pub enum Event where Balance = ::Balance { +/// Message(Balance), +/// } +/// ); +/// } +/// +/// mod event2 { +/// // Event that uses the generic parameter `Balance`. +/// // If no name for the generic parameter is speciefied explicitly, +/// // the name will be taken from the type name of the trait. +/// decl_event!( +/// pub enum Event where ::Balance { +/// Message(Balance), +/// } +/// ); +/// } +/// +/// mod event3 { +/// // And we even support declaring multiple generic parameters! +/// decl_event!( +/// pub enum Event where ::Balance, ::Token { +/// Message(Balance, Token), +/// } +/// ); +/// } +///# fn main() {} +/// ``` +/// +/// The syntax for generic events requires the `where`. #[macro_export] macro_rules! decl_event { ( $(#[$attr:meta])* - pub enum Event<$evt_generic_param:ident> - where $($generic_param:ident = <$generic:ident as $trait:path>::$trait_type:ident),* + pub enum Event<$evt_generic_param:ident> where + $( $( $generic_rename:ident = )* <$generic:ident as $trait:path>::$trait_type:ident ),* { $( $events:tt )* } ) => { - pub type Event<$evt_generic_param> = RawEvent<$( <$generic as $trait>::$trait_type ),*>; + __decl_generic_event!( + $( #[ $attr ] )*; + $evt_generic_param; + $( $( $generic_rename = )* <$generic as $trait>::$trait_type ),*; + Events { $( $events )* }; + ); + }; + ( + $(#[$attr:meta])* + pub enum Event { + $( + $events:tt + )* + } + ) => { // 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))] $(#[$attr])* - pub enum RawEvent<$( $generic_param ),*> { + pub enum Event { $( $events )* } - impl<$( $generic_param ),*> From> for () { - fn from(_: RawEvent<$( $generic_param ),*>) -> () { () } + impl From for () { + fn from(_: Event) -> () { () } } - impl<$( $generic_param ),*> RawEvent<$( $generic_param ),*> { + impl Event { #[allow(dead_code)] pub fn event_json_metadata() -> &'static str { concat!("{", __events_to_json!(""; $( $events )* ), " }") } } + } +} + +#[macro_export] +#[doc(hidden)] +macro_rules! __decl_generic_event { + ( + $(#[$attr:meta])*; + $event_generic_param:ident; + $generic_rename:ident = <$generic:ident as $trait:path>::$trait_type:ident + $(, $( $rest_gen_rename:ident = )* <$rest_gen:ident as $rest_trait:path>::$rest_trait_type:ident )*; + Events { $( $events:tt )* }; + ) => { + __decl_generic_event!( + $( #[ $attr ] )*; + $event_generic_param; + $( $( $rest_gen_rename = )* <$rest_gen as $rest_trait>::$rest_trait_type ),*; + Events { $( $events )* }; + $generic_rename; + <$generic as $trait>::$trait_type; + ); }; ( - $(#[$attr:meta])* - pub enum Event { - $( - $events:tt - )* - } + $(#[$attr:meta])*; + $event_generic_param:ident; + $generic_rename:ident = <$generic:ident as $trait:path>::$trait_type:ident + $(, $( $rest_gen_rename:ident = )* <$rest_gen:ident as $rest_trait:path>::$rest_trait_type:ident )*; + Events { $( $events:tt )* }; + $( $parsed_generic_params:ident ),*; + $( <$parsed_generic:ident as $parsed_trait:path>::$parsed_trait_type:ident ),*; + ) => { + __decl_generic_event!( + $( #[ $attr ] )*; + $event_generic_param; + $( $( $rest_gen_rename = )* <$rest_gen as $rest_trait>::$rest_trait_type ),*; + Events { $( $events )* }; + $( $parsed_generic_params ),*, $generic_rename; + $( <$parsed_generic as $parsed_trait>::$parsed_trait_type ),*, <$generic as $trait>::$trait_type; + ); + }; + ( + $(#[$attr:meta])*; + $event_generic_param:ident; + <$generic:ident as $trait:path>::$trait_type:ident + $(, $( $rest_gen_rename:ident = )* <$rest_gen:ident as $rest_trait:path>::$rest_trait_type:ident )*; + Events { $( $events:tt )* }; + ) => { + __decl_generic_event!( + $( #[ $attr ] )*; + $event_generic_param; + $( $( $rest_gen_rename = )* <$rest_gen as $rest_trait>::$rest_trait_type ),*; + Events { $( $events )* }; + $trait_type; + <$generic as $trait>::$trait_type; + ); + }; + ( + $(#[$attr:meta])*; + $event_generic_param:ident; + <$generic:ident as $trait:path>::$trait_type:ident + $(, $( $rest_gen_rename:ident = )* <$rest_gen:ident as $rest_trait:path>::$rest_trait_type:ident )*; + Events { $( $events:tt )* }; + $( $parsed_generic_params:ident ),*; + $( <$parsed_generic:ident as $parsed_trait:path>::$parsed_trait_type:ident ),*; + ) => { + __decl_generic_event!( + $( #[ $attr ] )*; + $event_generic_param; + $( $( $rest_gen_rename = )* <$rest_gen as $rest_trait>::$rest_trait_type ),*; + Events { $( $events )* }; + $( $parsed_generic_params ),*, $trait_type; + $( <$parsed_generic as $parsed_trait>::$parsed_trait_type ),*, <$generic as $trait>::$trait_type; + ); + }; + ( + $(#[$attr:meta])*; + $event_generic_param:ident; + ; + Events { $( $events:tt )* }; + $( $generic_param:ident ),*; + $( <$generic:ident as $trait:path>::$trait_type:ident ),*; ) => { + pub type Event<$event_generic_param> = RawEvent<$( <$generic as $trait>::$trait_type ),*>; // 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))] $(#[$attr])* - pub enum Event { + pub enum RawEvent<$( $generic_param ),*> { $( $events )* } - impl From for () { - fn from(_: Event) -> () { () } + impl<$( $generic_param ),*> From> for () { + fn from(_: RawEvent<$( $generic_param ),*>) -> () { () } } - impl Event { + impl<$( $generic_param ),*> RawEvent<$( $generic_param ),*> { #[allow(dead_code)] pub fn event_json_metadata() -> &'static str { concat!("{", __events_to_json!(""; $( $events )* ), " }") @@ -203,10 +360,11 @@ mod tests { } decl_event!( - pub enum Event where Balance = ::Balance + /// Event without renaming the generic parameter `Balance` and `Origin`. + pub enum Event where ::Balance, ::Origin { /// Hi, I am a comment. - TestEvent(Balance), + TestEvent(Balance, Origin), /// Dog EventWithoutParams, } @@ -224,9 +382,13 @@ mod tests { } decl_event!( - pub enum Event where Balance = ::Balance + /// Event with renamed generic parameter + pub enum Event where + BalanceRenamed = ::Balance, + OriginRenamed = ::Origin { - TestEvent(Balance), + TestEvent(BalanceRenamed), + TestOrigin(OriginRenamed), } ); } @@ -260,12 +422,19 @@ mod tests { ("event_module", concat!( "{", - r#" "TestEvent": { "params": [ "Balance" ], "description": [ " Hi, I am a comment." ] },"#, + r#" "TestEvent": { "params": [ "Balance", "Origin" ], "description": [ " Hi, I am a comment." ] },"#, r#" "EventWithoutParams": { "params": null, "description": [ " Dog" ] }"#, " }" ) ), - ("event_module2", r#"{ "TestEvent": { "params": [ "Balance" ], "description": [ ] } }"#), + ("event_module2", + concat!( + "{", + r#" "TestEvent": { "params": [ "BalanceRenamed" ], "description": [ ] },"#, + r#" "TestOrigin": { "params": [ "OriginRenamed" ], "description": [ ] }"#, + " }" + ) + ), ] ); diff --git a/srml/support/src/metadata.rs b/srml/support/src/metadata.rs index 34134c227ec40..280583b989b9c 100644 --- a/srml/support/src/metadata.rs +++ b/srml/support/src/metadata.rs @@ -151,7 +151,7 @@ mod tests { } decl_event!( - pub enum Event where Balance = ::Balance + pub enum Event where ::Balance { /// Hi, I am a comment. TestEvent(Balance), @@ -178,7 +178,7 @@ mod tests { } decl_event!( - pub enum Event where Balance = ::Balance + pub enum Event where ::Balance { TestEvent(Balance), } diff --git a/srml/treasury/src/lib.rs b/srml/treasury/src/lib.rs index 27bd5501dc966..4b1e55a7db283 100644 --- a/srml/treasury/src/lib.rs +++ b/srml/treasury/src/lib.rs @@ -136,10 +136,7 @@ decl_storage! { /// An event in this module. decl_event!( - pub enum Event where - Balance = ::Balance, - AccountId = ::AccountId - { + pub enum Event where ::Balance, ::AccountId { /// New proposal. Proposed(ProposalIndex), /// We have ended a spend period and will now allocate funds. From a09caf8086764f2f90541ea09f84cdb9e764821b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 12 Sep 2018 13:36:30 +0200 Subject: [PATCH 3/3] Adapts to latest refactoring changes --- srml/support/src/event.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/srml/support/src/event.rs b/srml/support/src/event.rs index 9b6e2f6d0b453..6f0e1760a037b 100644 --- a/srml/support/src/event.rs +++ b/srml/support/src/event.rs @@ -20,10 +20,10 @@ /// /// ```rust /// #[macro_use] -/// extern crate substrate_runtime_support; -/// extern crate substrate_codec as codec; +/// extern crate srml_support; +/// extern crate parity_codec as codec; /// #[macro_use] -/// extern crate substrate_codec_derive; +/// extern crate parity_codec_derive; /// #[macro_use] /// extern crate serde_derive; /// @@ -40,10 +40,10 @@ /// /// ```rust /// #[macro_use] -/// extern crate substrate_runtime_support; -/// extern crate substrate_codec as codec; +/// extern crate srml_support; +/// extern crate parity_codec as codec; /// #[macro_use] -/// extern crate substrate_codec_derive; +/// extern crate parity_codec_derive; /// #[macro_use] /// extern crate serde_derive; ///