rippled
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ripple::Pathfinder Class Reference

Calculates payment paths. More...

Inheritance diagram for ripple::Pathfinder:
Inheritance graph
[legend]
Collaboration diagram for ripple::Pathfinder:
Collaboration graph
[legend]

Classes

struct  PathRank
 

Public Types

enum  NodeType {
  nt_SOURCE, nt_ACCOUNTS, nt_BOOKS, nt_XRP_BOOK,
  nt_DEST_BOOK, nt_DESTINATION
}
 
enum  PaymentType {
  pt_XRP_to_XRP, pt_XRP_to_nonXRP, pt_nonXRP_to_XRP, pt_nonXRP_to_same,
  pt_nonXRP_to_nonXRP
}
 
using PathType = std::vector< NodeType >
 

Public Member Functions

 Pathfinder (std::shared_ptr< RippleLineCache > const &cache, AccountID const &srcAccount, AccountID const &dstAccount, Currency const &uSrcCurrency, std::optional< AccountID > const &uSrcIssuer, STAmount const &dstAmount, std::optional< STAmount > const &srcAmount, Application &app)
 Construct a pathfinder without an issuer. More...
 
 Pathfinder (Pathfinder const &)=delete
 
Pathfinderoperator= (Pathfinder const &)=delete
 
 ~Pathfinder ()=default
 
bool findPaths (int searchLevel, std::function< bool(void)> const &continueCallback={})
 
void computePathRanks (int maxPaths, std::function< bool(void)> const &continueCallback={})
 Compute the rankings of the paths. More...
 
STPathSet getBestPaths (int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer, std::function< bool(void)> const &continueCallback={})
 

Static Public Member Functions

static void initPathTable ()
 

Private Member Functions

STPathSetaddPathsForType (PathType const &type, std::function< bool(void)> const &continueCallback)
 
bool issueMatchesOrigin (Issue const &)
 
int getPathsOut (Currency const &currency, AccountID const &account, LineDirection direction, bool isDestCurrency, AccountID const &dest, std::function< bool(void)> const &continueCallback)
 
void addLink (STPath const &currentPath, STPathSet &incompletePaths, int addFlags, std::function< bool(void)> const &continueCallback)
 
void addLinks (STPathSet const &currentPaths, STPathSet &incompletePaths, int addFlags, std::function< bool(void)> const &continueCallback)
 
TER getPathLiquidity (STPath const &path, STAmount const &minDstAmount, STAmount &amountOut, uint64_t &qualityOut) const
 
bool isNoRippleOut (STPath const &currentPath)
 
bool isNoRipple (AccountID const &fromAccount, AccountID const &toAccount, Currency const &currency)
 
void rankPaths (int maxPaths, STPathSet const &paths, std::vector< PathRank > &rankedPaths, std::function< bool(void)> const &continueCallback)
 

Static Private Member Functions

static auto & getCounter () noexcept
 

Private Attributes

AccountID mSrcAccount
 
AccountID mDstAccount
 
AccountID mEffectiveDst
 
STAmount mDstAmount
 
Currency mSrcCurrency
 
std::optional< AccountIDmSrcIssuer
 
STAmount mSrcAmount
 
STAmount mRemainingAmount
 The amount remaining from mSrcAccount after the default liquidity has been removed. More...
 
bool convert_all_
 
std::shared_ptr< ReadView const > mLedger
 
std::unique_ptr< LoadEventm_loadEvent
 
std::shared_ptr< RippleLineCachemRLCache
 
STPathElement mSource
 
STPathSet mCompletePaths
 
std::vector< PathRankmPathRanks
 
std::map< PathType, STPathSetmPaths
 
hash_map< Issue, int > mPathsOutCountMap
 
Applicationapp_
 
const beast::Journal j_
 

Static Private Attributes

static const std::uint32_t afADD_ACCOUNTS = 0x001
 
static const std::uint32_t afADD_BOOKS = 0x002
 
static const std::uint32_t afOB_XRP = 0x010
 
static const std::uint32_t afOB_LAST = 0x040
 
static const std::uint32_t afAC_LAST = 0x080
 

Detailed Description

Calculates payment paths.

The RippleCalc determines the quality of the found paths.

See also
RippleCalc

Definition at line 38 of file Pathfinder.h.

Member Typedef Documentation

◆ PathType

