diff --git a/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm b/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm index 392b360796..c50aa4a3eb 100644 Binary files a/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm and b/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm differ diff --git a/substrate/srml/assets/src/lib.rs b/substrate/srml/assets/src/lib.rs index 61b36dc3c1..d92bf44495 100644 --- a/substrate/srml/assets/src/lib.rs +++ b/substrate/srml/assets/src/lib.rs @@ -52,7 +52,6 @@ extern crate sr_primitives as primitives; // depend on it being around. extern crate srml_system as system; -use primitives::traits::OnFinalise; use runtime_support::{StorageValue, StorageMap, dispatch::Result, Parameter}; use primitives::traits::{Member, SimpleArithmetic, Zero}; use system::ensure_signed; @@ -161,9 +160,6 @@ impl Module { } } -// This trait expresses what should happen when the block is finalised. -impl OnFinalise for Module {} - #[cfg(test)] mod tests { use super::*; diff --git a/substrate/srml/balances/src/lib.rs b/substrate/srml/balances/src/lib.rs index 50c9b27d76..f06990626e 100644 --- a/substrate/srml/balances/src/lib.rs +++ b/substrate/srml/balances/src/lib.rs @@ -44,7 +44,7 @@ use rstd::{cmp, result}; use codec::{Encode, Decode, Codec, Input, Output, HasCompact}; use runtime_support::{StorageValue, StorageMap, Parameter}; use runtime_support::dispatch::Result; -use primitives::traits::{Zero, One, SimpleArithmetic, OnFinalise, MakePayment, +use primitives::traits::{Zero, One, SimpleArithmetic, MakePayment, As, Lookup, Member, CheckedAdd, CheckedSub, CurrentHeight, BlockNumberToHash}; use address::Address as RawAddress; use system::ensure_signed; @@ -652,11 +652,6 @@ impl Module { } } -impl OnFinalise for Module { - fn on_finalise(_n: T::BlockNumber) { - } -} - pub struct ChainContext(::rstd::marker::PhantomData); impl Default for ChainContext { fn default() -> Self { diff --git a/substrate/srml/consensus/src/lib.rs b/substrate/srml/consensus/src/lib.rs index 835d39a44c..ba72df18f5 100644 --- a/substrate/srml/consensus/src/lib.rs +++ b/substrate/srml/consensus/src/lib.rs @@ -48,7 +48,7 @@ use runtime_support::storage::StorageValue; use runtime_support::storage::unhashed::StorageVec; use primitives::RuntimeString; use primitives::traits::{ - MaybeSerializeDebug, OnFinalise, Member, ProvideInherent, Block as BlockT + MaybeSerializeDebug, Member, ProvideInherent, Block as BlockT }; use substrate_primitives::storage::well_known_keys; use system::{ensure_signed, ensure_inherent}; @@ -148,6 +148,14 @@ decl_module! { fn remark(origin, remark: Vec) -> Result; fn set_code(new: Vec) -> Result; fn set_storage(items: Vec) -> Result; + fn on_finalise() { + if let Some(original_authorities) = >::take() { + let current_authorities = AuthorityStorageVec::::items(); + if current_authorities != original_authorities { + Self::deposit_log(RawLog::AuthoritiesChange(current_authorities)); + } + } + } } } @@ -267,15 +275,3 @@ impl ProvideInherent for Module { ) } } - -/// Finalization hook for the consensus module. -impl OnFinalise for Module { - fn on_finalise(_n: T::BlockNumber) { - if let Some(original_authorities) = >::take() { - let current_authorities = AuthorityStorageVec::::items(); - if current_authorities != original_authorities { - Self::deposit_log(RawLog::AuthoritiesChange(current_authorities)); - } - } - } -} diff --git a/substrate/srml/consensus/src/tests.rs b/substrate/srml/consensus/src/tests.rs index e27f617115..b823367c15 100644 --- a/substrate/srml/consensus/src/tests.rs +++ b/substrate/srml/consensus/src/tests.rs @@ -18,8 +18,7 @@ #![cfg(test)] -use super::*; -use primitives::{generic, testing}; +use primitives::{generic, testing, traits::OnFinalise}; use runtime_io::with_externalities; use substrate_primitives::H256; use mock::{Consensus, System, new_test_ext}; diff --git a/substrate/srml/contract/src/lib.rs b/substrate/srml/contract/src/lib.rs index 31a7d4ed22..d57a65bc1f 100644 --- a/substrate/srml/contract/src/lib.rs +++ b/substrate/srml/contract/src/lib.rs @@ -103,7 +103,7 @@ use double_map::StorageDoubleMap; use rstd::prelude::*; use rstd::marker::PhantomData; use codec::{Codec, HasCompact}; -use runtime_primitives::traits::{Hash, As, SimpleArithmetic, OnFinalise}; +use runtime_primitives::traits::{Hash, As, SimpleArithmetic}; use runtime_support::dispatch::Result; use runtime_support::{Parameter, StorageMap, StorageValue}; use system::ensure_signed; @@ -167,6 +167,9 @@ decl_module! { init_code: Vec, data: Vec ) -> Result; + fn on_finalise() { + >::kill(); + } } } @@ -326,10 +329,3 @@ impl balances::OnFreeBalanceZero for Module { >::remove_prefix(who.clone()); } } - -/// Finalization hook for the smart-contract module. -impl OnFinalise for Module { - fn on_finalise(_n: T::BlockNumber) { - >::kill(); - } -} diff --git a/substrate/srml/council/src/motions.rs b/substrate/srml/council/src/motions.rs index ab6ea5f4ef..a260eec60e 100644 --- a/substrate/srml/council/src/motions.rs +++ b/substrate/srml/council/src/motions.rs @@ -20,7 +20,7 @@ use rstd::prelude::*; use rstd::result; use codec::Compact; use substrate_primitives::u32_trait::Value as U32; -use primitives::traits::{Hash, EnsureOrigin, MaybeSerializeDebug, OnFinalise}; +use primitives::traits::{Hash, EnsureOrigin, MaybeSerializeDebug}; use srml_support::dispatch::{Result, Dispatchable, Parameter}; use srml_support::{StorageValue, StorageMap}; use super::{Trait as CouncilTrait, Module as Council}; @@ -194,11 +194,6 @@ impl Module { } } -impl OnFinalise for Module { - fn on_finalise(_n: T::BlockNumber) { - } -} - /// Ensure that the origin `o` represents at least `n` council members. Returns /// `Ok` or an `Err` otherwise. pub fn ensure_council_members(o: OuterOrigin, n: u32) -> result::Result diff --git a/substrate/srml/council/src/seats.rs b/substrate/srml/council/src/seats.rs index 42c3858efb..24d06ecf6a 100644 --- a/substrate/srml/council/src/seats.rs +++ b/substrate/srml/council/src/seats.rs @@ -18,7 +18,7 @@ use rstd::prelude::*; use codec::{Compact, HasCompact}; -use primitives::traits::{Zero, One, As, OnFinalise}; +use primitives::traits::{Zero, One, As}; use runtime_io::print; use srml_support::{StorageValue, StorageMap, dispatch::Result}; use democracy; @@ -97,6 +97,12 @@ decl_module! { fn remove_member(who: Address) -> Result; fn set_presentation_duration(count: ::Type) -> Result; fn set_term_duration(count: ::Type) -> Result; + fn on_finalise(n: T::BlockNumber) { + if let Err(e) = Self::end_block(n) { + print("Guru meditation"); + print(e); + } + } } } @@ -560,15 +566,6 @@ impl Module { } } -impl OnFinalise for Module { - fn on_finalise(n: T::BlockNumber) { - if let Err(e) = Self::end_block(n) { - print("Guru meditation"); - print(e); - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/substrate/srml/council/src/voting.rs b/substrate/srml/council/src/voting.rs index 094066327c..86c2c40c2a 100644 --- a/substrate/srml/council/src/voting.rs +++ b/substrate/srml/council/src/voting.rs @@ -19,7 +19,7 @@ use rstd::prelude::*; use rstd::borrow::Borrow; use codec::HasCompact; -use primitives::traits::{OnFinalise, Hash, As}; +use primitives::traits::{Hash, As}; use runtime_io::print; use srml_support::dispatch::Result; use srml_support::{StorageValue, StorageMap, IsSubType}; @@ -39,6 +39,12 @@ decl_module! { fn set_cooloff_period(blocks: ::Type) -> Result; fn set_voting_period(blocks: ::Type) -> Result; + fn on_finalise(n: T::BlockNumber) { + if let Err(e) = Self::end_block(n) { + print("Guru meditation"); + print(e); + } + } } } @@ -227,15 +233,6 @@ impl Module { } } -impl OnFinalise for Module { - fn on_finalise(n: T::BlockNumber) { - if let Err(e) = Self::end_block(n) { - print("Guru meditation"); - print(e); - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/substrate/srml/democracy/src/lib.rs b/substrate/srml/democracy/src/lib.rs index f5c3153251..0d54dbf441 100644 --- a/substrate/srml/democracy/src/lib.rs +++ b/substrate/srml/democracy/src/lib.rs @@ -41,7 +41,7 @@ extern crate srml_system as system; use rstd::prelude::*; use rstd::result; use codec::{HasCompact, Compact}; -use primitives::traits::{Zero, OnFinalise, As, MaybeSerializeDebug}; +use primitives::traits::{Zero, As, MaybeSerializeDebug}; use srml_support::{StorageValue, StorageMap, Parameter, Dispatchable, IsSubType}; use srml_support::dispatch::Result; use system::ensure_signed; @@ -68,6 +68,11 @@ decl_module! { fn start_referendum(proposal: Box, vote_threshold: VoteThreshold) -> Result; fn cancel_referendum(ref_index: Compact) -> Result; + fn on_finalise(n: T::BlockNumber) { + if let Err(e) = Self::end_block(n) { + runtime_io::print(e); + } + } } } @@ -308,14 +313,6 @@ impl Module { } } -impl OnFinalise for Module { - fn on_finalise(n: T::BlockNumber) { - if let Err(e) = Self::end_block(n) { - runtime_io::print(e); - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/substrate/srml/example/src/lib.rs b/substrate/srml/example/src/lib.rs index f60168d37b..587c4af258 100644 --- a/substrate/srml/example/src/lib.rs +++ b/substrate/srml/example/src/lib.rs @@ -57,7 +57,6 @@ extern crate srml_system as system; // might find it useful). extern crate srml_balances as balances; -use sr_primitives::traits::OnFinalise; use support::{StorageValue, dispatch::Result}; use system::ensure_signed; @@ -111,6 +110,13 @@ decl_module! { /// A privileged call; in this case it resets our dummy value to something new. fn set_dummy(new_dummy: T::Balance) -> Result; + + // The signature could also look like: `fn on_finalise()` + fn on_finalise(_n: T::BlockNumber) { + // Anything that needs to be done at the end of the block. + // We just kill our dummy storage item. + >::kill(); + } } } @@ -266,15 +272,6 @@ impl Module { } } -// This trait expresses what should happen when the block is finalised. -impl OnFinalise for Module { - fn on_finalise(_: T::BlockNumber) { - // Anything that needs to be done at the end of the block. - // We just kill our dummy storage item. - >::kill(); - } -} - #[cfg(test)] mod tests { use super::*; @@ -283,7 +280,9 @@ mod tests { use substrate_primitives::{H256, Blake2Hasher}; // The testing primitives are very useful for avoiding having to work with signatures // or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried. - use sr_primitives::{BuildStorage, traits::{BlakeTwo256}, testing::{Digest, DigestItem, Header}}; + use sr_primitives::{ + BuildStorage, traits::{BlakeTwo256, OnFinalise}, testing::{Digest, DigestItem, Header} + }; impl_outer_origin! { pub enum Origin for Test {} diff --git a/substrate/srml/session/src/lib.rs b/substrate/srml/session/src/lib.rs index 087e37ecfe..44d8922723 100644 --- a/substrate/srml/session/src/lib.rs +++ b/substrate/srml/session/src/lib.rs @@ -42,7 +42,7 @@ extern crate srml_system as system; extern crate srml_timestamp as timestamp; use rstd::prelude::*; -use primitives::traits::{As, Zero, One, OnFinalise, Convert}; +use primitives::traits::{As, Zero, One, Convert}; use codec::HasCompact; use runtime_support::{StorageValue, StorageMap}; use runtime_support::dispatch::Result; @@ -71,6 +71,9 @@ decl_module! { fn set_length(new: ::Type) -> Result; fn force_new_session(apply_rewards: bool) -> Result; + fn on_finalise(n: T::BlockNumber) { + Self::check_rotate_session(n); + } } } @@ -228,12 +231,6 @@ impl Module { } } -impl OnFinalise for Module { - fn on_finalise(n: T::BlockNumber) { - Self::check_rotate_session(n); - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/substrate/srml/staking/src/lib.rs b/substrate/srml/staking/src/lib.rs index 6b47e01c33..370c17ddb5 100644 --- a/substrate/srml/staking/src/lib.rs +++ b/substrate/srml/staking/src/lib.rs @@ -55,7 +55,7 @@ use codec::{HasCompact, Compact}; use runtime_support::{Parameter, StorageValue, StorageMap}; use runtime_support::dispatch::Result; use session::OnSessionChange; -use primitives::{Perbill, traits::{Zero, One, Bounded, OnFinalise, As}}; +use primitives::{Perbill, traits::{Zero, One, Bounded, As}}; use balances::{address::Address, OnDilution}; use system::ensure_signed; @@ -76,7 +76,7 @@ pub enum LockStatus { /// Preference of what happens on a slash event. #[derive(PartialEq, Eq, Clone, Encode, Decode)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] -pub struct ValidatorPrefs { // TODO: @bkchr shouldn't need this Copy but derive(Encode) breaks otherwise +pub struct ValidatorPrefs { // TODO: @bkchr shouldn't need this Copy but derive(Encode) breaks otherwise /// Validator should ensure this many more slashes than is necessary before being unstaked. #[codec(compact)] pub unstake_threshold: u32, @@ -525,11 +525,6 @@ impl Module { } } -impl OnFinalise for Module { - fn on_finalise(_n: T::BlockNumber) { - } -} - impl OnSessionChange for Module { fn on_session_change(elapsed: T::Moment, should_reward: bool) { Self::new_session(elapsed, should_reward); diff --git a/substrate/srml/support/src/dispatch.rs b/substrate/srml/support/src/dispatch.rs index a413f06b0f..8bdfcc88b9 100644 --- a/substrate/srml/support/src/dispatch.rs +++ b/substrate/srml/support/src/dispatch.rs @@ -76,6 +76,7 @@ macro_rules! decl_module { $(#[$attr])* pub struct $mod_type<$trait_instance: $trait_name> for enum $call_type where origin: $origin_type where system = system + {} [] $($t)* ); @@ -91,6 +92,7 @@ macro_rules! decl_module { $(#[$attr])* pub struct $mod_type<$trait_instance: $trait_name> for enum $call_type where origin: $origin_type where system = $system + {} [] $($t)* ); @@ -100,6 +102,26 @@ macro_rules! decl_module { $(#[$attr:meta])* pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> for enum $call_type:ident where origin: $origin_type:ty where system = $system:ident + { $( $on_finalise:tt )* } + [ $($t:tt)* ] + $(#[doc = $doc_attr:tt])* + fn on_finalise($($param_name:ident : $param:ty),* ) { $( $impl:tt )* } + $($rest:tt)* + ) => { + decl_module!(@normalize + $(#[$attr])* + pub struct $mod_type<$trait_instance: $trait_name> + for enum $call_type where origin: $origin_type where system = $system + { fn on_finalise( $( $param_name : $param ),* ) { $( $impl )* } } + [ $($t)* ] + $($rest)* + ); + }; + (@normalize + $(#[$attr:meta])* + pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> + for enum $call_type:ident where origin: $origin_type:ty where system = $system:ident + { $( $on_finalise:tt )* } [ $($t:tt)* ] $(#[doc = $doc_attr:tt])* fn $fn_name:ident(origin $(, $param_name:ident : $param:ty)* ) -> $result:ty ; @@ -109,6 +131,7 @@ macro_rules! decl_module { $(#[$attr])* pub struct $mod_type<$trait_instance: $trait_name> for enum $call_type where origin: $origin_type where system = $system + { $( $on_finalise )* } [ $($t)* $(#[doc = $doc_attr])* fn $fn_name(origin $( , $param_name : $param )* ) -> $result; ] $($rest)* ); @@ -117,6 +140,7 @@ macro_rules! decl_module { $(#[$attr:meta])* pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> for enum $call_type:ident where origin: $origin_type:ty where system = $system:ident + { $( $on_finalise:tt )* } [ $($t:tt)* ] $(#[doc = $doc_attr:tt])* fn $fn_name:ident($( $param_name:ident : $param:ty),* ) -> $result:ty ; @@ -126,6 +150,7 @@ macro_rules! decl_module { $(#[$attr])* pub struct $mod_type<$trait_instance: $trait_name> for enum $call_type where origin: $origin_type where system = $system + { $( $on_finalise )* } [ $($t)* $(#[doc = $doc_attr])* fn $fn_name(root $( , $param_name : $param )* ) -> $result; ] $($rest)* ); @@ -134,6 +159,7 @@ macro_rules! decl_module { $(#[$attr:meta])* pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> for enum $call_type:ident where origin: $origin_type:ty where system = $system:ident + { $( $on_finalise:tt )* } [ $($t:tt)* ] ) => { decl_module!(@imp @@ -142,6 +168,7 @@ macro_rules! decl_module { for enum $call_type where origin: $origin_type where system = $system { $($t)* } + { $( $on_finalise )* } ); }; @@ -161,14 +188,46 @@ macro_rules! decl_module { } }; + (@impl_on_finalise + $module:ident<$trait_instance:ident: $trait_name:ident>; + fn on_finalise() { $( $impl:tt )* } + ) => { + impl<$trait_instance: $trait_name> + $crate::runtime_primitives::traits::OnFinalise<$trait_instance::BlockNumber> + for $module<$trait_instance> { + fn on_finalise(_block_number_not_used: $trait_instance::BlockNumber) { $( $impl )* } + } + }; + + (@impl_on_finalise + $module:ident<$trait_instance:ident: $trait_name:ident>; + fn on_finalise($param:ident : $param_ty:ty) { $( $impl:tt )* } + ) => { + impl<$trait_instance: $trait_name> + $crate::runtime_primitives::traits::OnFinalise<$trait_instance::BlockNumber> + for $module<$trait_instance> { + fn on_finalise($param: $param_ty) { $( $impl )* } + } + }; + + (@impl_on_finalise + $module:ident<$trait_instance:ident: $trait_name:ident>; + ) => { + impl<$trait_instance: $trait_name> + $crate::runtime_primitives::traits::OnFinalise<$trait_instance::BlockNumber> + for $module<$trait_instance> {} + }; + (@imp $(#[$attr:meta])* pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> for enum $call_type:ident where origin: $origin_type:ty where system = $system:ident { - $( - $(#[doc = $doc_attr:tt])* - fn $fn_name:ident($from:ident $( , $param_name:ident : $param:ty)*) -> $result:ty; - )*} + $( + $(#[doc = $doc_attr:tt])* + fn $fn_name:ident($from:ident $( , $param_name:ident : $param:ty)*) -> $result:ty; + )* + } + { $( $on_finalise:tt )* } ) => { // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. #[derive(Clone, Copy, PartialEq, Eq)] @@ -185,6 +244,12 @@ macro_rules! decl_module { #[cfg(not(feature = "std"))] pub struct $mod_type<$trait_instance: $trait_name>(::core::marker::PhantomData<$trait_instance>); + decl_module! { + @impl_on_finalise + $mod_type<$trait_instance: $trait_name>; + $( $on_finalise )* + } + #[cfg(feature = "std")] $(#[$attr])* #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] @@ -615,6 +680,7 @@ mod tests { pub trait Trait { type Origin; + type BlockNumber; } pub mod system { @@ -722,6 +788,7 @@ mod tests { impl Trait for TraitImpl { type Origin = u32; + type BlockNumber = u32; } #[test] diff --git a/substrate/srml/support/src/event.rs b/substrate/srml/support/src/event.rs index 8a6c153029..ae7ddea412 100644 --- a/substrate/srml/support/src/event.rs +++ b/substrate/srml/support/src/event.rs @@ -433,6 +433,7 @@ mod tests { mod system { pub trait Trait { type Origin; + type BlockNumber; } decl_module! { @@ -449,6 +450,7 @@ mod tests { mod system_renamed { pub trait Trait { type Origin; + type BlockNumber; } decl_module! { @@ -466,6 +468,7 @@ mod tests { pub trait Trait { type Origin; type Balance; + type BlockNumber; } decl_module! { @@ -488,6 +491,7 @@ mod tests { pub trait Trait { type Origin; type Balance; + type BlockNumber; } decl_module! { @@ -539,29 +543,35 @@ mod tests { impl event_module::Trait for TestRuntime { type Origin = u32; type Balance = u32; + type BlockNumber = u32; } impl event_module2::Trait for TestRuntime { type Origin = u32; type Balance = u32; + type BlockNumber = u32; } impl system::Trait for TestRuntime { type Origin = u32; + type BlockNumber = u32; } impl event_module::Trait for TestRuntime2 { type Origin = u32; type Balance = u32; + type BlockNumber = u32; } impl event_module2::Trait for TestRuntime2 { type Origin = u32; type Balance = u32; + type BlockNumber = u32; } impl system_renamed::Trait for TestRuntime2 { type Origin = u32; + type BlockNumber = u32; } const EXPECTED_METADATA: OuterEventMetadata = OuterEventMetadata { diff --git a/substrate/srml/support/src/metadata.rs b/substrate/srml/support/src/metadata.rs index a3095851a6..79df4815bb 100644 --- a/substrate/srml/support/src/metadata.rs +++ b/substrate/srml/support/src/metadata.rs @@ -111,6 +111,7 @@ mod tests { pub trait Trait { type Origin: Into>> + From>; type AccountId; + type BlockNumber; } decl_module! { @@ -148,6 +149,7 @@ mod tests { pub trait Trait { type Origin; type Balance; + type BlockNumber; } decl_event!( @@ -175,6 +177,7 @@ mod tests { pub trait Trait { type Origin; type Balance; + type BlockNumber; } decl_event!( @@ -226,16 +229,19 @@ mod tests { impl event_module::Trait for TestRuntime { type Origin = Origin; type Balance = u32; + type BlockNumber = u32; } impl event_module2::Trait for TestRuntime { type Origin = Origin; type Balance = u32; + type BlockNumber = u32; } impl system::Trait for TestRuntime { type Origin = Origin; type AccountId = u32; + type BlockNumber = u32; } impl_runtime_metadata!( diff --git a/substrate/srml/support/src/storage/generator.rs b/substrate/srml/support/src/storage/generator.rs index 8398819ebe..5b01a686c6 100644 --- a/substrate/srml/support/src/storage/generator.rs +++ b/substrate/srml/support/src/storage/generator.rs @@ -2702,7 +2702,8 @@ mod tests { } pub trait Trait { - type Origin: codec::Encode + codec::Decode + ::std::default::Default; + type Origin: codec::Encode + codec::Decode + ::std::default::Default; + type BlockNumber; } decl_module! { @@ -2754,6 +2755,7 @@ mod tests { impl Trait for TraitImpl { type Origin = u32; + type BlockNumber = u32; } const EXPECTED_METADATA: StorageMetadata = StorageMetadata { @@ -2932,7 +2934,8 @@ mod tests { #[allow(dead_code)] mod test2 { pub trait Trait { - type Origin; + type Origin; + type BlockNumber; } decl_module! { @@ -2959,5 +2962,6 @@ mod test2 { impl Trait for TraitImpl { type Origin = u32; + type BlockNumber = u32; } } diff --git a/substrate/srml/timestamp/src/lib.rs b/substrate/srml/timestamp/src/lib.rs index c13972c7da..6b42a8218a 100644 --- a/substrate/srml/timestamp/src/lib.rs +++ b/substrate/srml/timestamp/src/lib.rs @@ -59,7 +59,7 @@ use runtime_support::{StorageValue, Parameter}; use runtime_support::dispatch::Result; use runtime_primitives::RuntimeString; use runtime_primitives::traits::{ - As, OnFinalise, SimpleArithmetic, Zero, ProvideInherent, Block as BlockT, Extrinsic + As, SimpleArithmetic, Zero, ProvideInherent, Block as BlockT, Extrinsic }; use system::ensure_inherent; use rstd::{result, ops::{Mul, Div}, vec::Vec}; @@ -75,6 +75,9 @@ pub trait Trait: consensus::Trait + system::Trait { decl_module! { pub struct Module for enum Call where origin: T::Origin { fn set(origin, now: ::Type) -> Result; + fn on_finalise() { + assert!(::DidUpdate::take(), "Timestamp must be updated once in the block"); + } } } @@ -171,12 +174,6 @@ impl ProvideInherent for Module { } } -impl OnFinalise for Module { - fn on_finalise(_n: T::BlockNumber) { - assert!(::DidUpdate::take(), "Timestamp must be updated once in the block"); - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/substrate/srml/treasury/src/lib.rs b/substrate/srml/treasury/src/lib.rs index febe5fed89..4c7c9c9107 100644 --- a/substrate/srml/treasury/src/lib.rs +++ b/substrate/srml/treasury/src/lib.rs @@ -45,7 +45,7 @@ extern crate srml_balances as balances; use rstd::prelude::*; use runtime_support::{StorageValue, StorageMap}; use runtime_support::dispatch::Result; -use runtime_primitives::{Permill, traits::{OnFinalise, Zero, EnsureOrigin}}; +use runtime_primitives::{Permill, traits::{Zero, EnsureOrigin}}; use codec::{HasCompact, Compact}; use balances::{OnDilution, address::Address}; use system::ensure_signed; @@ -90,6 +90,13 @@ decl_module! { // Approve a proposal. At a later time, the proposal will be allocated to the beneficiary // and the original deposit will be returned. fn approve_proposal(origin, proposal_id: Compact) -> Result; + + fn on_finalise(n: T::BlockNumber) { + // Check to see if we should spend some funds! + if (n % Self::spend_period()).is_zero() { + Self::spend_funds(); + } + } } } @@ -284,15 +291,6 @@ impl OnDilution for Module { } } -impl OnFinalise for Module { - fn on_finalise(n: T::BlockNumber) { - // Check to see if we should spend some funds! - if (n % Self::spend_period()).is_zero() { - Self::spend_funds(); - } - } -} - #[cfg(test)] mod tests { use super::*; @@ -300,7 +298,7 @@ mod tests { use runtime_io::with_externalities; use substrate_primitives::{H256, Blake2Hasher}; use runtime_primitives::BuildStorage; - use runtime_primitives::traits::{BlakeTwo256}; + use runtime_primitives::traits::{BlakeTwo256, OnFinalise}; use runtime_primitives::testing::{Digest, DigestItem, Header}; impl_outer_origin! {