mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Merge pull request #60 from sublimator/develop
Proposed fix for #51 and #57
This commit is contained in:
@@ -25,6 +25,9 @@ function Meta(raw_data) {
|
|||||||
result.fieldsNew = an.NewFields || {};
|
result.fieldsNew = an.NewFields || {};
|
||||||
result.fieldsFinal = an.FinalFields || {};
|
result.fieldsFinal = an.FinalFields || {};
|
||||||
|
|
||||||
|
// getAffectedBooks will set this
|
||||||
|
// result.bookKey = undefined;
|
||||||
|
|
||||||
self.nodes.push(result);
|
self.nodes.push(result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -151,6 +154,11 @@ Meta.prototype.getAffectedBooks = function () {
|
|||||||
|
|
||||||
var key = [ getsKey, paysKey ].join(':');
|
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);
|
books.push(key);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ var Amount = require('./amount').Amount;
|
|||||||
var UInt160 = require('./uint160').UInt160;
|
var UInt160 = require('./uint160').UInt160;
|
||||||
var Currency = require('./currency').Currency;
|
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);
|
EventEmitter.call(this);
|
||||||
|
|
||||||
var self = 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._currency_pays = currency_pays;
|
||||||
this._issuer_pays = issuer_pays;
|
this._issuer_pays = issuer_pays;
|
||||||
this._subs = 0;
|
this._subs = 0;
|
||||||
|
this._key = key;
|
||||||
|
|
||||||
// We consider ourselves synchronized if we have a current copy of the offers,
|
// We consider ourselves synchronized if we have a current copy of the offers,
|
||||||
// we are online and subscribed to updates.
|
// we are online and subscribed to updates.
|
||||||
@@ -187,7 +188,7 @@ OrderBook.prototype.notify = function (message) {
|
|||||||
var trade_pays = this.trade('pays');
|
var trade_pays = this.trade('pays');
|
||||||
|
|
||||||
function handleTransaction(an) {
|
function handleTransaction(an) {
|
||||||
if (an.entryType !== 'Offer') return;
|
if (an.entryType !== 'Offer' || an.bookKey !== self._key) return;
|
||||||
|
|
||||||
var i, l, offer;
|
var i, l, offer;
|
||||||
|
|
||||||
@@ -202,6 +203,8 @@ OrderBook.prototype.notify = function (message) {
|
|||||||
if (deletedNode) {
|
if (deletedNode) {
|
||||||
self._offers.splice(i, 1);
|
self._offers.splice(i, 1);
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: This assumes no fields are deleted, which is probably a
|
||||||
|
// safe assumption, but should be checked.
|
||||||
extend(offer, an.fieldsFinal);
|
extend(offer, an.fieldsFinal);
|
||||||
}
|
}
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|||||||
@@ -1292,7 +1292,7 @@ Remote.prototype.book = function(currency_gets, issuer_gets, currency_pays, issu
|
|||||||
var book;
|
var book;
|
||||||
|
|
||||||
if (!this._books.hasOwnProperty(key)) {
|
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()) {
|
if (book.is_valid()) {
|
||||||
this._books[key] = book;
|
this._books[key] = book;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user