Minor fixes and binding stop-flag to on-close

- Set flag_stop  when ws or http conn is closed
- Fixed: incorrect order of parameters to ws fns. ie, (ws, req) is the correct order
- Pass noTxList flag to options in show_ws and addressSummarySubQuery
- Fixed: minor typos/misspellings
This commit is contained in:
sairajzero 2023-02-04 17:53:50 +05:30
parent f4029eaf88
commit dbb8cafdc3
2 changed files with 21 additions and 10 deletions

View File

@ -22,6 +22,8 @@ AddressController.prototype.show = function(req, res) {
noTxList: parseInt(req.query.noTxList) noTxList: parseInt(req.query.noTxList)
}; };
self.common.bindStopFlagOnClose(res, options);
if (req.query.from && req.query.to) { if (req.query.from && req.query.to) {
options.from = parseInt(req.query.from); options.from = parseInt(req.query.from);
options.to = parseInt(req.query.to); 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 self = this;
/* var options = { noTxList: true };
var options = {
noTxList: parseInt(req.query.noTxList)
};
*/
if (req.query.from && req.query.to) { if (req.query.from && req.query.to) {
options.from = parseInt(req.query.from); options.from = parseInt(req.query.from);
options.to = parseInt(req.query.to); options.to = parseInt(req.query.to);
} }
self.common.bindStopFlagOnClose(ws, options);
self._address.getAddressSummary(req.addr, options, function (err, data) { self._address.getAddressSummary(req.addr, options, function (err, data) {
if(err) { if(err) {
return self.common.handleErrors_ws(err, ws); return self.common.handleErrors_ws(err, ws);
@ -92,7 +92,10 @@ AddressController.prototype.unconfirmedBalance = function(req, res) {
AddressController.prototype.addressSummarySubQuery = function(req, res, param) { AddressController.prototype.addressSummarySubQuery = function(req, res, param) {
var self = this; 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) { if(err) {
return self.common.handleErrors(err, res); return self.common.handleErrors(err, res);
} }
@ -119,8 +122,8 @@ AddressController.prototype.getAddressSummary = function(address, options, callb
totalSentSat: summary.totalSentSat, totalSentSat: summary.totalSentSat,
unconfirmedBalance: summary.unconfirmedBalance, unconfirmedBalance: summary.unconfirmedBalance,
unconfirmedBalanceSat: summary.unconfirmedBalanceSat, unconfirmedBalanceSat: summary.unconfirmedBalanceSat,
unconfirmedTxApperances: summary.unconfirmedAppearances, // misspelling - ew unconfirmedTxApperances: summary.unconfirmedTxApperances,
txApperances: summary.txApperances, // yuck txApperances: summary.txApperances,
transactions: summary.transactions 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; 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) { self._address.getAddressHistory(req.addrs, options, function(err, result) {
if(err) { 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 self = this;
var options = { var options = {
@ -325,6 +330,8 @@ AddressController.prototype.multitxs_ws = function(req, ws) {
var transformOptions = self._getTransformOptions(req); var transformOptions = self._getTransformOptions(req);
self.common.bindStopFlagOnClose(ws, options);
self._address.getAddressHistory(req.addrs, options, function (err, data) { self._address.getAddressHistory(req.addrs, options, function (err, data) {
if(err) { if(err) {
return self.common.handleErrors_ws(err, ws, false); return self.common.handleErrors_ws(err, ws, false);

View File

@ -20,6 +20,10 @@ Common.prototype.notReady_ws = function (err, ws, p) {
ws.close(); ws.close();
}; };
Common.prototype.bindStopFlagOnClose = function (res_ws, obj) {
res_ws.on("close", () => obj.flag_stop = true);
};
Common.prototype.handleErrors = function (err, res) { Common.prototype.handleErrors = function (err, res) {
if (err) { if (err) {
if (err.code) { if (err.code) {