Skip to content

Commit

Permalink
Address reviewer's feedback:
Browse files Browse the repository at this point in the history
* Fix paths comments in Payment
* Refactor View
  • Loading branch information
gregtatcam committed Oct 14, 2024
1 parent 9b8564e commit ac45342
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/xrpld/app/tx/detail/Payment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Payment::preflight(PreflightContext const& ctx)
TER
Payment::preclaim(PreclaimContext const& ctx)
{
// Ripple if source or destination is non-native or if there are hasPaths.
// Ripple if source or destination is non-native or if there are paths.
std::uint32_t const txFlags = ctx.tx.getFlags();
bool const partialPaymentAllowed = txFlags & tfPartialPayment;
auto const hasPaths = ctx.tx.isFieldPresent(sfPaths);
Expand Down Expand Up @@ -321,7 +321,7 @@ Payment::doApply()
{
auto const deliverMin = ctx_.tx[~sfDeliverMin];

// Ripple if source or destination is non-native or if there are hasPaths.
// Ripple if source or destination is non-native or if there are paths.
std::uint32_t const txFlags = ctx_.tx.getFlags();
bool const partialPaymentAllowed = txFlags & tfPartialPayment;
bool const limitQuality = txFlags & tfLimitQuality;
Expand Down
44 changes: 15 additions & 29 deletions src/xrpld/ledger/detail/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1892,20 +1892,17 @@ rippleCreditMPT(
{
auto const mptID = keylet::mptIssuance(saAmount.get<MPTIssue>().getMptID());
auto const issuer = saAmount.getIssuer();
if (!view.exists(mptID))
auto sleIssuance = view.peek(mptID);
if (!sleIssuance)
return tecOBJECT_NOT_FOUND;
if (uSenderID == issuer)
{
if (auto sle = view.peek(mptID))
{
sle->setFieldU64(
sfOutstandingAmount,
sle->getFieldU64(sfOutstandingAmount) + saAmount.mpt().value());
sleIssuance->setFieldU64(
sfOutstandingAmount,
sleIssuance->getFieldU64(sfOutstandingAmount) +
saAmount.mpt().value());

view.update(sle);
}
else
return tecINTERNAL;
view.update(sleIssuance);
}
else
{
Expand All @@ -1914,34 +1911,23 @@ rippleCreditMPT(
{
auto const amt = sle->getFieldU64(sfMPTAmount);
auto const pay = saAmount.mpt().value();
if (amt >= pay)
{
if (amt == pay)
sle->makeFieldAbsent(sfMPTAmount);
else
sle->setFieldU64(sfMPTAmount, amt - pay);
view.update(sle);
}
else
if (amt < pay)
return tecINSUFFICIENT_FUNDS;
(*sle)[sfMPTAmount] = amt - pay;
view.update(sle);
}
else
return tecNO_AUTH;
}

if (uReceiverID == issuer)
{
if (auto sle = view.peek(mptID))
auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
auto const redeem = saAmount.mpt().value();
if (outstanding >= redeem)
{
auto const outstanding = sle->getFieldU64(sfOutstandingAmount);
auto const redeem = saAmount.mpt().value();
if (outstanding >= redeem)
{
sle->setFieldU64(sfOutstandingAmount, outstanding - redeem);
view.update(sle);
}
else
return tecINSUFFICIENT_FUNDS;
sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem);
view.update(sleIssuance);
}
else
return tecINTERNAL;
Expand Down

0 comments on commit ac45342

Please sign in to comment.