20 #ifndef RIPPLE_APP_PATHS_IMPL_PAYSTEPS_H_INCLUDED
21 #define RIPPLE_APP_PATHS_IMPL_PAYSTEPS_H_INCLUDED
23 #include <ripple/app/paths/impl/AmountSpec.h>
24 #include <ripple/basics/Log.h>
25 #include <ripple/protocol/Quality.h>
26 #include <ripple/protocol/STLedgerEntry.h>
27 #include <ripple/protocol/TER.h>
29 #include <boost/container/flat_set.hpp>
82 virtual ~Step() =
default;
99 boost::container::flat_set<uint256>& ofrsToRm,
117 boost::container::flat_set<uint256>& ofrsToRm,
264 return lhs.
equal(rhs);
276 return !(lhs == rhs);
299 offersUsed(Strand
const& strand)
302 for (
auto const& step : strand)
305 r += step->offersUsed();
313 operator==(Strand
const& lhs, Strand
const& rhs)
315 if (lhs.size() != rhs.size())
317 for (
size_t i = 0, e = lhs.size(); i != e; ++i)
318 if (*lhs[i] != *rhs[i])
341 Issue
const& deliver,
372 Issue
const& deliver,
376 bool ownerPaysTransferFee,
409 Issue
const& deliver,
412 STPathSet
const& paths,
414 bool ownerPaysTransferFee,
419 template <
class TIn,
class TOut,
class TDerived>
420 struct StepImp :
public Step
422 explicit StepImp() =
default;
425 rev(PaymentSandbox& sb,
427 boost::container::flat_set<uint256>& ofrsToRm,
428 EitherAmount
const& out)
override
430 auto const r =
static_cast<TDerived*
>(
this)->revImp(
431 sb, afView, ofrsToRm, get<TOut>(out));
432 return {EitherAmount(r.first), EitherAmount(r.second)};
438 fwd(PaymentSandbox& sb,
440 boost::container::flat_set<uint256>& ofrsToRm,
441 EitherAmount
const& in)
override
443 auto const r =
static_cast<TDerived*
>(
this)->fwdImp(
444 sb, afView, ofrsToRm, get<TIn>(in));
445 return {EitherAmount(r.first), EitherAmount(r.second)};
449 isZero(EitherAmount
const& out)
const override
451 return get<TOut>(out) == beast::zero;
455 equalOut(EitherAmount
const& lhs, EitherAmount
const& rhs)
const override
457 return get<TOut>(lhs) == get<TOut>(rhs);
461 equalIn(EitherAmount
const& lhs, EitherAmount
const& rhs)
const override
463 return get<TIn>(lhs) == get<TIn>(rhs);
476 :
std::runtime_error(msg), ter(t)
489 checkNear(IOUAmount
const& expected, IOUAmount
const& actual);
491 checkNear(XRPAmount
const& expected, XRPAmount
const& actual);
534 Issue const& strandDeliver_,
537 bool ownerPaysTransferFee_,
540 std::array<boost::container::flat_set<Issue>, 2>&
542 boost::container::flat_set<Issue>&
566 StrandContext
const& ctx,
572 make_BookStepII(StrandContext
const& ctx, Issue
const& in, Issue
const& out);
583 template <
class InAmt,
class OutAmt>
virtual bool equalIn(EitherAmount const &lhs, EitherAmount const &rhs) const =0
Return true if In of lhs == In of rhs.
Context needed to build Strand Steps and for error checking.
const size_t strandSize
Length of Strand.
bool issues(DebtDirection dir)
A currency issued by an account.
virtual std::optional< EitherAmount > cachedIn() const =0
Amount of currency computed coming into the Step the last time the step ran in reverse.
std::pair< TER, STPath > normalizePath(AccountID const &src, AccountID const &dst, Issue const &deliver, std::optional< Issue > const &sendMaxIssue, STPath const &path)
virtual bool isZero(EitherAmount const &out) const =0
Check if amount is zero.
const Issue strandDeliver
Issue strand delivers.
A wrapper which makes credits unavailable to balances.
std::pair< TER, std::unique_ptr< Step > > make_BookStepXI(StrandContext const &ctx, Issue const &out)
std::pair< TER, std::unique_ptr< Step > > make_BookStepII(StrandContext const &ctx, Issue const &in, Issue const &out)
virtual std::optional< AccountID > directStepSrcAcct() const
If this step is DirectStepI (IOU->IOU direct step), return the src account.
friend bool operator!=(Step const &lhs, Step const &rhs)
Return true if lhs != rhs.
const bool ownerPaysTransferFee
true if owner, not sender, pays fee
virtual DebtDirection debtDirection(ReadView const &sb, StrandDirection dir) const =0
If this step is a DirectStepI and the src redeems to the dst, return true, otherwise return false.
virtual std::uint32_t lineQualityIn(ReadView const &) const
If this step is a DirectStepI, return the quality in of the dst account.
bool checkNear(IOUAmount const &expected, IOUAmount const &actual)
std::pair< TER, std::unique_ptr< Step > > make_DirectStepI(StrandContext const &ctx, AccountID const &src, AccountID const &dst, Currency const &c)
friend bool operator==(Step const &lhs, Step const &rhs)
Return true if lhs == rhs.
std::pair< TER, Strand > toStrand(ReadView const &view, AccountID const &src, AccountID const &dst, Issue const &deliver, std::optional< Quality > const &limitQuality, std::optional< Issue > const &sendMaxIssue, STPath const &path, bool ownerPaysTransferFee, bool offerCrossing, beast::Journal j)
Create a Strand for the specified path.
bool bookStepEqual(Step const &step, ripple::Book const &book)
friend std::ostream & operator<<(std::ostream &stream, Step const &step)
Streaming operator for a Step.
virtual bool equalOut(EitherAmount const &lhs, EitherAmount const &rhs) const =0
Return true if Out of lhs == Out of rhs.
Writeable view to a ledger, for applying a transaction.
bool operator==(Manifest const &lhs, Manifest const &rhs)
std::pair< TER, std::vector< Strand > > toStrands(ReadView const &view, AccountID const &src, AccountID const &dst, Issue const &deliver, std::optional< Quality > const &limitQuality, std::optional< Issue > const &sendMax, STPathSet const &paths, bool addDefaultPath, bool ownerPaysTransferFee, bool offerCrossing, beast::Journal j)
Create a Strand for each specified path (including the default path, if indicated)
const AccountID strandSrc
Strand source account.
virtual std::optional< Book > bookStepBook() const
If this step is a BookStep, return the book.
ReadView const & view
Current ReadView.
virtual bool inactive() const
Return true if the step should be considered inactive.
virtual std::pair< EitherAmount, EitherAmount > fwd(PaymentSandbox &sb, ApplyView &afView, boost::container::flat_set< uint256 > &ofrsToRm, EitherAmount const &in)=0
Find the amount we get out of the step given the input subject to liquidity limits.
const bool offerCrossing
true if offer crossing, not payment
virtual bool equal(Step const &rhs) const =0
const std::optional< Quality > limitQuality
Worst accepted quality.
std::pair< TER, std::unique_ptr< Step > > make_XRPEndpointStep(StrandContext const &ctx, AccountID const &acc)
A step in a payment path.
TERSubset< CanCvtToTER > TER
virtual std::pair< std::optional< Quality >, DebtDirection > qualityUpperBound(ReadView const &v, DebtDirection prevStepDir) const =0
Find an upper bound of quality for the step.
virtual std::pair< bool, EitherAmount > validFwd(PaymentSandbox &sb, ApplyView &afView, EitherAmount const &in)=0
Check that the step can correctly execute in the forward direction.
boost::container::flat_set< Issue > & seenBookOuts
A strand may not include an offer that output the same issue more than once.
const bool isLast
true if Step is last in Strand
A generic endpoint for log messages.
bool isDirectXrpToXrp(Strand const &strand)
std::string transHuman(TER code)
bool directStepEqual(Step const &step, AccountID const &src, AccountID const &dst, Currency const ¤cy)
bool redeems(DebtDirection dir)
base_uint< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
virtual std::optional< EitherAmount > cachedOut() const =0
Amount of currency computed coming out of the Step the last time the step ran in reverse.
StrandContext(ReadView const &view_, std::vector< std::unique_ptr< Step >> const &strand_, AccountID const &strandSrc_, AccountID const &strandDst_, Issue const &strandDeliver_, std::optional< Quality > const &limitQuality_, bool isLast_, bool ownerPaysTransferFee_, bool offerCrossing_, bool isDefaultPath_, std::array< boost::container::flat_set< Issue >, 2 > &seenDirectIssues_, boost::container::flat_set< Issue > &seenBookOuts_, beast::Journal j_)
StrandContext constructor.
virtual std::string logString() const =0
const AccountID strandDst
Strand destination account.
const bool isFirst
true if Step is first in Strand
Step const *const prevStep
The previous step in the strand.
virtual std::optional< std::pair< AccountID, AccountID > > directStepAccts() const
virtual std::pair< EitherAmount, EitherAmount > rev(PaymentSandbox &sb, ApplyView &afView, boost::container::flat_set< uint256 > &ofrsToRm, EitherAmount const &out)=0
Find the amount we need to put into the step to get the requested out subject to liquidity limits.
bool xrpEndpointStepEqual(Step const &step, AccountID const &acc)
virtual std::uint32_t offersUsed() const
Return the number of offers consumed or partially consumed the last time the step ran,...
std::pair< TER, std::unique_ptr< Step > > make_BookStepIX(StrandContext const &ctx, Issue const &in)
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.
const bool isDefaultPath
true if Strand is default path
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.