diff --git a/src/ripple/app/paths/Pathfinder.cpp b/src/ripple/app/paths/Pathfinder.cpp index a912c44a3c..55495a10e8 100644 --- a/src/ripple/app/paths/Pathfinder.cpp +++ b/src/ripple/app/paths/Pathfinder.cpp @@ -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); diff --git a/src/ripple/protocol/STPathSet.h b/src/ripple/protocol/STPathSet.h index 931eeef187..f5acfe1eca 100644 --- a/src/ripple/protocol/STPathSet.h +++ b/src/ripple/protocol/STPathSet.h @@ -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 mPath; };