20 #include <ripple/app/paths/impl/AmountSpec.h>
21 #include <ripple/ledger/PaymentSandbox.h>
22 #include <ripple/ledger/View.h>
23 #include <ripple/protocol/Feature.h>
24 #include <ripple/protocol/SField.h>
25 #include <ripple/protocol/STAccount.h>
26 #include <boost/optional.hpp>
51 STAmount const& preCreditSenderBalance)
53 assert(sender != receiver);
62 if (sender < receiver)
81 if (sender < receiver)
84 v.lowAcctCredits += amount;
98 auto& mapVal = r.first->second;
103 boost::optional<std::uint32_t>
117 Currency const& currency)
const -> boost::optional<Adjustment>
119 boost::optional<Adjustment> result;
121 Key const k = makeKey(main, other, currency);
122 auto i = credits_.find(k);
123 if (i == credits_.end())
126 auto const& v = i->second;
131 v.highAcctCredits, v.lowAcctCredits, v.lowAcctOrigBalance);
137 v.lowAcctCredits, v.highAcctCredits, -v.lowAcctOrigBalance);
150 auto& toVal = r.first->second;
151 auto const& fromVal = i.second;
152 toVal.lowAcctCredits += fromVal.lowAcctCredits;
153 toVal.highAcctCredits += fromVal.highAcctCredits;
163 auto& toVal = r.first->second;
164 auto const& fromVal = i.second;
191 auto delta = amount.
zeroed();
192 auto lastBal = amount;
193 auto minBal = amount;
194 for (
auto curSB =
this; curSB; curSB = curSB->ps_)
196 if (
auto adj = curSB->tab_.adjustments(account, issuer, currency))
198 delta += adj->debits;
199 lastBal = adj->origBalance;
200 if (lastBal < minBal)
209 auto adjustedAmt =
std::min({amount, lastBal - delta, minBal});
210 adjustedAmt.setIssuer(amount.
getIssuer());
212 if (
isXRP(issuer) && adjustedAmt < beast::zero)
227 for (
auto curSB =
this; curSB; curSB = curSB->ps_)
229 if (
auto adj = curSB->tab_.ownerCount(account))
242 tab_.
credit(from, to, amount, preCreditBalance);
281 auto each = [&result](
297 auto const bt = before->getType();
304 newBalance = oldBalance.
zeroed();
310 newBalance = oldBalance.
zeroed();
322 auto const at =
after->getType();
329 oldBalance = newBalance.
zeroed();
335 oldBalance = newBalance.
zeroed();
347 auto const at =
after->getType();
348 assert(at == before->getType());
371 auto delta = newBalance - oldBalance;
377 r.first->second += delta;
384 r.first->second += delta;