Definition at line 93 of file Pathfinder.h.

Member Enumeration Documentation

◆ NodeType

Enumerator
nt_SOURCE 
nt_ACCOUNTS 
nt_BOOKS 
nt_XRP_BOOK 
nt_DEST_BOOK 
nt_DESTINATION 

Definition at line 83 of file Pathfinder.h.

◆ PaymentType

Enumerator
pt_XRP_to_XRP 
pt_XRP_to_nonXRP 
pt_nonXRP_to_XRP 
pt_nonXRP_to_same 
pt_nonXRP_to_nonXRP 

Definition at line 97 of file Pathfinder.h.

Constructor & Destructor Documentation

◆ Pathfinder() [1/2]

ripple::Pathfinder::Pathfinder ( std::shared_ptr< RippleLineCache > const &  cache,
AccountID const &  srcAccount,
AccountID const &  dstAccount,
Currency const &  uSrcCurrency,
std::optional< AccountID > const &  uSrcIssuer,
STAmount const &  dstAmount,
std::optional< STAmount > const &  srcAmount,
Application app 
)

Construct a pathfinder without an issuer.

Definition at line 161 of file Pathfinder.cpp.

◆ Pathfinder() [2/2]

ripple::Pathfinder::Pathfinder ( Pathfinder const &  )
delete

◆ ~Pathfinder()

ripple::Pathfinder::~Pathfinder ( )
default

Member Function Documentation

◆ operator=()

Pathfinder& ripple::Pathfinder::operator= ( Pathfinder const &  )
delete

◆ initPathTable()

void ripple::Pathfinder::initPathTable ( )
static

Definition at line 1300 of file Pathfinder.cpp.

◆ findPaths()

bool ripple::Pathfinder::findPaths ( int  searchLevel,
std::function< bool(void)> const &  continueCallback = {} 
)

Definition at line 195 of file Pathfinder.cpp.

◆ computePathRanks()

void ripple::Pathfinder::computePathRanks ( int  maxPaths,
std::function< bool(void)> const &  continueCallback = {} 
)

Compute the rankings of the paths.

Definition at line 411 of file Pathfinder.cpp.

◆ getBestPaths()

STPathSet ripple::Pathfinder::getBestPaths ( int  maxPaths,
STPath fullLiquidityPath,
STPathSet const &  extraPaths,
AccountID const &  srcIssuer,
std::function< bool(void)> const &  continueCallback = {} 
)

Definition at line 567 of file Pathfinder.cpp.

◆ addPathsForType()

STPathSet & ripple::Pathfinder::addPathsForType ( PathType const &  type,
std::function< bool(void)> const &  continueCallback 
)
private

Definition at line 795 of file Pathfinder.cpp.

◆ issueMatchesOrigin()

bool ripple::Pathfinder::issueMatchesOrigin ( Issue const &  issue)
private

Definition at line 697 of file Pathfinder.cpp.

◆ getPathsOut()

int ripple::Pathfinder::getPathsOut ( Currency const &  currency,
AccountID const &  account,
LineDirection  direction,
bool  isDestCurrency,
AccountID const &  dest,
std::function< bool(void)> const &  continueCallback 
)
private

Definition at line 708 of file Pathfinder.cpp.

◆ addLink()

void ripple::Pathfinder::addLink ( STPath const &  currentPath,
STPathSet incompletePaths,
int  addFlags,
std::function< bool(void)> const &  continueCallback 
)
private

Definition at line 937 of file Pathfinder.cpp.

◆ addLinks()

void ripple::Pathfinder::addLinks ( STPathSet const &  currentPaths,
STPathSet incompletePaths,
int  addFlags,
std::function< bool(void)> const &  continueCallback 
)
private

Definition at line 778 of file Pathfinder.cpp.

◆ getPathLiquidity()

TER ripple::Pathfinder::getPathLiquidity ( STPath const &  path,
STAmount const &  minDstAmount,
STAmount amountOut,
uint64_t &  qualityOut 
) const
private

Definition at line 344 of file Pathfinder.cpp.

◆ isNoRippleOut()

bool ripple::Pathfinder::isNoRippleOut ( STPath const &  currentPath)
private

Definition at line 902 of file Pathfinder.cpp.

◆ isNoRipple()

bool ripple::Pathfinder::isNoRipple ( AccountID const &  fromAccount,
AccountID const &  toAccount,
Currency const &  currency 
)
private

