mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 22:37:57 +00:00
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:
committed by
Bastian Köcher
parent
4213fe15cf
commit
6ce7c1c8c8
@@ -59,7 +59,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_name: create_runtime_str!("substrate-node"),
|
||||
authoring_version: 10,
|
||||
spec_version: 90,
|
||||
impl_version: 90,
|
||||
impl_version: 91,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ use crate::runtime_primitives::traits::{
|
||||
MaybeSerializeDebug, SimpleArithmetic
|
||||
};
|
||||
|
||||
use super::for_each_tuple;
|
||||
|
||||
/// New trait for querying a single fixed value from a type.
|
||||
pub trait Get<T> {
|
||||
/// Return a constant value.
|
||||
@@ -36,20 +38,24 @@ pub trait OnFreeBalanceZero<AccountId> {
|
||||
fn on_free_balance_zero(who: &AccountId);
|
||||
}
|
||||
|
||||
impl<AccountId> OnFreeBalanceZero<AccountId> for () {
|
||||
fn on_free_balance_zero(_who: &AccountId) {}
|
||||
}
|
||||
impl<
|
||||
AccountId,
|
||||
X: OnFreeBalanceZero<AccountId>,
|
||||
Y: OnFreeBalanceZero<AccountId>,
|
||||
> OnFreeBalanceZero<AccountId> for (X, Y) {
|
||||
fn on_free_balance_zero(who: &AccountId) {
|
||||
X::on_free_balance_zero(who);
|
||||
Y::on_free_balance_zero(who);
|
||||
macro_rules! impl_on_free_balance_zero {
|
||||
() => (
|
||||
impl<AccountId> OnFreeBalanceZero<AccountId> for () {
|
||||
fn on_free_balance_zero(_: &AccountId) {}
|
||||
}
|
||||
);
|
||||
|
||||
( $($t:ident)* ) => {
|
||||
impl<AccountId, $($t: OnFreeBalanceZero<AccountId>),*> OnFreeBalanceZero<AccountId> for ($($t,)*) {
|
||||
fn on_free_balance_zero(who: &AccountId) {
|
||||
$($t::on_free_balance_zero(who);)*
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for_each_tuple!(impl_on_free_balance_zero);
|
||||
|
||||
/// Trait for a hook to get called when some balance has been minted, causing dilution.
|
||||
pub trait OnDilution<Balance> {
|
||||
/// Some `portion` of the total balance just "grew" by `minted`. `portion` is the pre-growth
|
||||
|
||||
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user