rippled
Public Member Functions | Private Member Functions | Friends | List of all members
ripple::Step Class Referenceabstract

A step in a payment path. More...

Public Member Functions

virtual ~Step ()=default
 
virtual std::pair< EitherAmount, EitherAmountrev (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. More...
 
virtual std::pair< EitherAmount, EitherAmountfwd (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. More...
 
virtual std::optional< EitherAmountcachedIn () const =0
 Amount of currency computed coming into the Step the last time the step ran in reverse. More...
 
virtual std::optional< EitherAmountcachedOut () const =0
 Amount of currency computed coming out of the Step the last time the step ran in reverse. More...
 
virtual std::optional< AccountIDdirectStepSrcAcct () const
 If this step is DirectStepI (IOU->IOU direct step), return the src account. More...
 
virtual std::optional< std::pair< AccountID, AccountID > > directStepAccts () const
 
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. More...
 
virtual std::uint32_t lineQualityIn (ReadView const &) const
 If this step is a DirectStepI, return the quality in of the dst account. More...
 
virtual std::pair< std::optional< Quality >, DebtDirectionqualityUpperBound (ReadView const &v, DebtDirection prevStepDir) const =0
 Find an upper bound of quality for the step. More...
 
virtual std::uint32_t offersUsed () const
 Return the number of offers consumed or partially consumed the last time the step ran, including expired and unfunded offers. More...
 
virtual std::optional< BookbookStepBook () const
 If this step is a BookStep, return the book. More...
 
virtual bool isZero (EitherAmount const &out) const =0
 Check if amount is zero. More...
 
virtual bool inactive () const
 Return true if the step should be considered inactive. More...
 
virtual bool equalOut (EitherAmount const &lhs, EitherAmount const &rhs) const =0
 Return true if Out of lhs == Out of rhs. More...
 
virtual bool equalIn (EitherAmount const &lhs, EitherAmount const &rhs) const =0
 Return true if In of lhs == In of rhs. More...
 
virtual std::pair< bool, EitherAmountvalidFwd (PaymentSandbox &sb, ApplyView &afView, EitherAmount const &in)=0
 Check that the step can correctly execute in the forward direction. More...
 

Private Member Functions

virtual std::string logString () const =0
 
virtual bool equal (Step const &rhs) const =0
 

Friends

bool operator== (Step const &lhs, Step const &rhs)
 Return true if lhs == rhs. More...
 
bool operator!= (Step const &lhs, Step const &rhs)
 Return true if lhs != rhs. More...
 
std::ostreamoperator<< (std::ostream &stream, Step const &step)
 Streaming operator for a Step. More...
 

Detailed Description

A step in a payment path.

There are five concrete step classes: DirectStepI is an IOU step between accounts BookStepII is an IOU/IOU offer book BookStepIX is an IOU/XRP offer book BookStepXI is an XRP/IOU offer book XRPEndpointStep is the source or destination account for XRP

Amounts may be transformed through a step in either the forward or the reverse direction. In the forward direction, the function fwd is used to find the amount the step would output given an input amount. In the reverse direction, the function rev is used to find the amount of input needed to produce the desired output.

Amounts are always transformed using liquidity with the same quality (quality is the amount out/amount in). For example, a BookStep may use multiple offers when executing fwd or rev, but all those offers will be from the same quality directory.

A step may not have enough liquidity to transform the entire requested amount. Both fwd and rev return a pair of amounts (one for input amount, one for output amount) that show how much of the requested amount the step was actually able to use.

Definition at line 79 of file Steps.h.

Constructor & Destructor Documentation

◆ ~Step()

virtual ripple::Step::~Step ( )
virtualdefault

Member Function Documentation

◆ rev()

virtual std::pair<EitherAmount, EitherAmount> ripple::Step::rev ( PaymentSandbox sb,
ApplyView afView,
boost::container::flat_set< uint256 > &  ofrsToRm,
EitherAmount const &  out 
)
pure virtual

Find the amount we need to put into the step to get the requested out subject to liquidity limits.

Parameters
sbview with the strand's state of balances and offers
afViewview the the state of balances before the strand runs this determines if an offer becomes unfunded or is found unfunded
ofrsToRmoffers found unfunded or in an error state are added to this collection
outrequested step output
Returns
actual step input and output

◆ fwd()

virtual std::pair<EitherAmount, EitherAmount> ripple::Step::fwd ( PaymentSandbox sb,
ApplyView afView,
boost::container::flat_set< uint256 > &  ofrsToRm,
EitherAmount const &  in 
)
pure virtual

Find the amount we get out of the step given the input subject to liquidity limits.

Parameters
sbview with the strand's state of balances and offers
afViewview the the state of balances before the strand runs this determines if an offer becomes unfunded or is found unfunded
ofrsToRmoffers found unfunded or in an error state are added to this collection
inrequested step input
Returns
actual step input and output

◆ cachedIn()

virtual std::optional<EitherAmount> ripple::Step::cachedIn ( ) const
pure virtual

Amount of currency computed coming into the Step the last time the step ran in reverse.

◆ cachedOut()

virtual std::optional<EitherAmount> ripple::Step::cachedOut ( ) const
pure virtual

Amount of currency computed coming out of the Step the last time the step ran in reverse.

◆ directStepSrcAcct()

virtual std::optional<AccountID> ripple::Step::directStepSrcAcct ( ) const
virtual

If this step is DirectStepI (IOU->IOU direct step), return the src account.

This is needed for checkNoRipple.

Definition at line 139 of file Steps.h.

◆ directStepAccts()

virtual std::optional<std::pair<AccountID, AccountID> > ripple::Step::directStepAccts ( ) const
virtual

Definition at line 147 of file Steps.h.

◆ debtDirection()

virtual DebtDirection ripple::Step::debtDirection ( ReadView const &  sb,
StrandDirection  dir 
) const
pure virtual

If this step is a DirectStepI and the src redeems to the dst, return true, otherwise return false.

If this step is a BookStep, return false if the owner pays the transfer fee, otherwise return true.

Parameters
sbview with the strand's state of balances and offers
dirreverse -> called from rev(); forward -> called from fwd().

◆ lineQualityIn()

virtual std::uint32_t ripple::Step::lineQualityIn ( ReadView const &  ) const
virtual

If this step is a DirectStepI, return the quality in of the dst account.

Definition at line 167 of file Steps.h.

◆ qualityUpperBound()

virtual std::pair<std::optional<Quality>, DebtDirection> ripple::Step::qualityUpperBound ( ReadView const &  v,
DebtDirection  prevStepDir 
) const
pure virtual

Find an upper bound of quality for the step.

Parameters
vview to query the ledger state from
prevStepDirSet to DebtDirection::redeems if the previous step redeems.
Returns
A pair. The first element is the upper bound of quality for the step, or std::nullopt if the step is dry. The second element will be set to DebtDirection::redeems if this steps redeems, DebtDirection:issues if this step issues.
Note
it is an upper bound because offers on the books may be unfunded. If there is always a funded offer at the tip of the book, then we could rename this theoreticalQuality rather than qualityUpperBound. It could still differ from the actual quality, but except for "dust" amounts, it should be a good estimate for the actual quality.

◆ offersUsed()

virtual std::uint32_t ripple::Step::offersUsed ( ) const
virtual

Return the number of offers consumed or partially consumed the last time the step ran, including expired and unfunded offers.

N.B. This this not the total number offers consumed by this step for the entire payment, it is only the number the last time it ran. Offers may be partially consumed multiple times during a payment.

Definition at line 199 of file Steps.h.

◆ bookStepBook()

virtual std::optional<Book> ripple::Step::bookStepBook ( ) const
virtual

If this step is a BookStep, return the book.

Definition at line 208 of file Steps.h.

◆ isZero()

virtual bool ripple::Step::isZero ( EitherAmount const &  out) const
pure virtual

Check if amount is zero.

◆ inactive()

virtual bool ripple::Step::inactive ( ) const
virtual

Return true if the step should be considered inactive.

A strand that has additional liquidity may be marked inactive if a step has consumed too many offers.

Definition at line 225 of file Steps.h.

◆ equalOut()

virtual bool ripple::Step::equalOut ( EitherAmount const &  lhs,
EitherAmount const &  rhs 
) const
pure virtual

Return true if Out of lhs == Out of rhs.

◆ equalIn()

virtual bool ripple::Step::equalIn ( EitherAmount const &  lhs,
EitherAmount const &  rhs 
) const
pure virtual

Return true if In of lhs == In of rhs.

◆ validFwd()

virtual std::pair<bool, EitherAmount> ripple::Step::validFwd ( PaymentSandbox sb,
ApplyView afView,
EitherAmount const &  in 
)
pure virtual

Check that the step can correctly execute in the forward direction.

Parameters
sbview with the strands state of balances and offers
afViewview the the state of balances before the strand runs this determines if an offer becomes unfunded or is found unfunded
inrequested step input
Returns
first element is true if step is valid, second element is out amount

◆ logString()

virtual std::string ripple::Step::logString ( ) const
privatepure virtual

◆ equal()

virtual bool ripple::Step::equal ( Step const &  rhs) const
privatepure virtual

Friends And Related Function Documentation

◆ operator==

bool operator== ( Step const &  lhs,
Step const &  rhs 
)
friend

Return true if lhs == rhs.

Parameters
lhsStep to compare.
rhsStep to compare.
Returns
true if lhs == rhs.

Definition at line 262 of file Steps.h.

◆ operator!=

bool operator!= ( Step const &  lhs,
Step const &  rhs 
)
friend

Return true if lhs != rhs.

Parameters
lhsStep to compare.
rhsStep to compare.
Returns
true if lhs != rhs.

Definition at line 274 of file Steps.h.

◆ operator<<

std::ostream& operator<< ( std::ostream stream,
Step const &  step 
)
friend

Streaming operator for a Step.

Definition at line 281 of file Steps.h.