From 7f8fd583b26281641bd1efc472e488c9de163153 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 8 Apr 2026 14:13:46 -0400 Subject: [PATCH] respond to comments --- include/xrpl/ledger/PaymentSandbox.h | 7 - include/xrpl/tx/paths/detail/FlowDebugInfo.h | 23 ---- src/libxrpl/ledger/PaymentSandbox.cpp | 125 ------------------ src/libxrpl/ledger/helpers/MPTokenHelpers.cpp | 1 + .../tx/transactors/dex/OfferCreate.cpp | 3 +- 5 files changed, 2 insertions(+), 157 deletions(-) diff --git a/include/xrpl/ledger/PaymentSandbox.h b/include/xrpl/ledger/PaymentSandbox.h index 36224525b6..42f62ef976 100644 --- a/include/xrpl/ledger/PaymentSandbox.h +++ b/include/xrpl/ledger/PaymentSandbox.h @@ -228,13 +228,6 @@ public: apply(PaymentSandbox& to); /** @} */ - // Return a map of balance changes on trust lines. The low account is the - // first account in the key. If the two accounts are equal, the map contains - // the total changes in currency regardless of issuer. This is useful to get - // the total change in XRP balances. - std::map, STAmount> - balanceChanges(ReadView const& view) const; - XRPAmount xrpDestroyed() const; diff --git a/include/xrpl/tx/paths/detail/FlowDebugInfo.h b/include/xrpl/tx/paths/detail/FlowDebugInfo.h index 3a1f45fd02..2c8172f219 100644 --- a/include/xrpl/tx/paths/detail/FlowDebugInfo.h +++ b/include/xrpl/tx/paths/detail/FlowDebugInfo.h @@ -312,29 +312,6 @@ writeDiffs(std::ostringstream& ostr, Iter begin, Iter end) ostr << ']'; }; -using BalanceDiffs = - std::pair, STAmount>, XRPAmount>; - -inline BalanceDiffs -balanceDiffs(PaymentSandbox const& sb, ReadView const& rv) -{ - return {sb.balanceChanges(rv), sb.xrpDestroyed()}; -} - -inline std::string -balanceDiffsToString(std::optional const& bd) -{ - if (!bd) - return std::string{}; - auto const& diffs = bd->first; - auto const& xrpDestroyed = bd->second; - std::ostringstream ostr; - ostr << ", xrpDestroyed: " << to_string(xrpDestroyed); - ostr << ", balanceDiffs: "; - writeDiffs(ostr, diffs.begin(), diffs.end()); - return ostr.str(); -}; - } // namespace detail } // namespace path } // namespace xrpl diff --git a/src/libxrpl/ledger/PaymentSandbox.cpp b/src/libxrpl/ledger/PaymentSandbox.cpp index 497bd74b23..b8de771e5d 100644 --- a/src/libxrpl/ledger/PaymentSandbox.cpp +++ b/src/libxrpl/ledger/PaymentSandbox.cpp @@ -450,131 +450,6 @@ PaymentSandbox::apply(PaymentSandbox& to) tab_.apply(to.tab_); } -std::map, STAmount> -PaymentSandbox::balanceChanges(ReadView const& view) const -{ - using key_t = std::tuple; - // Map of delta trust lines. As a special case, when both ends of the trust - // line are the same currency, then it's delta currency for that issuer. To - // get the change in XRP balance, Account == root, issuer == root, currency - // == XRP - std::map result; - - // populate a dictionary with low/high/currency/delta. This can be - // compared with the other versions payment code. - auto each = [&result]( - uint256 const& key, - bool isDelete, - std::shared_ptr const& before, - std::shared_ptr const& after) { - STAmount oldBalance; - STAmount newBalance; - AccountID lowID; - AccountID highID; - - // before is read from prev view - if (isDelete) - { - if (!before) - return; - - auto const bt = before->getType(); - switch (bt) - { - case ltACCOUNT_ROOT: - lowID = xrpAccount(); - highID = (*before)[sfAccount]; - oldBalance = (*before)[sfBalance]; - newBalance = oldBalance.zeroed(); - break; - case ltRIPPLE_STATE: - lowID = (*before)[sfLowLimit].getIssuer(); - highID = (*before)[sfHighLimit].getIssuer(); - oldBalance = (*before)[sfBalance]; - newBalance = oldBalance.zeroed(); - break; - case ltOFFER: - // TBD - break; - default: - break; - } - } - else if (!before) - { - // insert - auto const at = after->getType(); - switch (at) - { - case ltACCOUNT_ROOT: - lowID = xrpAccount(); - highID = (*after)[sfAccount]; - newBalance = (*after)[sfBalance]; - oldBalance = newBalance.zeroed(); - break; - case ltRIPPLE_STATE: - lowID = (*after)[sfLowLimit].getIssuer(); - highID = (*after)[sfHighLimit].getIssuer(); - newBalance = (*after)[sfBalance]; - oldBalance = newBalance.zeroed(); - break; - case ltOFFER: - // TBD - break; - default: - break; - } - } - else - { - // modify - auto const at = after->getType(); - XRPL_ASSERT( - at == before->getType(), - "xrpl::PaymentSandbox::balanceChanges : after and before " - "types matching"); - switch (at) - { - case ltACCOUNT_ROOT: - lowID = xrpAccount(); - highID = (*after)[sfAccount]; - oldBalance = (*before)[sfBalance]; - newBalance = (*after)[sfBalance]; - break; - case ltRIPPLE_STATE: - lowID = (*after)[sfLowLimit].getIssuer(); - highID = (*after)[sfHighLimit].getIssuer(); - oldBalance = (*before)[sfBalance]; - newBalance = (*after)[sfBalance]; - break; - case ltOFFER: - // TBD - break; - default: - break; - } - } - // The following are now set, put them in the map - auto delta = newBalance - oldBalance; - auto const cur = newBalance.get().currency; - result[std::make_tuple(lowID, highID, cur)] = delta; - auto r = result.emplace(std::make_tuple(lowID, lowID, cur), delta); - if (!r.second) - { - r.first->second += delta; - } - - delta.negate(); - r = result.emplace(std::make_tuple(highID, highID, cur), delta); - if (!r.second) - { - r.first->second += delta; - } - }; - items_.visit(view, each); - return result; -} - XRPAmount PaymentSandbox::xrpDestroyed() const { diff --git a/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp b/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp index 65175d86ff..bbf1900cf6 100644 --- a/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp +++ b/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/src/libxrpl/tx/transactors/dex/OfferCreate.cpp b/src/libxrpl/tx/transactors/dex/OfferCreate.cpp index 93fda9a30b..1df49910f2 100644 --- a/src/libxrpl/tx/transactors/dex/OfferCreate.cpp +++ b/src/libxrpl/tx/transactors/dex/OfferCreate.cpp @@ -682,8 +682,7 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel) stream << " out: " << format_amount(place_offer.out); } - bool const isLedgerOpen = sb.open(); - if (result == tecFAILED_PROCESSING && isLedgerOpen) + if (result == tecFAILED_PROCESSING && sb.open()) result = telFAILED_PROCESSING; if (!isTesSuccess(result))