decouple balances from some modules (#1641)

* decouple balances from some module by creating a new traits in support/traits
* improve decl_event
This commit is contained in:
thiolliere
2019-02-08 17:43:12 +01:00
committed by GitHub
parent 83f9e1e720
commit e5dbcf6890
19 changed files with 510 additions and 341 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ use {balances, system};
use rstd::cell::RefCell;
use rstd::collections::btree_map::{BTreeMap, Entry};
use rstd::prelude::*;
use runtime_support::{StorageMap, StorageDoubleMap};
use runtime_support::{StorageMap, StorageDoubleMap, traits::UpdateBalanceOutcome};
pub struct ChangeEntry<T: Trait> {
balance: Option<T::Balance>,
@@ -65,7 +65,7 @@ impl<T: Trait> AccountDb<T> for DirectAccountDb {
fn commit(&mut self, s: ChangeSet<T>) {
for (address, changed) in s.into_iter() {
if let Some(balance) = changed.balance {
if let balances::UpdateBalanceOutcome::AccountKilled =
if let UpdateBalanceOutcome::AccountKilled =
balances::Module::<T>::set_free_balance_creating(&address, balance)
{
// Account killed. This will ultimately lead to calling `OnFreeBalanceZero` callback
+1 -1
View File
@@ -18,10 +18,10 @@ use super::{CodeHash, Config, ContractAddressFor, Event, RawEvent, Trait};
use crate::account_db::{AccountDb, DirectAccountDb, OverlayAccountDb};
use crate::gas::{GasMeter, Token, approx_gas_for_balance};
use balances::{self, EnsureAccountLiquid};
use rstd::prelude::*;
use runtime_primitives::traits::{CheckedAdd, CheckedSub, Zero};
use timestamp;
use runtime_support::traits::EnsureAccountLiquid;
pub type BalanceOf<T> = <T as balances::Trait>::Balance;
pub type AccountIdOf<T> = <T as system::Trait>::AccountId;
+2 -1
View File
@@ -79,6 +79,7 @@ use codec::Codec;
use runtime_primitives::traits::{Hash, As, SimpleArithmetic,Bounded, StaticLookup};
use runtime_support::dispatch::{Result, Dispatchable};
use runtime_support::{Parameter, StorageMap, StorageValue, StorageDoubleMap};
use runtime_support::traits::OnFreeBalanceZero;
use system::{ensure_signed, RawOrigin};
use runtime_io::{blake2_256, twox_128};
use timestamp;
@@ -369,7 +370,7 @@ impl<T: Trait> StorageDoubleMap for StorageOf<T> {
}
}
impl<T: Trait> balances::OnFreeBalanceZero<T::AccountId> for Module<T> {
impl<T: Trait> OnFreeBalanceZero<T::AccountId> for Module<T> {
fn on_free_balance_zero(who: &T::AccountId) {
<CodeHashOf<T>>::remove(who);
<StorageOf<T>>::remove_prefix(who.clone());