mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 05:45:41 +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"),
|
impl_name: create_runtime_str!("substrate-node"),
|
||||||
authoring_version: 10,
|
authoring_version: 10,
|
||||||
spec_version: 90,
|
spec_version: 90,
|
||||||
impl_version: 90,
|
impl_version: 91,
|
||||||
apis: RUNTIME_API_VERSIONS,
|
apis: RUNTIME_API_VERSIONS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ use crate::runtime_primitives::traits::{
|
|||||||
MaybeSerializeDebug, SimpleArithmetic
|
MaybeSerializeDebug, SimpleArithmetic
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::for_each_tuple;
|
||||||
|
|
||||||
/// New trait for querying a single fixed value from a type.
|
/// New trait for querying a single fixed value from a type.
|
||||||
pub trait Get<T> {
|
pub trait Get<T> {
|
||||||
/// Return a constant value.
|
/// Return a constant value.
|
||||||
@@ -36,20 +38,24 @@ pub trait OnFreeBalanceZero<AccountId> {
|
|||||||
fn on_free_balance_zero(who: &AccountId);
|
fn on_free_balance_zero(who: &AccountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<AccountId> OnFreeBalanceZero<AccountId> for () {
|
macro_rules! impl_on_free_balance_zero {
|
||||||
fn on_free_balance_zero(_who: &AccountId) {}
|
() => (
|
||||||
}
|
impl<AccountId> OnFreeBalanceZero<AccountId> for () {
|
||||||
impl<
|
fn on_free_balance_zero(_: &AccountId) {}
|
||||||
AccountId,
|
}
|
||||||
X: OnFreeBalanceZero<AccountId>,
|
);
|
||||||
Y: OnFreeBalanceZero<AccountId>,
|
|
||||||
> OnFreeBalanceZero<AccountId> for (X, Y) {
|
( $($t:ident)* ) => {
|
||||||
fn on_free_balance_zero(who: &AccountId) {
|
impl<AccountId, $($t: OnFreeBalanceZero<AccountId>),*> OnFreeBalanceZero<AccountId> for ($($t,)*) {
|
||||||
X::on_free_balance_zero(who);
|
fn on_free_balance_zero(who: &AccountId) {
|
||||||
Y::on_free_balance_zero(who);
|
$($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.
|
/// Trait for a hook to get called when some balance has been minted, causing dilution.
|
||||||
pub trait OnDilution<Balance> {
|
pub trait OnDilution<Balance> {
|
||||||
/// Some `portion` of the total balance just "grew" by `minted`. `portion` is the pre-growth
|
/// 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 substrate_primitives::storage::well_known_keys;
|
||||||
use srml_support::{
|
use srml_support::{
|
||||||
storage, decl_module, decl_event, decl_storage, StorageDoubleMap, StorageValue,
|
storage, decl_module, decl_event, decl_storage, StorageDoubleMap, StorageValue,
|
||||||
StorageMap, Parameter,
|
StorageMap, Parameter, for_each_tuple,
|
||||||
};
|
};
|
||||||
use safe_mix::TripletMix;
|
use safe_mix::TripletMix;
|
||||||
use parity_codec::{Encode, Decode};
|
use parity_codec::{Encode, Decode};
|
||||||
@@ -102,10 +102,24 @@ pub trait OnNewAccount<AccountId> {
|
|||||||
fn on_new_account(who: &AccountId);
|
fn on_new_account(who: &AccountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<AccountId> OnNewAccount<AccountId> for () {
|
macro_rules! impl_on_new_account {
|
||||||
fn on_new_account(_who: &AccountId) {}
|
() => (
|
||||||
|
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.
|
/// Determiner to say whether a given account is unused.
|
||||||
pub trait IsDeadAccount<AccountId> {
|
pub trait IsDeadAccount<AccountId> {
|
||||||
/// Is the given account dead?
|
/// Is the given account dead?
|
||||||
|
|||||||
Reference in New Issue
Block a user