Make decl_module! implement OnFinalise (#947)

This commit is contained in:
Bastian Köcher
2018-10-23 09:58:15 +02:00
committed by GitHub
parent 52093c4b7a
commit 1ba73e0e88
19 changed files with 158 additions and 117 deletions
-4
View File
@@ -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<T: Trait> Module<T> {
}
}
// This trait expresses what should happen when the block is finalised.
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {}
#[cfg(test)]
mod tests {
use super::*;
+1 -6
View File
@@ -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<T: Trait> Module<T> {
}
}
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
fn on_finalise(_n: T::BlockNumber) {
}
}
pub struct ChainContext<T>(::rstd::marker::PhantomData<T>);
impl<T> Default for ChainContext<T> {
fn default() -> Self {
+9 -13
View File
@@ -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<u8>) -> Result;
fn set_code(new: Vec<u8>) -> Result;
fn set_storage(items: Vec<KeyValue>) -> Result;
fn on_finalise() {
if let Some(original_authorities) = <OriginalAuthorities<T>>::take() {
let current_authorities = AuthorityStorageVec::<T::SessionKey>::items();
if current_authorities != original_authorities {
Self::deposit_log(RawLog::AuthoritiesChange(current_authorities));
}
}
}
}
}
@@ -267,15 +275,3 @@ impl<T: Trait> ProvideInherent for Module<T> {
)
}
}
/// Finalization hook for the consensus module.
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
fn on_finalise(_n: T::BlockNumber) {
if let Some(original_authorities) = <OriginalAuthorities<T>>::take() {
let current_authorities = AuthorityStorageVec::<T::SessionKey>::items();
if current_authorities != original_authorities {
Self::deposit_log(RawLog::AuthoritiesChange(current_authorities));
}
}
}
}
+1 -2
View File
@@ -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};
+4 -8
View File
@@ -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<u8>,
data: Vec<u8>
) -> Result;
fn on_finalise() {
<GasSpent<T>>::kill();
}
}
}
@@ -326,10 +329,3 @@ impl<T: Trait> balances::OnFreeBalanceZero<T::AccountId> for Module<T> {
<StorageOf<T>>::remove_prefix(who.clone());
}
}
/// Finalization hook for the smart-contract module.
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
fn on_finalise(_n: T::BlockNumber) {
<GasSpent<T>>::kill();
}
}
+1 -6
View File
@@ -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<T: Trait> Module<T> {
}
}
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
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<OuterOrigin>(o: OuterOrigin, n: u32) -> result::Result<u32, &'static str>
+7 -10
View File
@@ -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<T::AccountId, T::AccountIndex>) -> Result;
fn set_presentation_duration(count: <T::BlockNumber as HasCompact>::Type) -> Result;
fn set_term_duration(count: <T::BlockNumber as HasCompact>::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<T: Trait> Module<T> {
}
}
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
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::*;
+7 -10
View File
@@ -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: <T::BlockNumber as HasCompact>::Type) -> Result;
fn set_voting_period(blocks: <T::BlockNumber as HasCompact>::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<T: Trait> Module<T> {
}
}
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
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::*;
+6 -9
View File
@@ -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<T::Proposal>, vote_threshold: VoteThreshold) -> Result;
fn cancel_referendum(ref_index: Compact<ReferendumIndex>) -> Result;
fn on_finalise(n: T::BlockNumber) {
if let Err(e) = Self::end_block(n) {
runtime_io::print(e);
}
}
}
}
@@ -308,14 +313,6 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
fn on_finalise(n: T::BlockNumber) {
if let Err(e) = Self::end_block(n) {
runtime_io::print(e);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
+10 -11
View File
@@ -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.
<Dummy<T>>::kill();
}
}
}
@@ -266,15 +272,6 @@ impl<T: Trait> Module<T> {
}
}
// This trait expresses what should happen when the block is finalised.
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
fn on_finalise(_: T::BlockNumber) {
// Anything that needs to be done at the end of the block.
// We just kill our dummy storage item.
<Dummy<T>>::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 {}
+4 -7
View File
@@ -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: <T::BlockNumber as HasCompact>::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<T: Trait> Module<T> {
}
}
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
fn on_finalise(n: T::BlockNumber) {
Self::check_rotate_session(n);
}
}
#[cfg(test)]
mod tests {
use super::*;
+2 -7
View File
@@ -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<BlockNumber: Parameter> {
/// 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<Balance: HasCompact + Copy> { // TODO: @bkchr shouldn't need this Copy but derive(Encode) breaks otherwise
pub struct ValidatorPrefs<Balance: HasCompact + Copy> { // 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<T: Trait> Module<T> {
}
}
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
fn on_finalise(_n: T::BlockNumber) {
}
}
impl<T: Trait> OnSessionChange<T::Moment> for Module<T> {
fn on_session_change(elapsed: T::Moment, should_reward: bool) {
Self::new_session(elapsed, should_reward);
+71 -4
View File
@@ -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]
+10
View File
@@ -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 {
+6
View File
@@ -111,6 +111,7 @@ mod tests {
pub trait Trait {
type Origin: Into<Option<RawOrigin<Self::AccountId>>> + From<RawOrigin<Self::AccountId>>;
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!(
@@ -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;
}
}
+4 -7
View File
@@ -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<T: Trait> for enum Call where origin: T::Origin {
fn set(origin, now: <T::Moment as HasCompact>::Type) -> Result;
fn on_finalise() {
assert!(<Self as Store>::DidUpdate::take(), "Timestamp must be updated once in the block");
}
}
}
@@ -171,12 +174,6 @@ impl<T: Trait> ProvideInherent for Module<T> {
}
}
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
fn on_finalise(_n: T::BlockNumber) {
assert!(<Self as Store>::DidUpdate::take(), "Timestamp must be updated once in the block");
}
}
#[cfg(test)]
mod tests {
use super::*;
+9 -11
View File
@@ -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<ProposalIndex>) -> 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<T: Trait> OnDilution<T::Balance> for Module<T> {
}
}
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
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! {