Merge pull request #60 from sublimator/develop

Proposed fix for #51 and #57
This commit is contained in:
wltsmrz
2014-02-27 12:14:16 -08:00
3 changed files with 14 additions and 3 deletions

View File

@@ -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);
});

View File

@@ -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;

View File

@@ -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;
}