Cleanups needed to support new code.

This commit is contained in:
JoelKatz
2013-03-14 18:46:52 -07:00
parent be932de252
commit 0baccf10b0
3 changed files with 44 additions and 100 deletions

View File

@@ -17,7 +17,6 @@ void OrderBookDB::invalidate()
mSeq = 0;
}
// TODO: this would be way faster if we could just look under the order dirs
void OrderBookDB::setup(Ledger::ref ledger)
{
boost::unordered_set<uint256> mSeen;
@@ -30,14 +29,13 @@ void OrderBookDB::setup(Ledger::ref ledger)
LoadEvent::autoptr ev = theApp->getJobQueue().getLoadEventAP(jtOB_SETUP, "OrderBookDB::setup");
mXRPOrders.clear();
mIssuerMap.clear();
// walk through the entire ledger looking for orderbook entries
uint256 currentIndex = ledger->getFirstLedgerIndex();
mDestMap.clear();
mSourceMap.clear();
cLog(lsDEBUG) << "OrderBookDB>";
// walk through the entire ledger looking for orderbook entries
uint256 currentIndex = ledger->getFirstLedgerIndex();
while (currentIndex.isNonZero())
{
SLE::pointer entry = ledger->getSLEi(currentIndex);
@@ -55,10 +53,8 @@ void OrderBookDB::setup(Ledger::ref ledger)
OrderBook::pointer book = boost::make_shared<OrderBook>(boost::cref(index),
boost::cref(ci), boost::cref(co), boost::cref(ii), boost::cref(io));
if (!book->getCurrencyIn()) // XRP
mXRPOrders.push_back(book);
else
mIssuerMap[book->getIssuerIn()].push_back(book);
mSourceMap[currencyIssuer_t(ci, ii)].push_back(book);
mDestMap[currencyIssuer_t(co, io)].push_back(book);
}
}
@@ -68,29 +64,31 @@ void OrderBookDB::setup(Ledger::ref ledger)
cLog(lsDEBUG) << "OrderBookDB<";
}
// return list of all orderbooks that want IssuerID
std::vector<OrderBook::pointer>& OrderBookDB::getBooks(const uint160& issuerID)
// return list of all orderbooks that want this issuerID and currencyID
void OrderBookDB::getBooksByTakerPays(const uint160& issuerID, const uint160& currencyID,
std::vector<OrderBook::pointer>& bookRet)
{
boost::recursive_mutex::scoped_lock sl(mLock);
boost::unordered_map< uint160, std::vector<OrderBook::pointer> >::iterator it = mIssuerMap.find(issuerID);
return (it == mIssuerMap.end())
? mEmptyVector
: it->second;
boost::unordered_map< currencyIssuer_t, std::vector<OrderBook::pointer> >::const_iterator
it = mSourceMap.find(currencyIssuer_t(currencyID, issuerID));
if (it != mSourceMap.end())
bookRet = it->second;
else
bookRet.clear();
cLog(lsINFO) << "gbTP: " << currencyID << " : " << issuerID << " : " << bookRet.size();
}
// 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)
// return list of all orderbooks that give this issuerID and currencyID
void OrderBookDB::getBooksByTakerGets(const uint160& issuerID, const uint160& currencyID,
std::vector<OrderBook::pointer>& bookRet)
{
boost::recursive_mutex::scoped_lock sl(mLock);
boost::unordered_map< uint160, std::vector<OrderBook::pointer> >::iterator it = mIssuerMap.find(issuerID);
if (it != mIssuerMap.end())
{
BOOST_FOREACH(OrderBook::ref book, it->second)
{
if (book->getCurrencyIn() == currencyID)
bookRet.push_back(book);
}
}
boost::unordered_map< currencyIssuer_t, std::vector<OrderBook::pointer> >::const_iterator
it = mDestMap.find(currencyIssuer_t(currencyID, issuerID));
if (it != mDestMap.end())
bookRet = it->second;
else bookRet.clear();
}
BookListeners::pointer OrderBookDB::makeBookListeners(const uint160& currencyPays, const uint160& currencyGets,
@@ -133,53 +131,6 @@ BookListeners::pointer OrderBookDB::getBookListeners(const uint160& currencyPays
return (*it3).second;
}
/*
"CreatedNode" : {
"LedgerEntryType" : "Offer",
"LedgerIndex" : "F353BF8A7DCE35EA2985596F4C8421E30EF3B9A21618566BFE0ED00B62A8A5AB",
"NewFields" : {
"Account" : "rB5TihdPbKgMrkFqrqUC3yLdE8hhv4BdeY",
"BookDirectory" : "FF26BE244767D0EA9EFD523941439009E4185E4CBB918F714C08E1BC9BF04000",
"Sequence" : 112,
"TakerGets" : "400000000",
"TakerPays" : {
"currency" : "BTC",
"issuer" : "r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV",
"value" : "1"
}
}
}
"ModifiedNode" : {
"FinalFields" : {
"Account" : "rHTxKLzRbniScyQFGMb3NodmxA848W8dKM",
"BookDirectory" : "407AF8FFDE71114B1981574FDDA9B0334572D56FC579735B4B0BD7A625405555",
"BookNode" : "0000000000000000",
"Flags" : 0,
"OwnerNode" : "0000000000000000",
"Sequence" : 32,
"TakerGets" : "149900000000",
"TakerPays" : {
"currency" : "USD",
"issuer" : "r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X",
"value" : "49.96666666666667"
}
},
"LedgerEntryType" : "Offer",
"LedgerIndex" : "C60F8CC514208FA5F7BD03CF1B64B38B7183CD52318FCBBD3726350D4FE693B0",
"PreviousFields" : {
"TakerGets" : "150000000000",
"TakerPays" : {
"currency" : "USD",
"issuer" : "r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X",
"value" : "50"
}
},
"PreviousTxnID" : "1A6AAE3F1AC5A8A7554A5ABC395D17FED5BF62CD90181AA8E4315EDFED4EDEB3",
"PreviousTxnLgrSeq" : 140734
}
*/
// Based on the meta, send the meta to the streams that are listening
// We need to determine which streams a given meta effects
void OrderBookDB::processTxn(Ledger::ref ledger, const ALTransaction& alTx, Json::Value& jvObj)