mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-11-17 16:16:09 +00:00
fungible::Unbalanced::decrease_balance: Handle precision properly (#2823)
This commit is contained in:
1 parent
19de1c9660
commit
1c95310a66
3 files changed
+46
-3
No files matched your search
@@ -181,9 +181,16 @@ pub trait Unbalanced<AccountId>: Inspect<AccountId> {
|
||||
) -> Result<Self::Balance, DispatchError> {
|
||||
let old_balance = Self::balance(who);
|
||||
let free = Self::reducible_balance(who, preservation, force);
|
||||
if let BestEffort = precision {
|
||||
amount = amount.min(free);
|
||||
match precision {
|
||||
BestEffort => {
|
||||
amount = amount.min(free);
|
||||
},
|
||||
Exact =>
|
||||
if free < amount {
|
||||
return Err(TokenError::FundsUnavailable.into())
|
||||
},
|
||||
}
|
||||
|
||||
let new_balance = old_balance.checked_sub(&amount).ok_or(TokenError::FundsUnavailable)?;
|
||||
if let Some(dust) = Self::write_balance(who, new_balance)? {
|
||||
Self::handle_dust(Dust(dust));
|
||||
|
||||
Reference in new issue
Block a user