1#include <xrpl/beast/utility/instrumentation.h> 
    2#include <xrpl/ledger/PaymentSandbox.h> 
    3#include <xrpl/ledger/View.h> 
    4#include <xrpl/protocol/SField.h> 
   27    STAmount const& preCreditSenderBalance)
 
   31        "ripple::detail::DeferredCredits::credit : sender is not receiver");
 
   34        "ripple::detail::DeferredCredits::credit : positive amount");
 
   42        if (sender < receiver)
 
   61        if (sender < receiver)
 
   64            v.lowAcctCredits += amount;
 
 
   78        auto& mapVal = r.first->second;
 
 
  101    Key const k = makeKey(main, other, currency);
 
  102    auto i = credits_.find(k);
 
  103    if (i == credits_.end())
 
  106    auto const& v = i->second;
 
  111            v.highAcctCredits, v.lowAcctCredits, v.lowAcctOrigBalance);
 
  117            v.lowAcctCredits, v.highAcctCredits, -v.lowAcctOrigBalance);
 
 
  130            auto& toVal = r.first->second;
 
  131            auto const& fromVal = i.second;
 
  132            toVal.lowAcctCredits += fromVal.lowAcctCredits;
 
  133            toVal.highAcctCredits += fromVal.highAcctCredits;
 
  143            auto& toVal = r.first->second;
 
  144            auto const& fromVal = i.second;
 
 
  171    auto delta = amount.
zeroed();
 
  172    auto lastBal = amount;
 
  173    auto minBal = amount;
 
  174    for (
auto curSB = 
this; curSB; curSB = curSB->ps_)
 
  176        if (
auto adj = curSB->tab_.adjustments(account, issuer, currency))
 
  178            delta += adj->debits;
 
  179            lastBal = adj->origBalance;
 
  180            if (lastBal < minBal)
 
  189    auto adjustedAmt = 
std::min({amount, lastBal - delta, minBal});
 
  192    if (
isXRP(issuer) && adjustedAmt < beast::zero)
 
 
  207    for (
auto curSB = 
this; curSB; curSB = curSB->ps_)
 
  209        if (
auto adj = curSB->tab_.ownerCount(account))
 
 
  222    tab_.
credit(from, to, amount, preCreditBalance);
 
 
  237    XRPL_ASSERT(!
ps_, 
"ripple::PaymentSandbox::apply : non-null sandbox");
 
 
  244    XRPL_ASSERT(
ps_ == &to, 
"ripple::PaymentSandbox::apply : matching sandbox");
 
 
  261    auto each = [&result](
 
  277            auto const bt = before->getType();
 
  282                    highID = (*before)[sfAccount];
 
  283                    oldBalance = (*before)[sfBalance];
 
  284                    newBalance = oldBalance.
zeroed();
 
  287                    lowID = (*before)[sfLowLimit].getIssuer();
 
  288                    highID = (*before)[sfHighLimit].getIssuer();
 
  289                    oldBalance = (*before)[sfBalance];
 
  290                    newBalance = oldBalance.
zeroed();
 
  302            auto const at = 
after->getType();
 
  307                    highID = (*after)[sfAccount];
 
  308                    newBalance = (*after)[sfBalance];
 
  309                    oldBalance = newBalance.
zeroed();
 
  312                    lowID = (*after)[sfLowLimit].getIssuer();
 
  313                    highID = (*after)[sfHighLimit].getIssuer();
 
  314                    newBalance = (*after)[sfBalance];
 
  315                    oldBalance = newBalance.
zeroed();
 
  327            auto const at = 
after->getType();
 
  329                at == before->getType(),
 
  330                "ripple::PaymentSandbox::balanceChanges : after and before " 
  336                    highID = (*after)[sfAccount];
 
  337                    oldBalance = (*before)[sfBalance];
 
  338                    newBalance = (*after)[sfBalance];
 
  341                    lowID = (*after)[sfLowLimit].getIssuer();
 
  342                    highID = (*after)[sfHighLimit].getIssuer();
 
  343                    oldBalance = (*before)[sfBalance];
 
  344                    newBalance = (*after)[sfBalance];
 
  354        auto delta = newBalance - oldBalance;
 
  360            r.first->second += delta;
 
  367            r.first->second += delta;
 
 
A wrapper which makes credits unavailable to balances.
 
XRPAmount xrpDestroyed() const
 
std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const override
 
std::map< std::tuple< AccountID, AccountID, Currency >, STAmount > balanceChanges(ReadView const &view) const
 
void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance) override
 
void apply(RawView &to)
Apply changes to base view.
 
detail::DeferredCredits tab_
 
STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const override
 
void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next) override
 
PaymentSandbox const  * ps_
 
Interface for ledger entry changes.
 
void setIssuer(AccountID const &uIssuer)
 
Currency const & getCurrency() const
 
bool negative() const noexcept
 
AccountID const & getIssuer() const
 
STAmount zeroed() const
Returns a zero value with the same issuer and currency.
 
XRPAmount const & dropsDestroyed() const
 
void visit(ReadView const &base, std::function< void(uint256 const &key, bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)> const &func) const
 
void apply(RawView &to) const
 
detail::ApplyStateTable items_
 
std::optional< Adjustment > adjustments(AccountID const &main, AccountID const &other, Currency const ¤cy) const
 
void credit(AccountID const &sender, AccountID const &receiver, STAmount const &amount, STAmount const &preCreditSenderBalance)
 
void apply(DeferredCredits &to)
 
std::map< AccountID, std::uint32_t > ownerCounts_
 
void ownerCount(AccountID const &id, std::uint32_t cur, std::uint32_t next)
 
std::map< Key, Value > credits_
 
static Key makeKey(AccountID const &a1, AccountID const &a2, Currency const &c)
 
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
 
bool isXRP(AccountID const &c)
 
AccountID const & xrpAccount()
Compute AccountID from public key.
 
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
 
STAmount lowAcctOrigBalance