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>
30 #include <boost/optional.hpp>
82 virtual ~Step() =
default;
99 boost::container::flat_set<uint256>& ofrsToRm,
117 boost::container::flat_set<uint256>& ofrsToRm,
124 virtual boost::optional<EitherAmount>
131 virtual boost::optional<EitherAmount>
138 virtual boost::optional<AccountID>
146 virtual boost::optional<std::pair<AccountID, AccountID>>
194 virtual boost::optional<Book>
251 return lhs.
equal(rhs);
263 return !(lhs == rhs);
288 operator==(Strand
const& lhs, Strand
const& rhs)
290 if (lhs.size() != rhs.size())
292 for (
size_t i = 0, e = lhs.size(); i != e; ++i)
293 if (*lhs[i] != *rhs[i])
316 Issue
const& deliver,
317 boost::optional<Issue>
const& sendMaxIssue,
347 Issue
const& deliver,
348 boost::optional<Quality>
const& limitQuality,
349 boost::optional<Issue>
const& sendMaxIssue,
351 bool ownerPaysTransferFee,
384 Issue
const& deliver,
385 boost::optional<Quality>
const& limitQuality,
386 boost::optional<Issue>
const& sendMax,
387 STPathSet
const& paths,
389 bool ownerPaysTransferFee,
394 template <
class TIn,
class TOut,
class TDerived>
395 struct StepImp :
public Step
397 explicit StepImp() =
default;
400 rev(PaymentSandbox& sb,
402 boost::container::flat_set<uint256>& ofrsToRm,
403 EitherAmount
const& out)
override
405 auto const r =
static_cast<TDerived*
>(
this)->revImp(
406 sb, afView, ofrsToRm, get<TOut>(out));
407 return {EitherAmount(r.first), EitherAmount(r.second)};
413 fwd(PaymentSandbox& sb,
415 boost::container::flat_set<uint256>& ofrsToRm,
416 EitherAmount
const& in)
override
418 auto const r =
static_cast<TDerived*
>(
this)->fwdImp(
419 sb, afView, ofrsToRm, get<TIn>(in));
420 return {EitherAmount(r.first), EitherAmount(r.second)};
424 isZero(EitherAmount
const& out)
const override
426 return get<TOut>(out) == beast::zero;
430 equalOut(EitherAmount
const& lhs, EitherAmount
const& rhs)
const override
432 return get<TOut>(lhs) == get<TOut>(rhs);
436 equalIn(EitherAmount
const& lhs, EitherAmount
const& rhs)
const override
438 return get<TIn>(lhs) == get<TIn>(rhs);
451 :
std::runtime_error(msg), ter(t)
464 checkNear(IOUAmount
const& expected, IOUAmount
const& actual);
466 checkNear(XRPAmount
const& expected, XRPAmount
const& actual);
509 Issue const& strandDeliver_,
510 boost::optional<Quality>
const& limitQuality_,
512 bool ownerPaysTransferFee_,
515 std::array<boost::container::flat_set<Issue>, 2>&
517 boost::container::flat_set<Issue>&
541 StrandContext
const& ctx,
547 make_BookStepII(StrandContext
const& ctx, Issue
const& in, Issue
const& out);
558 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 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)
friend bool operator!=(Step const &lhs, Step const &rhs)
Return true if lhs != rhs.
std::pair< TER, STPath > normalizePath(AccountID const &src, AccountID const &dst, Issue const &deliver, boost::optional< Issue > const &sendMaxIssue, STPath const &path)
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.
std::pair< TER, Strand > toStrand(ReadView const &view, AccountID const &src, AccountID const &dst, Issue const &deliver, boost::optional< Quality > const &limitQuality, boost::optional< Issue > const &sendMaxIssue, STPath const &path, bool ownerPaysTransferFee, bool offerCrossing, beast::Journal j)
Create a Strand for the specified path.
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.
virtual boost::optional< Book > bookStepBook() const
If this step is a BookStep, return the book.
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)
virtual boost::optional< EitherAmount > cachedOut() const =0
Amount of currency computed coming out of the Step the last time the step ran in reverse.
const AccountID strandSrc
Strand source account.
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
virtual boost::optional< EitherAmount > cachedIn() const =0
Amount of currency computed coming into 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_, boost::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.
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< 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::string logString() const =0
virtual std::pair< boost::optional< Quality >, DebtDirection > qualityUpperBound(ReadView const &v, DebtDirection prevStepDir) const =0
Find an upper bound of quality for the step.
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.
const boost::optional< Quality > limitQuality
Worst accepted quality.
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)
std::pair< TER, std::vector< Strand > > toStrands(ReadView const &view, AccountID const &src, AccountID const &dst, Issue const &deliver, boost::optional< Quality > const &limitQuality, boost::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)
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
virtual boost::optional< AccountID > directStepSrcAcct() const
If this step is DirectStepI (IOU->IOU direct step), return the src account.
virtual boost::optional< std::pair< AccountID, AccountID > > directStepAccts() const
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.