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;
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