diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index e741e75fa7..d58d951dab 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -714,7 +714,7 @@ boost::unordered_set usAccountSourceCurrencies(const RippleAddress& raA BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems()) { RippleState* rspEntry = (RippleState*) item.get(); - STAmount saBalance = rspEntry->getBalance(); + const STAmount& saBalance = rspEntry->getBalance(); // Filter out non if (saBalance.isPositive() // Have IOUs to send. @@ -729,6 +729,30 @@ boost::unordered_set usAccountSourceCurrencies(const RippleAddress& raA return usCurrencies; } +boost::unordered_set usAccountDestCurrencies(const RippleAddress& raAccountID, Ledger::ref lrLedger, + bool includeXRP) +{ + boost::unordered_set usCurrencies; + + if (includeXRP) + usCurrencies.insert(uint160(CURRENCY_XRP)); // Even if account doesn't exist + + // List of ripple lines. + AccountItems rippleLines(raAccountID.getAccountID(), lrLedger, AccountItem::pointer(new RippleState())); + + BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems()) + { + RippleState* rspEntry = (RippleState*) item.get(); + const STAmount& saBalance = rspEntry->getBalance(); + + if (saBalance < rspEntry->getLimit()) // Can take more + usCurrencies.insert(saBalance.getCurrency()); + } + + usCurrencies.erase(CURRENCY_BAD); + return usCurrencies; +} + AccountItems& Pathfinder::getRippleLines(const uint160& accountID) { boost::unordered_map::iterator it = mRLMap.find(accountID); diff --git a/src/cpp/ripple/Pathfinder.h b/src/cpp/ripple/Pathfinder.h index 1f723f562f..acc5e5a7d9 100644 --- a/src/cpp/ripple/Pathfinder.h +++ b/src/cpp/ripple/Pathfinder.h @@ -78,8 +78,12 @@ public: bool bDefaultPath(const STPath& spPath); }; +boost::unordered_set usAccountDestCurrencies(const RippleAddress& raAccountID, Ledger::ref lrLedger, + bool includeXRP); + boost::unordered_set usAccountSourceCurrencies(const RippleAddress& raAccountID, Ledger::ref lrLedger, bool includeXRP); + #endif // vim:ts=4 diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 70eeefd6dd..a649e11848 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1234,6 +1234,15 @@ Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest, int& cost) ScopedUnlock su(theApp->getMasterLock()); // As long as we have a locked copy of the ledger, we can unlock. + // Fill in currencies destination will accept + Json::Value jvDestCur(Json::arrayValue); + + boost::unordered_set usDestCurrID = usAccountDestCurrencies(raDst, lpLedger, true); + BOOST_FOREACH(const uint160& uCurrency, usDestCurrID) + jvDestCur.append(STAmount::createHumanCurrency(uCurrency)); + + jvResult["destination_currencies"] = jvDestCur; + Json::Value jvArray(Json::arrayValue); for (unsigned int i=0; i != jvSrcCurrencies.size(); ++i) {