Add support for tuples in OnNewAccount hook (#2765)

* Add support for tuples in `OnNewAccount` hook

* Bump impl version

* Use `for_each_tuple` with `OnNewAccount` hook

* Update `OnFreeBalanceZero` to also use `for_each_tuple`

* Fix spelling/typo

* Bump spec again

* Update srml/support/src/traits.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update srml/system/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Shawn Tabrizi
2019-06-04 08:48:22 +02:00
committed by Bastian Köcher
parent 4213fe15cf
commit 6ce7c1c8c8
3 changed files with 35 additions and 15 deletions
+17 -3
View File
@@ -85,7 +85,7 @@ use primitives::traits::Zero;
use substrate_primitives::storage::well_known_keys;
use srml_support::{
storage, decl_module, decl_event, decl_storage, StorageDoubleMap, StorageValue,
StorageMap, Parameter,
StorageMap, Parameter, for_each_tuple,
};
use safe_mix::TripletMix;
use parity_codec::{Encode, Decode};
@@ -102,10 +102,24 @@ pub trait OnNewAccount<AccountId> {
fn on_new_account(who: &AccountId);
}
impl<AccountId> OnNewAccount<AccountId> for () {
fn on_new_account(_who: &AccountId) {}
macro_rules! impl_on_new_account {
() => (
impl<AccountId> OnNewAccount<AccountId> for () {
fn on_new_account(_: &AccountId) {}
}
);
( $($t:ident)* ) => {
impl<AccountId, $($t: OnNewAccount<AccountId>),*> OnNewAccount<AccountId> for ($($t,)*) {
fn on_new_account(who: &AccountId) {
$($t::on_new_account(who);)*
}
}
}
}
for_each_tuple!(impl_on_new_account);
/// Determiner to say whether a given account is unused.
pub trait IsDeadAccount<AccountId> {
/// Is the given account dead?