mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Fix order book scaning for path finding.
This commit is contained in:
@@ -1,28 +1,42 @@
|
||||
#include "OrderBookDB.h"
|
||||
#include "Log.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include "OrderBookDB.h"
|
||||
#include "Log.h"
|
||||
|
||||
SETUP_LOG();
|
||||
|
||||
// TODO: this would be way faster if we could just look under the order dirs
|
||||
OrderBookDB::OrderBookDB(Ledger::pointer ledger)
|
||||
{
|
||||
// walk through the entire ledger looking for orderbook entries
|
||||
uint256 currentIndex=ledger->getFirstLedgerIndex();
|
||||
while(currentIndex.isNonZero())
|
||||
uint256 currentIndex = ledger->getFirstLedgerIndex();
|
||||
|
||||
cLog(lsDEBUG) << "OrderBookDB>";
|
||||
|
||||
while (currentIndex.isNonZero())
|
||||
{
|
||||
SLE::pointer entry=ledger->getSLE(currentIndex);
|
||||
|
||||
OrderBook::pointer book=OrderBook::newOrderBook(entry);
|
||||
if(book)
|
||||
OrderBook::pointer book = OrderBook::newOrderBook(entry);
|
||||
if (book)
|
||||
{
|
||||
if( mKnownMap.find(book->getBookBase()) != mKnownMap.end() )
|
||||
{
|
||||
mKnownMap[book->getBookBase()]=true;
|
||||
cLog(lsDEBUG) << "OrderBookDB: found book";
|
||||
|
||||
if(!book->getCurrencyIn())
|
||||
{ // XRP
|
||||
if (mKnownMap.find(book->getBookBase()) == mKnownMap.end())
|
||||
{
|
||||
mKnownMap[book->getBookBase()] = true;
|
||||
|
||||
cLog(lsDEBUG) << "OrderBookDB: unknown book in: "
|
||||
<< STAmount::createHumanCurrency(book->getCurrencyIn())
|
||||
<< " -> "
|
||||
<< STAmount::createHumanCurrency(book->getCurrencyOut());
|
||||
|
||||
if (!book->getCurrencyIn())
|
||||
{
|
||||
// XRP
|
||||
mXRPOrders.push_back(book);
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
mIssuerMap[book->getIssuerIn()].push_back(book);
|
||||
}
|
||||
@@ -31,26 +45,29 @@ OrderBookDB::OrderBookDB(Ledger::pointer ledger)
|
||||
|
||||
currentIndex=ledger->getNextLedgerIndex(currentIndex);
|
||||
}
|
||||
|
||||
cLog(lsDEBUG) << "OrderBookDB<";
|
||||
}
|
||||
|
||||
// return list of all orderbooks that want IssuerID
|
||||
std::vector<OrderBook::pointer>& OrderBookDB::getBooks(const uint160& issuerID)
|
||||
{
|
||||
if( mIssuerMap.find(issuerID) == mIssuerMap.end() ) return mEmptyVector;
|
||||
else return( mIssuerMap[issuerID]);
|
||||
return mIssuerMap.find(issuerID) == mIssuerMap.end()
|
||||
? mEmptyVector
|
||||
: mIssuerMap[issuerID];
|
||||
}
|
||||
|
||||
// return list of all orderbooks that want this issuerID and currencyID
|
||||
void OrderBookDB::getBooks(const uint160& issuerID, const uint160& currencyID, std::vector<OrderBook::pointer>& bookRet)
|
||||
{
|
||||
if( mIssuerMap.find(issuerID) == mIssuerMap.end() )
|
||||
if (mIssuerMap.find(issuerID) == mIssuerMap.end())
|
||||
{
|
||||
BOOST_FOREACH(OrderBook::ref book, mIssuerMap[issuerID])
|
||||
{
|
||||
if(book->getCurrencyIn()==currencyID)
|
||||
{
|
||||
if (book->getCurrencyIn() == currencyID)
|
||||
bookRet.push_back(book);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
Reference in New Issue
Block a user