Order book subscribe cleanups.

This commit is contained in:
JoelKatz
2014-01-08 14:31:00 -08:00
committed by Vinnie Falco
parent 93e03804d0
commit d474d68566
4 changed files with 12 additions and 9 deletions

View File

@@ -210,6 +210,7 @@ BookListeners::pointer OrderBookDB::makeBookListeners (RippleCurrency const& cur
mListeners [RippleBookRef ( mListeners [RippleBookRef (
RippleAssetRef (currencyPays, issuerPays), RippleAssetRef (currencyPays, issuerPays),
RippleAssetRef (currencyGets, issuerGets))] = ret; RippleAssetRef (currencyGets, issuerGets))] = ret;
assert (getBookListeners (currencyPays, currencyGets, issuerPays, issuerGets) == ret);
} }
return ret; return ret;
@@ -228,12 +229,12 @@ BookListeners::pointer OrderBookDB::getBookListeners (RippleCurrency const& curr
if (it0 != mListeners.end ()) if (it0 != mListeners.end ())
ret = it0->second; ret = it0->second;
return ret;; return ret;
} }
// Based on the meta, send the meta to the streams that are listening // Based on the meta, send the meta to the streams that are listening
// We need to determine which streams a given meta effects // We need to determine which streams a given meta effects
void OrderBookDB::processTxn (Ledger::ref ledger, const AcceptedLedgerTx& alTx, Json::Value& jvObj) void OrderBookDB::processTxn (Ledger::ref ledger, const AcceptedLedgerTx& alTx, Json::Value const& jvObj)
{ {
ScopedLockType sl (mLock, __FILE__, __LINE__); ScopedLockType sl (mLock, __FILE__, __LINE__);
@@ -249,6 +250,7 @@ void OrderBookDB::processTxn (Ledger::ref ledger, const AcceptedLedgerTx& alTx,
{ {
SField* field = NULL; SField* field = NULL;
// We need a field that contains the TakerGets and TakerPays parameters
if (node.getFName () == sfModifiedNode) if (node.getFName () == sfModifiedNode)
{ {
field = &sfPreviousFields; field = &sfPreviousFields;
@@ -313,7 +315,7 @@ void BookListeners::removeSubscriber (uint64 seq)
mListeners.erase (seq); mListeners.erase (seq);
} }
void BookListeners::publish (Json::Value& jvObj) void BookListeners::publish (Json::Value const& jvObj)
{ {
Json::FastWriter jfwWriter; Json::FastWriter jfwWriter;
std::string sObj = jfwWriter.write (jvObj); std::string sObj = jfwWriter.write (jvObj);

View File

@@ -29,7 +29,7 @@ public:
BookListeners (); BookListeners ();
void addSubscriber (InfoSub::ref sub); void addSubscriber (InfoSub::ref sub);
void removeSubscriber (uint64 sub); void removeSubscriber (uint64 sub);
void publish (Json::Value& jvObj); void publish (Json::Value const& jvObj);
private: private:
typedef RippleRecursiveMutex LockType; typedef RippleRecursiveMutex LockType;
@@ -73,7 +73,7 @@ public:
RippleIssuer const& issuerPays, RippleIssuer const& issuerGets); RippleIssuer const& issuerPays, RippleIssuer const& issuerGets);
// see if this txn effects any orderbook // see if this txn effects any orderbook
void processTxn (Ledger::ref ledger, const AcceptedLedgerTx& alTx, Json::Value& jvObj); void processTxn (Ledger::ref ledger, const AcceptedLedgerTx& alTx, Json::Value const& jvObj);
private: private:
// by ci/ii // by ci/ii

View File

@@ -2609,6 +2609,7 @@ bool NetworkOPsImp::subBook (InfoSub::ref isrListener, RippleCurrency const& cur
BookListeners::pointer listeners = BookListeners::pointer listeners =
getApp().getOrderBookDB ().makeBookListeners (currencyPays, currencyGets, issuerPays, issuerGets); getApp().getOrderBookDB ().makeBookListeners (currencyPays, currencyGets, issuerPays, issuerGets);
assert (listeners);
if (listeners) if (listeners)
listeners->addSubscriber (isrListener); listeners->addSubscriber (isrListener);

View File

@@ -3530,10 +3530,10 @@ Json::Value RPCHandler::doSubscribe (Json::Value params, Resource::Charge& loadT
|| !jvSubRequest["taker_gets"].isObject ()) || !jvSubRequest["taker_gets"].isObject ())
return rpcError (rpcINVALID_PARAMS); return rpcError (rpcINVALID_PARAMS);
uint160 uTakerPaysCurrencyID; RippleCurrency uTakerPaysCurrencyID;
uint160 uTakerPaysIssuerID; RippleIssuer uTakerPaysIssuerID;
uint160 uTakerGetsCurrencyID; RippleCurrency uTakerGetsCurrencyID;
uint160 uTakerGetsIssuerID; RippleIssuer uTakerGetsIssuerID;
bool bBoth = (jvSubRequest.isMember ("both") && jvSubRequest["both"].asBool ()) bool bBoth = (jvSubRequest.isMember ("both") && jvSubRequest["both"].asBool ())
|| (jvSubRequest.isMember ("both_sides") && jvSubRequest["both_sides"].asBool ()); // DEPRECATED || (jvSubRequest.isMember ("both_sides") && jvSubRequest["both_sides"].asBool ()); // DEPRECATED
bool bSnapshot = (jvSubRequest.isMember ("snapshot") && jvSubRequest["snapshot"].asBool ()) bool bSnapshot = (jvSubRequest.isMember ("snapshot") && jvSubRequest["snapshot"].asBool ())