API query options

- Deprecating options (from/to) in API `/addr/:addr`
- Adding option `after` in APIs `/addr/:addr` and  `/addrs/:addrs/txs`,
- Adding response value `lastItem` to API `/addrs/:addrs/txs`
This commit is contained in:
sairajzero 2023-02-05 04:01:04 +05:30
parent dbb8cafdc3
commit 20eb50b281

View File

@ -24,9 +24,14 @@ AddressController.prototype.show = function(req, res) {
self.common.bindStopFlagOnClose(res, options);
/*DEPRECATED
if (req.query.from && req.query.to) {
options.from = parseInt(req.query.from);
options.to = parseInt(req.query.to);
}*/
if (req.query.after) {
options.after = req.query.after;
}
self._address.getAddressSummary(req.addr, options, function(err, data) {
@ -46,9 +51,8 @@ AddressController.prototype.show_ws = function(ws, req) {
var self = this;
var options = { noTxList: true };
if (req.query.from && req.query.to) {
options.from = parseInt(req.query.from);
options.to = parseInt(req.query.to);
if (req.query.after) {
options.after = req.query.after;
}
self.common.bindStopFlagOnClose(ws, options);
@ -282,11 +286,19 @@ AddressController.prototype.multiutxo = function(req, res) {
AddressController.prototype.multitxs = function(req, res) {
var self = this;
var options = {
from: parseInt(req.query.from) || parseInt(req.body.from) || 0
};
var options = {};
options.to = parseInt(req.query.to) || parseInt(req.body.to) || parseInt(options.from) + 10;
options.after = req.query.after || req.body.after || undefined;
//Temporary support
if(req.query.from || req.body.from) {
options.from = parseInt(req.query.from) || parseInt(req.body.from) || undefined;
}
//Temporary support
if(req.query.to || req.body.to) {
options.to = parseInt(req.query.to) || parseInt(req.body.to) || undefined;
}
self.common.bindStopFlagOnClose(res, options);
@ -306,8 +318,9 @@ AddressController.prototype.multitxs = function(req, res) {
var ret = {
totalItems: result.totalCount,
from: options.from,
to: Math.min(options.to, result.totalCount),
lastItem: items.find(a => a.confirmations !== 0), //assuming items is recent tx first order
//from: options.from,
//to: Math.min(options.to, result.totalCount),
items: items
};
@ -320,11 +333,11 @@ AddressController.prototype.multitxs = function(req, res) {
AddressController.prototype.multitxs_ws = function(ws, req) {
var self = this;
var options = {
from: parseInt(req.query.from) || parseInt(req.body.from) || 0
};
var options = {};
options.to = parseInt(req.query.to) || parseInt(req.body.to) || parseInt(options.from) + 10;
if (req.query.after) {
options.after = req.query.after;
}
options.txNotNeeded = true;
@ -332,6 +345,8 @@ AddressController.prototype.multitxs_ws = function(ws, req) {
self.common.bindStopFlagOnClose(ws, options);
var lastItem = {id: '', height: 0};
self._address.getAddressHistory(req.addrs, options, function (err, data) {
if(err) {
return self.common.handleErrors_ws(err, ws, false);
@ -342,6 +357,13 @@ AddressController.prototype.multitxs_ws = function(ws, req) {
if(err) {
return self.common.handleErrors_ws(err, ws, false);
}
//finding the last key (useful for `after` option on next request call)
if(data.confirmations)
if(lastItem.height < data.blockheight || (lastItem.height == data.blockheight && lastItem.id < data.txid)){
lastItem.id = data.txid;
lastItem.height = data.blockheight;
}
ws.send({data})
@ -355,8 +377,7 @@ AddressController.prototype.multitxs_ws = function(ws, req) {
var ret = {
totalItems: result.totalCount,
from: options.from,
to: Math.min(options.to, result.totalCount)
lastItem: lastItem.id
}
if(ws.readyState === ws.OPEN){