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>
50 STAmount const& preCreditSenderBalance)
52 assert(sender != receiver);
61 if (sender < receiver)
80 if (sender < receiver)
83 v.lowAcctCredits += amount;
97 auto& mapVal = r.first->second;
120 Key const k = makeKey(main, other, currency);
121 auto i = credits_.find(k);
122 if (i == credits_.end())
125 auto const& v = i->second;
130 v.highAcctCredits, v.lowAcctCredits, v.lowAcctOrigBalance);
136 v.lowAcctCredits, v.highAcctCredits, -v.lowAcctOrigBalance);
149 auto& toVal = r.first->second;
150 auto const& fromVal = i.second;
151 toVal.lowAcctCredits += fromVal.lowAcctCredits;
152 toVal.highAcctCredits += fromVal.highAcctCredits;
162 auto& toVal = r.first->second;
163 auto const& fromVal = i.second;
190 auto delta = amount.
zeroed();
191 auto lastBal = amount;
192 auto minBal = amount;
193 for (
auto curSB =
this; curSB; curSB = curSB->ps_)
195 if (
auto adj = curSB->tab_.adjustments(account, issuer, currency))
197 delta += adj->debits;
198 lastBal = adj->origBalance;
199 if (lastBal < minBal)
208 auto adjustedAmt =
std::min({amount, lastBal - delta, minBal});
209 adjustedAmt.setIssuer(amount.
getIssuer());
211 if (
isXRP(issuer) && adjustedAmt < beast::zero)
226 for (
auto curSB =
this; curSB; curSB = curSB->ps_)
228 if (
auto adj = curSB->tab_.ownerCount(account))
241 tab_.
credit(from, to, amount, preCreditBalance);
280 auto each = [&result](
296 auto const bt = before->getType();
303 newBalance = oldBalance.
zeroed();
309 newBalance = oldBalance.
zeroed();
321 auto const at =
after->getType();
328 oldBalance = newBalance.
zeroed();
334 oldBalance = newBalance.
zeroed();
346 auto const at =
after->getType();
347 assert(at == before->getType());
370 auto delta = newBalance - oldBalance;
376 r.first->second += delta;
383 r.first->second += delta;
XRPAmount xrpDestroyed() const
A wrapper which makes credits unavailable to balances.
std::optional< Adjustment > adjustments(AccountID const &main, AccountID const &other, Currency const ¤cy) 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
STAmount zeroed() const
Returns a zero value with the same issuer and currency.
void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next) override
detail::ApplyStateTable items_
std::map< std::tuple< AccountID, AccountID, Currency >, STAmount > balanceChanges(ReadView const &view) const
XRPAmount const & dropsDestroyed() const
std::map< Key, Value > credits_
void credit(AccountID const &sender, AccountID const &receiver, STAmount const &amount, STAmount const &preCreditSenderBalance)
AccountID const & getIssuer() const
const SF_AMOUNT sfLowLimit
@ ltOFFER
A ledger object which describes an offer on the DEX.
Interface for ledger entry changes.
void apply(RawView &to) const
PaymentSandbox const * ps_
AccountID const & xrpAccount()
Compute AccountID from public key.
bool isXRP(AccountID const &c)
const SF_AMOUNT sfHighLimit
void apply(DeferredCredits &to)
detail::DeferredCredits tab_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void apply(RawView &to)
Apply changes to base view.
@ ltACCOUNT_ROOT
A ledger object which describes an account.
bool negative() const noexcept
void ownerCount(AccountID const &id, std::uint32_t cur, std::uint32_t next)
const SF_AMOUNT sfBalance
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
const SF_ACCOUNT sfAccount
@ ltRIPPLE_STATE
A ledger object which describes a bidirectional trust line.
STAmount lowAcctOrigBalance
static Key makeKey(AccountID const &a1, AccountID const &a2, Currency const &c)
std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const override
Currency const & getCurrency() const
void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance) override
std::map< AccountID, std::uint32_t > ownerCounts_
STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const override