diff --git a/substrate/node-template/runtime/src/template.rs b/substrate/node-template/runtime/src/template.rs index 7f9d03fbb7..c1fa6f2d31 100644 --- a/substrate/node-template/runtime/src/template.rs +++ b/substrate/node-template/runtime/src/template.rs @@ -35,7 +35,7 @@ decl_module! { pub struct Module for enum Call where origin: T::Origin { // Initializing events // this is needed only if you are using events in your module - fn deposit_event() = default; + fn deposit_event() = default; // Just a dummy entry point. // function that can be called by the external world as an extrinsics call diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index a36801c44b..6fec9abe7a 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -80,7 +80,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. spec_version: 154, - impl_version: 156, + impl_version: 157, apis: RUNTIME_API_VERSIONS, }; diff --git a/substrate/srml/assets/src/lib.rs b/substrate/srml/assets/src/lib.rs index c8b24662be..a8268d1463 100644 --- a/substrate/srml/assets/src/lib.rs +++ b/substrate/srml/assets/src/lib.rs @@ -149,7 +149,7 @@ pub trait Trait: system::Trait { decl_module! { pub struct Module for enum Call where origin: T::Origin { - fn deposit_event() = default; + fn deposit_event() = default; /// Issue a new class of fungible assets. There are, and will only ever be, `total` /// such assets and they'll all belong to the `origin` initially. It will have an /// identifier `AssetId` instance: this will be specified in the `Issued` event. diff --git a/substrate/srml/balances/src/lib.rs b/substrate/srml/balances/src/lib.rs index 0c83897045..e37ce5c4de 100644 --- a/substrate/srml/balances/src/lib.rs +++ b/substrate/srml/balances/src/lib.rs @@ -413,7 +413,7 @@ decl_module! { /// The fee to be paid for making a transaction; the per-byte portion. const TransactionByteFee: T::Balance = T::TransactionByteFee::get(); - fn deposit_event() = default; + fn deposit_event() = default; /// Transfer some liquid free balance to another account. /// diff --git a/substrate/srml/collective/src/lib.rs b/substrate/srml/collective/src/lib.rs index 3828988015..ea616beb4b 100644 --- a/substrate/srml/collective/src/lib.rs +++ b/substrate/srml/collective/src/lib.rs @@ -138,7 +138,7 @@ decl_event!( // operational class. decl_module! { pub struct Module, I: Instance=DefaultInstance> for enum Call where origin: ::Origin { - fn deposit_event() = default; + fn deposit_event() = default; /// Set the collective's membership manually to `new_members`. Be nice to the chain and /// provide it pre-sorted. diff --git a/substrate/srml/contracts/src/lib.rs b/substrate/srml/contracts/src/lib.rs index f8485f848a..7618551298 100644 --- a/substrate/srml/contracts/src/lib.rs +++ b/substrate/srml/contracts/src/lib.rs @@ -504,7 +504,7 @@ decl_module! { /// default value is 10_000_000. const BlockGasLimit: Gas = T::BlockGasLimit::get(); - fn deposit_event() = default; + fn deposit_event() = default; /// Updates the schedule for metering contracts. /// diff --git a/substrate/srml/democracy/src/lib.rs b/substrate/srml/democracy/src/lib.rs index 4853d192c4..244d653662 100644 --- a/substrate/srml/democracy/src/lib.rs +++ b/substrate/srml/democracy/src/lib.rs @@ -354,7 +354,7 @@ decl_module! { /// Period in blocks where an external proposal may not be re-submitted after being vetoed. const CooloffPeriod: T::BlockNumber = T::CooloffPeriod::get(); - fn deposit_event() = default; + fn deposit_event() = default; /// Propose a sensitive action to be taken. /// diff --git a/substrate/srml/elections/src/lib.rs b/substrate/srml/elections/src/lib.rs index 9c49b9055b..63a4509acc 100644 --- a/substrate/srml/elections/src/lib.rs +++ b/substrate/srml/elections/src/lib.rs @@ -296,7 +296,7 @@ decl_module! { /// The chunk size of the approval vector. const APPROVAL_SET_SIZE: u32 = APPROVAL_SET_SIZE as u32; - fn deposit_event() = default; + fn deposit_event() = default; /// Set candidate approvals. Approval slots stay valid as long as candidates in those slots /// are registered. diff --git a/substrate/srml/example/src/lib.rs b/substrate/srml/example/src/lib.rs index 3de961f5cd..247be01239 100644 --- a/substrate/srml/example/src/lib.rs +++ b/substrate/srml/example/src/lib.rs @@ -363,7 +363,7 @@ decl_module! { /// It is also possible to provide a custom implementation. /// For non-generic events, the generic parameter just needs to be dropped, so that it /// looks like: `fn deposit_event() = default;`. - fn deposit_event() = default; + fn deposit_event() = default; /// This is your public interface. Be extremely careful. /// This is just a simple example of how to interact with the module from the external /// world. diff --git a/substrate/srml/generic-asset/src/lib.rs b/substrate/srml/generic-asset/src/lib.rs index 016e39127f..abd6e1302f 100644 --- a/substrate/srml/generic-asset/src/lib.rs +++ b/substrate/srml/generic-asset/src/lib.rs @@ -324,7 +324,7 @@ impl Into> for PermissionLatest for enum Call where origin: T::Origin { - fn deposit_event() = default; + fn deposit_event() = default; /// Create a new kind of asset. fn create(origin, options: AssetOptions) -> Result { diff --git a/substrate/srml/im-online/src/lib.rs b/substrate/srml/im-online/src/lib.rs index 06a350655b..fe604ca788 100644 --- a/substrate/srml/im-online/src/lib.rs +++ b/substrate/srml/im-online/src/lib.rs @@ -238,7 +238,7 @@ decl_storage! { decl_module! { pub struct Module for enum Call where origin: T::Origin { - fn deposit_event() = default; + fn deposit_event() = default; fn heartbeat( origin, diff --git a/substrate/srml/indices/src/lib.rs b/substrate/srml/indices/src/lib.rs index 5bf838f321..31e825d2c8 100644 --- a/substrate/srml/indices/src/lib.rs +++ b/substrate/srml/indices/src/lib.rs @@ -73,7 +73,7 @@ pub trait Trait: system::Trait { decl_module! { pub struct Module for enum Call where origin: T::Origin { - fn deposit_event() = default; + fn deposit_event() = default; } } diff --git a/substrate/srml/membership/src/lib.rs b/substrate/srml/membership/src/lib.rs index e36351ddbe..aed8b598f7 100644 --- a/substrate/srml/membership/src/lib.rs +++ b/substrate/srml/membership/src/lib.rs @@ -99,7 +99,7 @@ decl_module! { for enum Call where origin: T::Origin { - fn deposit_event() = default; + fn deposit_event() = default; /// Add a member `who` to the set. /// diff --git a/substrate/srml/scored-pool/src/lib.rs b/substrate/srml/scored-pool/src/lib.rs index 1348b73864..f2f5d426d9 100644 --- a/substrate/srml/scored-pool/src/lib.rs +++ b/substrate/srml/scored-pool/src/lib.rs @@ -228,7 +228,7 @@ decl_module! { for enum Call where origin: T::Origin { - fn deposit_event() = default; + fn deposit_event() = default; /// Every `Period` blocks the `Members` set is refreshed from the /// highest scoring members in the pool. diff --git a/substrate/srml/staking/src/lib.rs b/substrate/srml/staking/src/lib.rs index d0c60bfa46..e7824d36e0 100644 --- a/substrate/srml/staking/src/lib.rs +++ b/substrate/srml/staking/src/lib.rs @@ -674,7 +674,7 @@ decl_module! { /// Number of eras that staked funds must remain bonded for. const BondingDuration: EraIndex = T::BondingDuration::get(); - fn deposit_event() = default; + fn deposit_event() = default; fn on_finalize() { // Set the start of the first era. @@ -1595,7 +1595,7 @@ impl ReportOffence R::report_offence(reporters, offence) } else { >::deposit_event( - RawEvent::OldSlashingReportDiscarded(offence_session).into() + RawEvent::OldSlashingReportDiscarded(offence_session) ) } } diff --git a/substrate/srml/sudo/src/lib.rs b/substrate/srml/sudo/src/lib.rs index 65a15b4abf..d91f61bd2f 100644 --- a/substrate/srml/sudo/src/lib.rs +++ b/substrate/srml/sudo/src/lib.rs @@ -106,7 +106,7 @@ pub trait Trait: system::Trait { decl_module! { // Simple declaration of the `Module` type. Lets the macro know what it's working on. pub struct Module for enum Call where origin: T::Origin { - fn deposit_event() = default; + fn deposit_event() = default; /// Authenticates the sudo key and dispatches a function call with `Root` origin. /// diff --git a/substrate/srml/support/src/dispatch.rs b/substrate/srml/support/src/dispatch.rs index d77da619a9..86c21da67b 100644 --- a/substrate/srml/support/src/dispatch.rs +++ b/substrate/srml/support/src/dispatch.rs @@ -203,7 +203,7 @@ impl Parameter for T where T: Codec + Clone + Eq {} /// * `deposit_event`: Helper function for depositing an [event](https://docs.substrate.dev/docs/event-enum). /// The default behavior is to call `deposit_event` from the [System module](../srml_system/index.html). /// However, you can write your own implementation for events in your runtime. To use the default behavior, -/// add `fn deposit_event() = default;` to your `Module`. +/// add `fn deposit_event() = default;` to your `Module`. /// /// The following reserved functions also take the block number (with type `T::BlockNumber`) as an optional input: /// @@ -288,7 +288,7 @@ macro_rules! decl_module { { $( $constants:tt )* } [ $( $dispatchables:tt )* ] $(#[doc = $doc_attr:tt])* - $vis:vis fn deposit_event $(<$dpeg:ident $(, $dpeg_instance:ident)?>)* () = default; + $vis:vis fn deposit_event() = default; $($rest:tt)* ) => { $crate::decl_module!(@normalize @@ -296,7 +296,7 @@ macro_rules! decl_module { pub struct $mod_type<$trait_instance: $trait_name$(, I: $instantiable $(= $module_default_instance)?)?> for enum $call_type where origin: $origin_type, system = $system { $( $other_where_bounds )* } - { $vis fn deposit_event $(<$dpeg $(, $dpeg_instance)?>)* () = default; } + { $vis fn deposit_event() = default; } { $( $on_initialize )* } { $( $on_finalize )* } { $( $offchain )* } @@ -317,23 +317,11 @@ macro_rules! decl_module { { $( $constants:tt )* } [ $( $dispatchables:tt )* ] $(#[doc = $doc_attr:tt])* - $vis:vis fn deposit_event $(<$dpeg:ident $(, $dpeg_instance:ident)?>)* ( - $($param_name:ident : $param:ty),* - ) { $( $impl:tt )* } + $vis:vis fn deposit_event $($rest:tt)* ) => { - $crate::decl_module!(@normalize - $(#[$attr])* - pub struct $mod_type<$trait_instance: $trait_name$(, I: $instantiable $(= $module_default_instance)?)?> - for enum $call_type where origin: $origin_type, system = $system - { $( $other_where_bounds )* } - { $vis fn deposit_event $(<$dpeg $(, $dpeg_instance)?>)* ($( $param_name: $param ),* ) { $( $impl )* } } - { $( $on_initialize )* } - { $( $on_finalize )* } - { $( $offchain )* } - { $( $constants )* } - [ $( $dispatchables )* ] - $($rest)* + compile_error!( + "`deposit_event` function is reserved and must follow the syntax: `$vis:vis fn deposit_event() = default;`" ); }; (@normalize @@ -685,25 +673,10 @@ macro_rules! decl_module { impl<$trait_instance: $trait_name$(, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?> where $( $other_where_bounds )* { - $vis fn deposit_event(event: Event$(<$event_trait_instance $(, $event_instance)?>)?) { - <$system::Module<$trait_instance>>::deposit_event( - <$trait_instance as $trait_name$(<$instance>)?>::Event::from(event).into() - ); - } - } - }; - - (@impl_deposit_event - $module:ident<$trait_instance:ident: $trait_name:ident$(, $instance:ident: $instantiable:path)?>; - $system:ident; - { $( $other_where_bounds:tt )* } - $vis:vis fn deposit_event($param:ident : $param_ty:ty) { $( $impl:tt )* } - ) => { - impl<$trait_instance: $trait_name$(, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?> - where $( $other_where_bounds )* - { - $vis fn deposit_event($param: $param_ty) { - $( $impl )* + $vis fn deposit_event( + event: impl Into<< $trait_instance as $trait_name $(<$instance>)? >::Event> + ) { + <$system::Module<$trait_instance>>::deposit_event(event.into()) } } }; diff --git a/substrate/srml/support/test/tests/instance.rs b/substrate/srml/support/test/tests/instance.rs index 440fb9e779..e9c660eea3 100644 --- a/substrate/srml/support/test/tests/instance.rs +++ b/substrate/srml/support/test/tests/instance.rs @@ -55,7 +55,7 @@ mod module1 { { fn offchain_worker() {} - fn deposit_event() = default; + fn deposit_event() = default; fn one(origin) { system::ensure_root(origin)?; @@ -132,7 +132,7 @@ mod module2 { pub struct Module, I: Instance=DefaultInstance> for enum Call where origin: ::Origin { - fn deposit_event() = default; + fn deposit_event() = default; } } diff --git a/substrate/srml/support/test/tests/reserved_keyword/on_initialize.stderr b/substrate/srml/support/test/tests/reserved_keyword/on_initialize.stderr index 04adefab3a..13c2ef8d2c 100644 --- a/substrate/srml/support/test/tests/reserved_keyword/on_initialize.stderr +++ b/substrate/srml/support/test/tests/reserved_keyword/on_initialize.stderr @@ -38,7 +38,7 @@ error: Invalid call fn name: `offchain_worker`, name is reserved and doesn't mat | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) -error: Invalid call fn name: `deposit_event`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. +error: `deposit_event` function is reserved and must follow the syntax: `$vis:vis fn deposit_event() = default;` --> $DIR/on_initialize.rs:30:1 | 30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event); diff --git a/substrate/srml/support/test/tests/system.rs b/substrate/srml/support/test/tests/system.rs index 6483161211..9ea0b2bc76 100644 --- a/substrate/srml/support/test/tests/system.rs +++ b/substrate/srml/support/test/tests/system.rs @@ -12,8 +12,11 @@ pub trait Trait: 'static + Eq + Clone { srml_support::decl_module! { pub struct Module for enum Call where origin: T::Origin { - pub fn deposit_event(_event: T::Event) { - } + } +} + +impl Module { + pub fn deposit_event(_event: impl Into) { } } @@ -49,4 +52,4 @@ pub fn ensure_root(o: OuterOrigin) -> Result<(), &'stati where OuterOrigin: Into, OuterOrigin>> { o.into().map(|_| ()).map_err(|_| "bad origin: expected to be a root origin") -} \ No newline at end of file +} diff --git a/substrate/srml/system/src/lib.rs b/substrate/srml/system/src/lib.rs index 54aa3b282a..91959f43e4 100644 --- a/substrate/srml/system/src/lib.rs +++ b/substrate/srml/system/src/lib.rs @@ -246,11 +246,6 @@ pub type KeyValue = (Vec, Vec); decl_module! { pub struct Module for enum Call where origin: T::Origin { - /// Deposits an event into this block's event record. - pub fn deposit_event(event: T::Event) { - Self::deposit_event_indexed(&[], event); - } - /// A big dispatch that will disallow any other transaction to be included. // TODO: this must be preferable available for testing really (not possible at the moment). #[weight = SimpleDispatchInfo::MaxOperational] @@ -545,6 +540,11 @@ pub fn ensure_none(o: OuterOrigin) -> Result<(), &'stati } impl Module { + /// Deposits an event into this block's event record. + pub fn deposit_event(event: impl Into) { + Self::deposit_event_indexed(&[], event.into()); + } + /// Deposits an event into this block's event record adding this event /// to the corresponding topic indexes. /// @@ -815,7 +815,7 @@ impl Module { Self::deposit_event(match r { Ok(_) => Event::ExtrinsicSuccess, Err(_) => Event::ExtrinsicFailed, - }.into()); + }); let next_extrinsic_index = Self::extrinsic_index().unwrap_or_default() + 1u32; diff --git a/substrate/srml/treasury/src/lib.rs b/substrate/srml/treasury/src/lib.rs index 1e709b74a6..ef2b9e69fe 100644 --- a/substrate/srml/treasury/src/lib.rs +++ b/substrate/srml/treasury/src/lib.rs @@ -139,7 +139,7 @@ decl_module! { /// Percentage of spare funds (if any) that are burnt per spend period. const Burn: Permill = T::Burn::get(); - fn deposit_event() = default; + fn deposit_event() = default; /// Put forward a suggestion for spending. A deposit proportional to the value /// is reserved and slashed if the proposal is rejected. It is returned once the /// proposal is awarded.