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>
48 STAmount const& preCreditSenderBalance)
50 assert (sender != receiver);
59 if (sender < receiver)
78 if (sender < receiver)
81 v.lowAcctCredits += amount;
94 auto& mapVal = r.first->second;
99 boost::optional<std::uint32_t>
112 Currency const& currency)
const -> boost::optional<Adjustment>
114 boost::optional<Adjustment> result;
116 Key const k = makeKey (main, other, currency);
117 auto i = credits_.find (k);
118 if (i == credits_.end ())
121 auto const& v = i->second;
125 result.emplace (v.highAcctCredits, v.lowAcctCredits, v.lowAcctOrigBalance);
130 result.emplace (v.lowAcctCredits, v.highAcctCredits, -v.lowAcctOrigBalance);
143 auto& toVal = r.first->second;
144 auto const& fromVal = i.second;
145 toVal.lowAcctCredits += fromVal.lowAcctCredits;
146 toVal.highAcctCredits += fromVal.highAcctCredits;
156 auto& toVal = r.first->second;
157 auto const& fromVal = i.second;
183 auto delta = amount.
zeroed ();
184 auto lastBal = amount;
185 auto minBal = amount;
186 for (
auto curSB =
this; curSB; curSB = curSB->ps_)
188 if (
auto adj = curSB->tab_.adjustments (account, issuer, currency))
190 delta += adj->debits;
191 lastBal = adj->origBalance;
192 if (lastBal < minBal)
201 auto adjustedAmt =
std::min({amount, lastBal - delta, minBal});
202 adjustedAmt.setIssuer(amount.
getIssuer());
204 if (
isXRP(issuer) && adjustedAmt < beast::zero)
219 for (
auto curSB =
this; curSB; curSB = curSB->ps_)
221 if (
auto adj = curSB->tab_.ownerCount (account))
233 tab_.
credit (from, to, amount, preCreditBalance);
270 auto each = [&result](
uint256 const& key,
bool isDelete,
285 auto const bt = before->getType ();
292 newBalance = oldBalance.
zeroed();
298 newBalance = oldBalance.
zeroed();
310 auto const at =
after->getType ();
317 oldBalance = newBalance.
zeroed();
323 oldBalance = newBalance.
zeroed();
335 auto const at =
after->getType ();
336 assert (at == before->getType ());
359 auto delta = newBalance - oldBalance;
365 r.first->second += delta;
372 r.first->second += delta;
XRPAmount xrpDestroyed() const
A wrapper which makes credits unavailable to balances.
boost::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
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
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
const SF_Amount sfHighLimit(access, STI_AMOUNT, 7, "HighLimit")
XRPAmount const & dropsDestroyed() const
std::map< Key, Value > credits_
const SF_Amount sfLowLimit(access, STI_AMOUNT, 6, "LowLimit")
void credit(AccountID const &sender, AccountID const &receiver, STAmount const &amount, STAmount const &preCreditSenderBalance)
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)
void apply(DeferredCredits &to)
Currency const & getCurrency() const
AccountID const & getIssuer() const
detail::DeferredCredits tab_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
const SF_Amount sfBalance(access, STI_AMOUNT, 2, "Balance")
void apply(RawView &to)
Apply changes to base view.
bool negative() const noexcept
void ownerCount(AccountID const &id, std::uint32_t cur, std::uint32_t next)
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
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
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