Definition at line 885 of file Pathfinder.cpp.

◆ rankPaths()

void ripple::Pathfinder::rankPaths ( int  maxPaths,
STPathSet const &  paths,
std::vector< PathRank > &  rankedPaths,
std::function< bool(void)> const &  continueCallback 
)
private

Definition at line 489 of file Pathfinder.cpp.

◆ getCounter()

static auto& ripple::CountedObject< Pathfinder >::getCounter
staticprivatenoexceptinherited

Definition at line 128 of file CountedObject.h.

Member Data Documentation

◆ mSrcAccount

AccountID ripple::Pathfinder::mSrcAccount
private

Definition at line 196 of file Pathfinder.h.

◆ mDstAccount

AccountID ripple::Pathfinder::mDstAccount
private

Definition at line 197 of file Pathfinder.h.

◆ mEffectiveDst

AccountID ripple::Pathfinder::mEffectiveDst
private

Definition at line 198 of file Pathfinder.h.

◆ mDstAmount

STAmount ripple::Pathfinder::mDstAmount
private

Definition at line 199 of file Pathfinder.h.

◆ mSrcCurrency

Currency ripple::Pathfinder::mSrcCurrency
private

Definition at line 200 of file Pathfinder.h.

◆ mSrcIssuer

std::optional<AccountID> ripple::Pathfinder::mSrcIssuer
private

Definition at line 201 of file Pathfinder.h.

◆ mSrcAmount

STAmount ripple::Pathfinder::mSrcAmount
private

Definition at line 202 of file Pathfinder.h.

◆ mRemainingAmount

STAmount ripple::Pathfinder::mRemainingAmount
private

The amount remaining from mSrcAccount after the default liquidity has been removed.

Definition at line 205 of file Pathfinder.h.

◆ convert_all_

bool ripple::Pathfinder::convert_all_
private

Definition at line 206 of file Pathfinder.h.

◆ mLedger

std::shared_ptr<ReadView const> ripple::Pathfinder::mLedger
private

Definition at line 208 of file Pathfinder.h.

◆ m_loadEvent

std::unique_ptr<LoadEvent> ripple::Pathfinder::m_loadEvent
private

Definition at line 209 of file Pathfinder.h.

◆ mRLCache

std::shared_ptr<RippleLineCache> ripple::Pathfinder::mRLCache
private

Definition at line 210 of file Pathfinder.h.

◆ mSource

STPathElement ripple::Pathfinder::mSource
private

Definition at line 212 of file Pathfinder.h.

◆ mCompletePaths

STPathSet ripple::Pathfinder::mCompletePaths
private

Definition at line 213 of file Pathfinder.h.

◆ mPathRanks

std::vector<PathRank> ripple::Pathfinder::mPathRanks
private

Definition at line 214 of file Pathfinder.h.

◆ mPaths

std::map<PathType, STPathSet> ripple::Pathfinder::mPaths
private

Definition at line 215 of file Pathfinder.h.

◆ mPathsOutCountMap

hash_map<Issue, int> ripple::Pathfinder::mPathsOutCountMap
private

Definition at line 217 of file Pathfinder.h.

◆ app_

Application& ripple::Pathfinder::app_
private

Definition at line 219 of file Pathfinder.h.

◆ j_

const beast::Journal ripple::Pathfinder::j_
private

Definition at line 220 of file Pathfinder.h.

◆ afADD_ACCOUNTS

const std::uint32_t ripple::Pathfinder::afADD_ACCOUNTS = 0x001
staticprivate

Definition at line 223 of file Pathfinder.h.

◆ afADD_BOOKS

const std::uint32_t ripple::Pathfinder::afADD_BOOKS = 0x002
staticprivate

Definition at line 226 of file Pathfinder.h.

◆ afOB_XRP

const std::uint32_t ripple::Pathfinder::afOB_XRP = 0x010
staticprivate

Definition at line 229 of file Pathfinder.h.

◆ afOB_LAST

const std::uint32_t ripple::Pathfinder::afOB_LAST = 0x040
staticprivate

Definition at line 232 of file Pathfinder.h.

◆ afAC_LAST

const std::uint32_t ripple::Pathfinder::afAC_LAST = 0x080
staticprivate

Definition at line 235 of file Pathfinder.h.