diff --git a/src/js/ripple/meta.js b/src/js/ripple/meta.js index 05e69c9a..23d40b5c 100644 --- a/src/js/ripple/meta.js +++ b/src/js/ripple/meta.js @@ -25,6 +25,9 @@ function Meta(raw_data) { result.fieldsNew = an.NewFields || {}; result.fieldsFinal = an.FinalFields || {}; + // getAffectedBooks will set this + // result.bookKey = undefined; + self.nodes.push(result); } }); @@ -151,6 +154,11 @@ Meta.prototype.getAffectedBooks = function () { var key = [ getsKey, paysKey ].join(':'); + // Hell of a lot of work, so we are going to cache this. We can use this + // later to good effect in OrderBook.notify to make sure we only process + // pertinent offers. + an.bookKey = key; + books.push(key); }); diff --git a/src/js/ripple/orderbook.js b/src/js/ripple/orderbook.js index aa05418d..d51f3e72 100644 --- a/src/js/ripple/orderbook.js +++ b/src/js/ripple/orderbook.js @@ -15,7 +15,7 @@ var Amount = require('./amount').Amount; var UInt160 = require('./uint160').UInt160; var Currency = require('./currency').Currency; -function OrderBook(remote, currency_gets, issuer_gets, currency_pays, issuer_pays) { +function OrderBook(remote, currency_gets, issuer_gets, currency_pays, issuer_pays, key) { EventEmitter.call(this); var self = this; @@ -26,6 +26,7 @@ function OrderBook(remote, currency_gets, issuer_gets, currency_pays, issuer_pay this._currency_pays = currency_pays; this._issuer_pays = issuer_pays; this._subs = 0; + this._key = key; // We consider ourselves synchronized if we have a current copy of the offers, // we are online and subscribed to updates. @@ -187,7 +188,7 @@ OrderBook.prototype.notify = function (message) { var trade_pays = this.trade('pays'); function handleTransaction(an) { - if (an.entryType !== 'Offer') return; + if (an.entryType !== 'Offer' || an.bookKey !== self._key) return; var i, l, offer; @@ -202,6 +203,8 @@ OrderBook.prototype.notify = function (message) { if (deletedNode) { self._offers.splice(i, 1); } else { + // TODO: This assumes no fields are deleted, which is probably a + // safe assumption, but should be checked. extend(offer, an.fieldsFinal); } changed = true; diff --git a/src/js/ripple/remote.js b/src/js/ripple/remote.js index b961eab8..957eb5fb 100644 --- a/src/js/ripple/remote.js +++ b/src/js/ripple/remote.js @@ -1292,7 +1292,7 @@ Remote.prototype.book = function(currency_gets, issuer_gets, currency_pays, issu var book; if (!this._books.hasOwnProperty(key)) { - book = new OrderBook(this, currency_gets, issuer_gets, currency_pays, issuer_pays); + book = new OrderBook(this, currency_gets, issuer_gets, currency_pays, issuer_pays, key); if (book.is_valid()) { this._books[key] = book; }