diff --git a/lib/addresses.js b/lib/addresses.js index 3fdba58..1e2ef84 100644 --- a/lib/addresses.js +++ b/lib/addresses.js @@ -22,6 +22,8 @@ AddressController.prototype.show = function(req, res) { noTxList: parseInt(req.query.noTxList) }; + self.common.bindStopFlagOnClose(res, options); + if (req.query.from && req.query.to) { options.from = parseInt(req.query.from); options.to = parseInt(req.query.to); @@ -40,19 +42,17 @@ AddressController.prototype.show = function(req, res) { }); }; -AddressController.prototype.show_ws = function(req, ws) { +AddressController.prototype.show_ws = function(ws, req) { var self = this; - /* - var options = { - noTxList: parseInt(req.query.noTxList) - }; - */ + var options = { noTxList: true }; if (req.query.from && req.query.to) { options.from = parseInt(req.query.from); options.to = parseInt(req.query.to); } + self.common.bindStopFlagOnClose(ws, options); + self._address.getAddressSummary(req.addr, options, function (err, data) { if(err) { return self.common.handleErrors_ws(err, ws); @@ -92,7 +92,10 @@ AddressController.prototype.unconfirmedBalance = function(req, res) { AddressController.prototype.addressSummarySubQuery = function(req, res, param) { var self = this; - self.getAddressSummary(req.addr, {}, function(err, data) { + var options = { noTxList: true }; + self.common.bindStopFlagOnClose(res, options); + + self.getAddressSummary(req.addr, options, function(err, data) { if(err) { return self.common.handleErrors(err, res); } @@ -119,8 +122,8 @@ AddressController.prototype.getAddressSummary = function(address, options, callb totalSentSat: summary.totalSentSat, unconfirmedBalance: summary.unconfirmedBalance, unconfirmedBalanceSat: summary.unconfirmedBalanceSat, - unconfirmedTxApperances: summary.unconfirmedAppearances, // misspelling - ew - txApperances: summary.txApperances, // yuck + unconfirmedTxApperances: summary.unconfirmedTxApperances, + txApperances: summary.txApperances, transactions: summary.transactions }; @@ -285,6 +288,8 @@ AddressController.prototype.multitxs = function(req, res) { options.to = parseInt(req.query.to) || parseInt(req.body.to) || parseInt(options.from) + 10; + self.common.bindStopFlagOnClose(res, options); + self._address.getAddressHistory(req.addrs, options, function(err, result) { if(err) { @@ -312,7 +317,7 @@ AddressController.prototype.multitxs = function(req, res) { }); }; -AddressController.prototype.multitxs_ws = function(req, ws) { +AddressController.prototype.multitxs_ws = function(ws, req) { var self = this; var options = { @@ -325,6 +330,8 @@ AddressController.prototype.multitxs_ws = function(req, ws) { var transformOptions = self._getTransformOptions(req); + self.common.bindStopFlagOnClose(ws, options); + self._address.getAddressHistory(req.addrs, options, function (err, data) { if(err) { return self.common.handleErrors_ws(err, ws, false); diff --git a/lib/common.js b/lib/common.js index 844c724..cd6ff2d 100644 --- a/lib/common.js +++ b/lib/common.js @@ -20,6 +20,10 @@ Common.prototype.notReady_ws = function (err, ws, p) { ws.close(); }; +Common.prototype.bindStopFlagOnClose = function (res_ws, obj) { + res_ws.on("close", () => obj.flag_stop = true); +}; + Common.prototype.handleErrors = function (err, res) { if (err) { if (err.code) {