bug fixes, testing

This commit is contained in:
Richard Holland
2022-04-04 12:37:15 +00:00
parent d7f6007690
commit 166b4a76d4
2 changed files with 43 additions and 6 deletions

View File

@@ -150,8 +150,43 @@ closeChannel(
return tefINTERNAL;
assert((*slep)[sfAmount] >= (*slep)[sfBalance]);
(*sle)[sfBalance] =
(*sle)[sfBalance] + (*slep)[sfAmount] - (*slep)[sfBalance];
auto const amount = (*slep)[sfAmount] - (*slep)[sfBalance];
if (isXRP(amount))
{
(*sle)[sfBalance] = (*sle)[sfBalance] + amount;
}
else if (view.rules().enabled(featurePaychanAndEscrowForTokens))
{
// unlock the TL balance that was locked by this channel
auto& account = src;
auto issuerAccID = amount.getIssuer();
auto currency = amount.getCurrency();
auto sleSrcLine = view.peek(keylet::line(account, issuerAccID, currency));
bool isLow = account < issuerAccID;
STAmount priorLockedBalance =
isLow ? (*sleSrcLine)[sfLockedBalance] : -(*sleSrcLine)[sfLockedBalance];
STAmount finalLockedBalance = priorLockedBalance - amount;
if (finalLockedBalance < beast::zero)
{
JLOG(j.warn())
<< "Paychanel close would force locked balance below zero";
return tecINTERNAL;
}
if (finalLockedBalance == beast::zero)
sleSrcLine->makeFieldAbsent(sfLockedBalance);
else
sleSrcLine->setFieldAmount(sfLockedBalance, isLow ? finalLockedBalance : -finalLockedBalance);
view.update(sleSrcLine);
}
else
return tefINTERNAL;
adjustOwnerCount(view, sle, -1, j);
view.update(sle);
@@ -165,7 +200,8 @@ closeChannel(
TxConsequences
PayChanCreate::makeTxConsequences(PreflightContext const& ctx)
{
return TxConsequences{ctx.tx, ctx.tx[sfAmount].xrp()};
return TxConsequences{ctx.tx,
isXRP(ctx.tx[sfAmount]) ? ctx.tx[sfAmount].xrp() : beast::zero};
}
NotTEC
@@ -518,6 +554,7 @@ PayChanFund::doApply()
}
else if (ctx_.view().rules().enabled(featurePaychanAndEscrowForTokens))
{
// RH UPTO: add freeze checks for all featurePaychanAndEscrowForTokens applies on escrow and paychan
// find the user's trustline
auto const& account = src;
auto const currency = amount.getCurrency();
@@ -552,7 +589,7 @@ PayChanFund::doApply()
lockedBalance += high ? -amount : amount;
sleLine->setFieldAmount(sfLockedBalance, lockedBalance);
ctx_.view().update(sleLine);
view.update(sleLine);
}
else
return tecINTERNAL;

View File

@@ -56,7 +56,7 @@ enum class LedgerNameSpace : std::uint16_t {
FEE_SETTINGS = 'e',
TICKET = 'T',
SIGNER_LIST = 'S',
XRP_PAYMENT_CHANNEL = 'x',
PAYMENT_CHANNEL = 'x',
CHECK = 'C',
DEPOSIT_PREAUTH = 'p',
NEGATIVE_UNL = 'N',
@@ -322,7 +322,7 @@ payChan(AccountID const& src, AccountID const& dst, std::uint32_t seq) noexcept
{
return {
ltPAYCHAN,
indexHash(LedgerNameSpace::XRP_PAYMENT_CHANNEL, src, dst, seq)};
indexHash(LedgerNameSpace::PAYMENT_CHANNEL, src, dst, seq)};
}
} // namespace keylet