put back UInt160 in AutobridgeCalculator

fix lint issues
This commit is contained in:
Ivan Tivonenko
2015-09-24 20:12:51 +03:00
parent 0d6dda579f
commit 45db95da79
3 changed files with 21 additions and 22 deletions

View File

@@ -3,6 +3,7 @@
const _ = require('lodash');
const assert = require('assert');
const Amount = require('./amount').Amount;
const UInt160 = require('./uint160').UInt160;
const Utils = require('./orderbookutils');
function assertValidNumber(number, message) {
@@ -42,8 +43,6 @@ const NULL_AMOUNT = Utils.normalizeAmount('0');
*/
AutobridgeCalculator.prototype.calculate = function(callback) {
this._oldMode = Amount.strict_mode;
Amount.strict_mode = false;
const legOnePointer = 0;
const legTwoPointer = 0;
@@ -60,6 +59,12 @@ AutobridgeCalculator.prototype._calculateInternal = function(
legOnePointer_, legTwoPointer_, offersAutobridged, callback
) {
// Amount class is calling _check_limits after each operation in strict mode,
// and _check_limits is very computationally expensive, so we turning it off
// whle doing calculations
this._oldMode = Amount.strict_mode;
Amount.strict_mode = false;
let legOnePointer = legOnePointer_;
let legTwoPointer = legTwoPointer_;
@@ -70,12 +75,8 @@ AutobridgeCalculator.prototype._calculateInternal = function(
// of execution so user's browser stays responsive
const lasted = (Date.now() - startTime);
if (lasted > 30) {
setTimeout(() => {
this._oldMode = Amount.strict_mode;
Amount.strict_mode = false;
this._calculateInternal(legOnePointer, legTwoPointer, offersAutobridged,
callback);
}, 0);
setTimeout(this._calculateInternal.bind(this, legOnePointer,
legTwoPointer, offersAutobridged, callback), 0);
Amount.strict_mode = this._oldMode;
return;

View File

@@ -88,7 +88,7 @@ function OrderBook(remote,
this._gotOffersFromLegTwo = false;
this._waitingForOffers = false;
this._offersModifiedAt = 0;
this._lastUpdateLedgerSequence = 0;
this._transactionsLeft = 0;
this._calculatorRunning = false;
@@ -839,29 +839,29 @@ OrderBook.prototype.isBalanceChangeNode = function(node) {
OrderBook.prototype._canRunAutobridgeCalc = function(): boolean {
return !this._calculatorRunning;
}
};
OrderBook.prototype.onTransaction = function(transaction) {
this.updateFundedAmounts(transaction);
if (--this._transactionsLeft === 0 && !this._waitingForOffers) {
const lastClosedLedger = this._remote.getLedgerSequence() - 1;
const lastClosedLedger = this._remote.getLedgerSequence();
if (this._isAutobridgeable) {
if (this._canRunAutobridgeCalc()) {
if (this._legOneBook._offersModifiedAt === lastClosedLedger ||
this._legTwoBook._offersModifiedAt === lastClosedLedger
if (this._legOneBook._lastUpdateLedgerSequence === lastClosedLedger ||
this._legTwoBook._lastUpdateLedgerSequence === lastClosedLedger
) {
this.computeAutobridgedOffersWrapper();
} else if (this._offersModifiedAt === lastClosedLedger) {
} else if (this._lastUpdateLedgerSequence === lastClosedLedger) {
this.mergeDirectAndAutobridgedBooks();
}
}
} else if (this._offersModifiedAt === lastClosedLedger) {
} else if (this._lastUpdateLedgerSequence === lastClosedLedger) {
this.emit('model', this._offers);
}
}
}
};
/**
* Updates funded amounts/balances using modified balance nodes
@@ -978,7 +978,7 @@ OrderBook.prototype.onLedgerClosed = function(message) {
return;
}
this._transactionsLeft = message.txn_count;
}
};
/**
* Notify orderbook of a relevant transaction
@@ -1080,7 +1080,7 @@ OrderBook.prototype.notify = function(transaction) {
this.emit('transaction', transaction);
this._offersModifiedAt = this._remote.getLedgerSequence() - 1;
this._lastUpdateLedgerSequence = this._remote.getLedgerSequence();
if (!takerGetsTotal.is_zero()) {
this.emit('trade', takerPaysTotal, takerGetsTotal);
@@ -1384,8 +1384,6 @@ OrderBook.prototype.computeAutobridgedOffers = function(callback = function() {}
this._issuerPays
);
const lastClosedLedger = this._remote.getLedgerSequence() - 1;
autobridgeCalculator.calculate((autobridgedOffers) => {
this._offersAutobridged = autobridgedOffers;
callback();