mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
put back UInt160 in AutobridgeCalculator
fix lint issues
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const Amount = require('./amount').Amount;
|
const Amount = require('./amount').Amount;
|
||||||
|
const UInt160 = require('./uint160').UInt160;
|
||||||
const Utils = require('./orderbookutils');
|
const Utils = require('./orderbookutils');
|
||||||
|
|
||||||
function assertValidNumber(number, message) {
|
function assertValidNumber(number, message) {
|
||||||
@@ -42,8 +43,6 @@ const NULL_AMOUNT = Utils.normalizeAmount('0');
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
AutobridgeCalculator.prototype.calculate = function(callback) {
|
AutobridgeCalculator.prototype.calculate = function(callback) {
|
||||||
this._oldMode = Amount.strict_mode;
|
|
||||||
Amount.strict_mode = false;
|
|
||||||
|
|
||||||
const legOnePointer = 0;
|
const legOnePointer = 0;
|
||||||
const legTwoPointer = 0;
|
const legTwoPointer = 0;
|
||||||
@@ -60,6 +59,12 @@ AutobridgeCalculator.prototype._calculateInternal = function(
|
|||||||
legOnePointer_, legTwoPointer_, offersAutobridged, callback
|
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 legOnePointer = legOnePointer_;
|
||||||
let legTwoPointer = legTwoPointer_;
|
let legTwoPointer = legTwoPointer_;
|
||||||
|
|
||||||
@@ -70,12 +75,8 @@ AutobridgeCalculator.prototype._calculateInternal = function(
|
|||||||
// of execution so user's browser stays responsive
|
// of execution so user's browser stays responsive
|
||||||
const lasted = (Date.now() - startTime);
|
const lasted = (Date.now() - startTime);
|
||||||
if (lasted > 30) {
|
if (lasted > 30) {
|
||||||
setTimeout(() => {
|
setTimeout(this._calculateInternal.bind(this, legOnePointer,
|
||||||
this._oldMode = Amount.strict_mode;
|
legTwoPointer, offersAutobridged, callback), 0);
|
||||||
Amount.strict_mode = false;
|
|
||||||
this._calculateInternal(legOnePointer, legTwoPointer, offersAutobridged,
|
|
||||||
callback);
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
Amount.strict_mode = this._oldMode;
|
Amount.strict_mode = this._oldMode;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ function OrderBook(remote,
|
|||||||
this._gotOffersFromLegTwo = false;
|
this._gotOffersFromLegTwo = false;
|
||||||
|
|
||||||
this._waitingForOffers = false;
|
this._waitingForOffers = false;
|
||||||
this._offersModifiedAt = 0;
|
this._lastUpdateLedgerSequence = 0;
|
||||||
this._transactionsLeft = 0;
|
this._transactionsLeft = 0;
|
||||||
this._calculatorRunning = false;
|
this._calculatorRunning = false;
|
||||||
|
|
||||||
@@ -839,29 +839,29 @@ OrderBook.prototype.isBalanceChangeNode = function(node) {
|
|||||||
|
|
||||||
OrderBook.prototype._canRunAutobridgeCalc = function(): boolean {
|
OrderBook.prototype._canRunAutobridgeCalc = function(): boolean {
|
||||||
return !this._calculatorRunning;
|
return !this._calculatorRunning;
|
||||||
}
|
};
|
||||||
|
|
||||||
OrderBook.prototype.onTransaction = function(transaction) {
|
OrderBook.prototype.onTransaction = function(transaction) {
|
||||||
this.updateFundedAmounts(transaction);
|
this.updateFundedAmounts(transaction);
|
||||||
|
|
||||||
|
|
||||||
if (--this._transactionsLeft === 0 && !this._waitingForOffers) {
|
if (--this._transactionsLeft === 0 && !this._waitingForOffers) {
|
||||||
const lastClosedLedger = this._remote.getLedgerSequence() - 1;
|
const lastClosedLedger = this._remote.getLedgerSequence();
|
||||||
if (this._isAutobridgeable) {
|
if (this._isAutobridgeable) {
|
||||||
if (this._canRunAutobridgeCalc()) {
|
if (this._canRunAutobridgeCalc()) {
|
||||||
if (this._legOneBook._offersModifiedAt === lastClosedLedger ||
|
if (this._legOneBook._lastUpdateLedgerSequence === lastClosedLedger ||
|
||||||
this._legTwoBook._offersModifiedAt === lastClosedLedger
|
this._legTwoBook._lastUpdateLedgerSequence === lastClosedLedger
|
||||||
) {
|
) {
|
||||||
this.computeAutobridgedOffersWrapper();
|
this.computeAutobridgedOffersWrapper();
|
||||||
} else if (this._offersModifiedAt === lastClosedLedger) {
|
} else if (this._lastUpdateLedgerSequence === lastClosedLedger) {
|
||||||
this.mergeDirectAndAutobridgedBooks();
|
this.mergeDirectAndAutobridgedBooks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (this._offersModifiedAt === lastClosedLedger) {
|
} else if (this._lastUpdateLedgerSequence === lastClosedLedger) {
|
||||||
this.emit('model', this._offers);
|
this.emit('model', this._offers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates funded amounts/balances using modified balance nodes
|
* Updates funded amounts/balances using modified balance nodes
|
||||||
@@ -978,7 +978,7 @@ OrderBook.prototype.onLedgerClosed = function(message) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._transactionsLeft = message.txn_count;
|
this._transactionsLeft = message.txn_count;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify orderbook of a relevant transaction
|
* Notify orderbook of a relevant transaction
|
||||||
@@ -1080,7 +1080,7 @@ OrderBook.prototype.notify = function(transaction) {
|
|||||||
|
|
||||||
this.emit('transaction', transaction);
|
this.emit('transaction', transaction);
|
||||||
|
|
||||||
this._offersModifiedAt = this._remote.getLedgerSequence() - 1;
|
this._lastUpdateLedgerSequence = this._remote.getLedgerSequence();
|
||||||
|
|
||||||
if (!takerGetsTotal.is_zero()) {
|
if (!takerGetsTotal.is_zero()) {
|
||||||
this.emit('trade', takerPaysTotal, takerGetsTotal);
|
this.emit('trade', takerPaysTotal, takerGetsTotal);
|
||||||
@@ -1384,8 +1384,6 @@ OrderBook.prototype.computeAutobridgedOffers = function(callback = function() {}
|
|||||||
this._issuerPays
|
this._issuerPays
|
||||||
);
|
);
|
||||||
|
|
||||||
const lastClosedLedger = this._remote.getLedgerSequence() - 1;
|
|
||||||
|
|
||||||
autobridgeCalculator.calculate((autobridgedOffers) => {
|
autobridgeCalculator.calculate((autobridgedOffers) => {
|
||||||
this._offersAutobridged = autobridgedOffers;
|
this._offersAutobridged = autobridgedOffers;
|
||||||
callback();
|
callback();
|
||||||
|
|||||||
Reference in New Issue
Block a user