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:
parent
dbb8cafdc3
commit
20eb50b281
@ -24,9 +24,14 @@ AddressController.prototype.show = function(req, res) {
|
|||||||
|
|
||||||
self.common.bindStopFlagOnClose(res, options);
|
self.common.bindStopFlagOnClose(res, options);
|
||||||
|
|
||||||
|
/*DEPRECATED
|
||||||
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);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if (req.query.after) {
|
||||||
|
options.after = req.query.after;
|
||||||
}
|
}
|
||||||
|
|
||||||
self._address.getAddressSummary(req.addr, options, function(err, data) {
|
self._address.getAddressSummary(req.addr, options, function(err, data) {
|
||||||
@ -46,9 +51,8 @@ AddressController.prototype.show_ws = function(ws, req) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var options = { noTxList: true };
|
var options = { noTxList: true };
|
||||||
|
|
||||||
if (req.query.from && req.query.to) {
|
if (req.query.after) {
|
||||||
options.from = parseInt(req.query.from);
|
options.after = req.query.after;
|
||||||
options.to = parseInt(req.query.to);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.common.bindStopFlagOnClose(ws, options);
|
self.common.bindStopFlagOnClose(ws, options);
|
||||||
@ -282,11 +286,19 @@ AddressController.prototype.multiutxo = function(req, res) {
|
|||||||
AddressController.prototype.multitxs = function(req, res) {
|
AddressController.prototype.multitxs = function(req, res) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var options = {
|
var options = {};
|
||||||
from: parseInt(req.query.from) || parseInt(req.body.from) || 0
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
self.common.bindStopFlagOnClose(res, options);
|
||||||
|
|
||||||
@ -306,8 +318,9 @@ AddressController.prototype.multitxs = function(req, res) {
|
|||||||
|
|
||||||
var ret = {
|
var ret = {
|
||||||
totalItems: result.totalCount,
|
totalItems: result.totalCount,
|
||||||
from: options.from,
|
lastItem: items.find(a => a.confirmations !== 0), //assuming items is recent tx first order
|
||||||
to: Math.min(options.to, result.totalCount),
|
//from: options.from,
|
||||||
|
//to: Math.min(options.to, result.totalCount),
|
||||||
items: items
|
items: items
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -320,11 +333,11 @@ AddressController.prototype.multitxs = function(req, res) {
|
|||||||
AddressController.prototype.multitxs_ws = function(ws, req) {
|
AddressController.prototype.multitxs_ws = function(ws, req) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var options = {
|
var options = {};
|
||||||
from: parseInt(req.query.from) || parseInt(req.body.from) || 0
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
options.txNotNeeded = true;
|
||||||
|
|
||||||
@ -332,6 +345,8 @@ AddressController.prototype.multitxs_ws = function(ws, req) {
|
|||||||
|
|
||||||
self.common.bindStopFlagOnClose(ws, options);
|
self.common.bindStopFlagOnClose(ws, options);
|
||||||
|
|
||||||
|
var lastItem = {id: '', height: 0};
|
||||||
|
|
||||||
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);
|
||||||
@ -342,6 +357,13 @@ AddressController.prototype.multitxs_ws = function(ws, req) {
|
|||||||
if(err) {
|
if(err) {
|
||||||
return self.common.handleErrors_ws(err, ws, false);
|
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})
|
ws.send({data})
|
||||||
|
|
||||||
@ -355,8 +377,7 @@ AddressController.prototype.multitxs_ws = function(ws, req) {
|
|||||||
|
|
||||||
var ret = {
|
var ret = {
|
||||||
totalItems: result.totalCount,
|
totalItems: result.totalCount,
|
||||||
from: options.from,
|
lastItem: lastItem.id
|
||||||
to: Math.min(options.to, result.totalCount)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ws.readyState === ws.OPEN){
|
if(ws.readyState === ws.OPEN){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user