mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
prevent trustlines being spent below spendable balance
This commit is contained in:
@@ -247,6 +247,29 @@ accountHolds(
|
||||
// Put balance in account terms.
|
||||
amount.negate();
|
||||
}
|
||||
|
||||
// If tokens can be escrowed then they can be locked in the trustline
|
||||
// which means we must never spend them until the escrow is released.
|
||||
if (view.rules().enabled(featurePaychanAndEscrowForTokens)
|
||||
&& sle->isFieldPresent(sfLockedBalance))
|
||||
{
|
||||
STAmount lockedBalance = sle->getFieldAmount(sfLockedBalance);
|
||||
STAmount spendableBalance = amount -
|
||||
(account > issuer ? -lockedBalance : lockedBalance);
|
||||
|
||||
// RH NOTE: this is defensively programmed, it should never fire
|
||||
// if something bad does happen the trustline acts as a frozen line.
|
||||
if (spendableBalance < beast::zero || spendableBalance > amount)
|
||||
{
|
||||
JLOG(j.error())
|
||||
<< "SpendableBalance has illegal value in accountHolds "
|
||||
<< spendableBalance;
|
||||
amount.clear(Issue{currency, issuer});
|
||||
}
|
||||
else
|
||||
amount = spendableBalance;
|
||||
}
|
||||
|
||||
amount.setIssuer(issuer);
|
||||
}
|
||||
JLOG(j.trace()) << "accountHolds:"
|
||||
|
||||
Reference in New Issue
Block a user