20 #include <ripple/app/paths/Credit.h>
21 #include <ripple/app/paths/impl/AmountSpec.h>
22 #include <ripple/app/paths/impl/StepChecks.h>
23 #include <ripple/app/paths/impl/Steps.h>
24 #include <ripple/basics/IOUAmount.h>
25 #include <ripple/basics/Log.h>
26 #include <ripple/basics/XRPAmount.h>
27 #include <ripple/ledger/PaymentSandbox.h>
28 #include <ripple/protocol/Feature.h>
29 #include <ripple/protocol/Quality.h>
31 #include <boost/container/flat_set.hpp>
38 template <
class TDerived>
40 :
public StepImp<XRPAmount, XRPAmount, XRPEndpointStep<TDerived>>
106 boost::container::flat_set<uint256>& ofrsToRm,
113 boost::container::flat_set<uint256>& ofrsToRm,
136 <<
"\nAcc: " <<
acc_;
148 return !(lhs == rhs);
235 template <
class TDerived>
244 template <
class TDerived>
255 template <
class TDerived>
260 boost::container::flat_set<uint256>& ofrsToRm,
263 auto const balance =
static_cast<TDerived const*
>(
this)->
xrpLiquid(sb);
268 auto& receiver = isLast_ ? acc_ :
xrpAccount();
273 cache_.emplace(result);
274 return {result, result};
277 template <
class TDerived>
282 boost::container::flat_set<uint256>& ofrsToRm,
286 auto const balance =
static_cast<TDerived const*
>(
this)->
xrpLiquid(sb);
288 auto const result = isLast_ ?
in :
std::min(balance,
in);
291 auto& receiver = isLast_ ? acc_ :
xrpAccount();
296 cache_.emplace(result);
297 return {result, result};
300 template <
class TDerived>
309 JLOG(j_.
error()) <<
"Expected valid cache in validFwd";
315 auto const& xrpIn =
in.xrp;
316 auto const balance =
static_cast<TDerived const*
>(
this)->
xrpLiquid(sb);
318 if (!isLast_ && balance < xrpIn)
320 JLOG(j_.
warn()) <<
"XRPEndpointStep: Strand re-execute check failed."
321 <<
" Insufficient balance: " <<
to_string(balance)
326 if (xrpIn != *cache_)
328 JLOG(j_.
warn()) <<
"XRPEndpointStep: Strand re-execute check failed."
335 template <
class TDerived>
341 JLOG(j_.
debug()) <<
"XRPEndpointStep: specified bad account.";
348 JLOG(j_.
warn()) <<
"XRPEndpointStep: can't send or receive XRP from "
349 "non-existent account: "
367 auto const issuesIndex = isLast_ ? 0 : 1;
371 <<
"XRPEndpointStep: loop detected: Index: " << ctx.
strandSize
390 return xs->acc() == acc;
405 auto offerCrossingStep =
406 std::make_unique<XRPEndpointOfferCrossingStep>(ctx, acc);
407 ter = offerCrossingStep->check(ctx);
408 r = std::move(offerCrossingStep);
412 auto paymentStep = std::make_unique<XRPEndpointPaymentStep>(ctx, acc);
413 ter = paymentStep->check(ctx);
414 r = std::move(paymentStep);
417 return {ter,
nullptr};
Context needed to build Strand Steps and for error checking.
const size_t strandSize
Length of Strand.
static std::int32_t computeReserveReduction(StrandContext const &ctx, AccountID const &acc)
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
XRPEndpointOfferCrossingStep(StrandContext const &ctx, AccountID const &acc)
std::pair< XRPAmount, XRPAmount > fwdImp(PaymentSandbox &sb, ApplyView &afView, boost::container::flat_set< uint256 > &ofrsToRm, XRPAmount const &in)
const Issue strandDeliver
Issue strand delivers.
A wrapper which makes credits unavailable to balances.
AccountID const & acc() const
friend bool operator!=(XRPEndpointStep const &lhs, XRPEndpointStep const &rhs)
std::optional< EitherAmount > cached() const
Writeable view to a ledger, for applying a transaction.
const std::int32_t reserveReduction_
bool operator==(Manifest const &lhs, Manifest const &rhs)
std::optional< XRPAmount > cache_
ReadView const & view
Current ReadView.
std::optional< EitherAmount > cachedOut() const override
Keylet account(AccountID const &id) noexcept
AccountID root.
const bool offerCrossing
true if offer crossing, not payment
bool equal(Step const &rhs) const override
friend bool operator==(XRPEndpointStep< P > const &lhs, XRPEndpointStep< P > const &rhs)
STAmount toSTAmount(IOUAmount const &iou, Issue const &iss)
std::pair< TER, std::unique_ptr< Step > > make_XRPEndpointStep(StrandContext const &ctx, AccountID const &acc)
std::string logStringImpl(char const *name) const
A step in a payment path.
std::string logString() const override
XRPAmount xrpLiquid(ReadView &sb) const
TER accountSend(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j)
XRPEndpointStep(StrandContext const &ctx, AccountID const &acc)
AccountID const & xrpAccount()
Compute AccountID from public key.
XRPAmount xrpLiquid(ReadView const &view, AccountID const &id, std::int32_t ownerCountAdj, beast::Journal j)
XRPAmount xrpLiquid(ReadView &sb) const
XRPAmount xrpLiquidImpl(ReadView &sb, std::int32_t reserveReduction) const
const bool isLast
true if Step is last in Strand
A generic endpoint for log messages.
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
std::optional< EitherAmount > cachedIn() const override
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
virtual Rules const & rules() const =0
Returns the tx processing rules.
TER check(StrandContext const &ctx) const
const bool isFirst
true if Step is first in Strand
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
TER checkFreeze(ReadView const &view, AccountID const &src, AccountID const &dst, Currency const ¤cy)
std::pair< bool, EitherAmount > validFwd(PaymentSandbox &sb, ApplyView &afView, EitherAmount const &in) override
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
bool xrpEndpointStepEqual(Step const &step, AccountID const &acc)
std::string logString() const override
std::optional< std::pair< AccountID, AccountID > > directStepAccts() const override
std::pair< XRPAmount, XRPAmount > revImp(PaymentSandbox &sb, ApplyView &afView, boost::container::flat_set< uint256 > &ofrsToRm, XRPAmount const &out)
std::array< boost::container::flat_set< Issue >, 2 > & seenDirectIssues
A strand may not include the same account node more than once in the same currency.
std::pair< std::optional< Quality >, DebtDirection > qualityUpperBound(ReadView const &v, DebtDirection prevStepDir) const override
DebtDirection debtDirection(ReadView const &sb, StrandDirection dir) const override
Currency const & xrpCurrency()
XRP currency.
static const std::uint64_t uRateOne