When pathfinding, don't output a redundant account node

This commit is contained in:
JoelKatz
2014-10-28 11:34:27 -07:00
committed by Nik Bougalis
parent c6c8e5d70c
commit 0a3e1af04c
2 changed files with 34 additions and 13 deletions

View File

@@ -1086,20 +1086,31 @@ void Pathfinder::addLink (
book->getIssuerOut (),
book->getCurrencyOut (),
book->getIssuerOut ()))
{ // Don't want the book if we've already seen the issuer
// add the order book itself
newPath.emplace_back (
STPathElement::typeCurrency |
STPathElement::typeIssuer,
xrpAccount (),
book->getCurrencyOut (),
book->getIssuerOut ());
if (book->getIssuerOut () == mDstAccount &&
book->getCurrencyOut () == mDstAmount.getCurrency())
{
// Don't want the book if we've already seen the issuer
// book -> account -> book
if ((newPath.size() >= 2) &&
(newPath.back().isAccount ()) &&
(newPath[newPath.size() - 2].isOffer ()))
{
// with the destination account, this path is
// complete
// replace the redundant account with the order book
newPath[newPath.size() - 1] = STPathElement (
STPathElement::typeCurrency | STPathElement::typeIssuer,
xrpAccount(), book->getCurrencyOut(),
book->getIssuerOut());
}
else
{
// add the order book
newPath.emplace_back(
STPathElement::typeCurrency | STPathElement::typeIssuer,
xrpAccount(), book->getCurrencyOut(),
book->getIssuerOut());
}
if (book->getIssuerOut() == mDstAccount &&
book->getCurrencyOut() == mDstAmount.getCurrency())
{ // with the destination account, this path is complete
WriteLog (lsTRACE, Pathfinder)
<< "complete path found ba: "
<< currentPath.getJson(0);

View File

@@ -195,6 +195,16 @@ public:
return mPath.front ();
}
STPathElement& operator[](int i)
{
return mPath[i];
}
const STPathElement& operator[](int i) const
{
return mPath[i];
}
private:
std::vector<STPathElement> mPath;
};