Compare commits

..

No commits in common. "35f5a82d4be9b685a03661fb3f56ec472f671f45" and "40b2e64a8ffe4544160fd8a761be756a9781de2a" have entirely different histories.

2 changed files with 23 additions and 24 deletions

View File

@ -16,7 +16,7 @@ var utils = require('../../utils');
var LRU = require('lru-cache');
var XXHash = require('xxhash');
const MAX_TX_QUERY_LIMIT = 100;
const MAX_TX_QUERY_LIMIT = 10;
// See rationale about this cache at function getTxList(next)
const TXID_LIST_CACHE_ITEMS = 250; // nr of items (this translates to: consecutive
@ -218,11 +218,11 @@ AddressService.prototype.getAddressHistory = function(addresses, options, stream
if(!results.items.some(x => x.txid() === tx.txid())) //push only if tx not already in array
results.items.unshift(tx); //using unshift, so that recent tx (low) are at front
if(results.items.length > MAX_TX_QUERY_LIMIT) { //remove items from array when overflown
results.items.sort((a, b) => (b.__height || 0xffffffff) - (a.__height || 0xffffffff) || b.txid().localeCompare(a.txid()));
if(results.items.length > MAX_TX_QUERY_LIMIT) {
results.items.sort((a, b) => b.__height - a.__height || a.txid().localeCompare(b.txid()));
let del_count = options.old_support ? results.items.length : results.items.length - MAX_TX_QUERY_LIMIT;
let start_index = options.old_support ? MAX_TX_QUERY_LIMIT : 0;
results.items.splice(start_index, del_count);
console.debug("POPED", results.items.splice(start_index, del_count).map(r => r.txid())) ;
}
}
@ -239,7 +239,7 @@ AddressService.prototype.getAddressHistory = function(addresses, options, stream
}
//sort items in desc block-height, then asc txid (if same height)
results.items.sort((a, b) => (b.__height || 0xffffffff) - (a.__height || 0xffffffff) || b.txid().localeCompare(a.txid()));
results.items.sort((a, b) => b.__height - a.__height || a.txid().localeCompare(b.txid()));
results.totalCount = parseInt(results.totalCount.toFixed());
//Quick support for `from` and `to` options (DEPRECATED! Not recommeded to use)
@ -848,9 +848,11 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
//declare the queue to process tx data
var tmpTxList = {}; //store processed txid temporarily to ignore duplication
let td_count = 0; //test
var q = async.queue(function(id, cb) {
td_count++; //test
//duplication finding
if(id.txid in tmpTxList){
tmpTxList[id.txid][0]++;
@ -879,7 +881,7 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
}, 4);
//q.pause(); //pause and wait until queue is set (not needed)
//q.pause(); //pause and wait until queue is set
function chunkCallback(err, tx){
@ -919,6 +921,8 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
self._transaction.getTransaction(options.after, options, function(err, tx) {
if(!tx) console.debug(options.after + "Not found");
if(tx && tx.confirmations && tx.height >= options.start) {
options.start = tx.height;
@ -956,8 +960,9 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
txIdTransformStream._transform = function(chunk, enc, cb) {
if(options.flag_stop){//stop data query
console.debug("FLAG STOP:", options.flag_stop)
if(options.flag_stop){
//stop data query
console.debug("FLAG:", options.flag_stop)
return txIdTransformStream.unpipe();
}
@ -995,15 +1000,11 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
//wait for queue to complete
function(next) {
console.debug("WAITING FOR QUEUE TO COMPLETE", q.started)
if(!q.started) //No tx in query
return next();
else
q.drain = () => next();
console.debug("WAITING FOR DRAIN")
q.drain = ()=> {
console.debug("END-DRAIN", d_count, td_count);
next();
};
}
], callback);

View File

@ -100,15 +100,13 @@ WebService.prototype.stop = function(callback) {
* all of the exposed HTTP routes.
*/
WebService.prototype.setupAllRoutes = function() {
const self = this;
for(var key in self.node.services) {
for(var key in this.node.services) {
var subApp = new express();
var service = self.node.services[key];
var service = this.node.services[key];
if(service.getRoutePrefix && service.setupRoutes) {
self.app.use('/' + self.node.services[key].getRoutePrefix(), subApp);
self.node.services[key].setupRoutes(subApp, express, a => express_ws(a, self.server));
this.app.use('/' + this.node.services[key].getRoutePrefix(), subApp);
this.node.services[key].setupRoutes(subApp, express, express_ws);
} else {
log.debug('No routes defined for: ' + key);
}