Do nothing for zero imbalances (#4089)

This commit is contained in:
Gavin Wood
2019-11-12 09:42:32 +01:00
committed by GitHub
parent bff16d906d
commit c91d42712a
5 changed files with 61 additions and 14 deletions
+26 -3
View File
@@ -155,7 +155,8 @@ use codec::{Decode, Encode, HasCompact, Input, Output, Error};
use sr_primitives::RuntimeDebug;
use sr_primitives::traits::{
CheckedAdd, CheckedSub, MaybeSerializeDeserialize, Member, One, Saturating, SimpleArithmetic, Zero, Bounded
CheckedAdd, CheckedSub, MaybeSerializeDeserialize, Member, One, Saturating, SimpleArithmetic,
Zero, Bounded,
};
use rstd::prelude::*;
@@ -165,7 +166,7 @@ use support::{
decl_event, decl_module, decl_storage, ensure,
traits::{
Currency, ExistenceRequirement, Imbalance, LockIdentifier, LockableCurrency, ReservableCurrency,
SignedImbalance, UpdateBalanceOutcome, WithdrawReason, WithdrawReasons,
SignedImbalance, UpdateBalanceOutcome, WithdrawReason, WithdrawReasons, TryDrop,
},
Parameter, StorageMap,
};
@@ -862,7 +863,9 @@ pub trait AssetIdProvider {
// wrapping these imbalanes in a private module is necessary to ensure absolute privacy
// of the inner member.
mod imbalances {
use super::{result, AssetIdProvider, Imbalance, Saturating, StorageMap, Subtrait, Zero};
use super::{
result, AssetIdProvider, Imbalance, Saturating, StorageMap, Subtrait, Zero, TryDrop
};
use rstd::mem;
/// Opaque, move-only struct with private fields that serves as a token denoting that
@@ -899,6 +902,16 @@ mod imbalances {
}
}
impl<T, U> TryDrop for PositiveImbalance<T, U>
where
T: Subtrait,
U: AssetIdProvider<AssetId = T::AssetId>,
{
fn try_drop(self) -> result::Result<(), Self> {
self.drop_zero()
}
}
impl<T, U> Imbalance<T::Balance> for PositiveImbalance<T, U>
where
T: Subtrait,
@@ -948,6 +961,16 @@ mod imbalances {
}
}
impl<T, U> TryDrop for NegativeImbalance<T, U>
where
T: Subtrait,
U: AssetIdProvider<AssetId = T::AssetId>,
{
fn try_drop(self) -> result::Result<(), Self> {
self.drop_zero()
}
}
impl<T, U> Imbalance<T::Balance> for NegativeImbalance<T, U>
where
T: Subtrait,