Compare commits
10 Commits
40b2e64a8f
...
35f5a82d4b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35f5a82d4b | ||
|
|
a396c4a24e | ||
|
|
fe9741fdf3 | ||
|
|
9da18c7073 | ||
|
|
7663026227 | ||
|
|
8d4f9f5a6e | ||
|
|
1d53646101 | ||
|
|
e5c86ebe5f | ||
|
|
5ab1214fa4 | ||
|
|
c5690aa490 |
@ -16,7 +16,7 @@ var utils = require('../../utils');
|
|||||||
var LRU = require('lru-cache');
|
var LRU = require('lru-cache');
|
||||||
var XXHash = require('xxhash');
|
var XXHash = require('xxhash');
|
||||||
|
|
||||||
const MAX_TX_QUERY_LIMIT = 10;
|
const MAX_TX_QUERY_LIMIT = 100;
|
||||||
|
|
||||||
// See rationale about this cache at function getTxList(next)
|
// See rationale about this cache at function getTxList(next)
|
||||||
const TXID_LIST_CACHE_ITEMS = 250; // nr of items (this translates to: consecutive
|
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
|
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
|
results.items.unshift(tx); //using unshift, so that recent tx (low) are at front
|
||||||
|
|
||||||
if(results.items.length > MAX_TX_QUERY_LIMIT) {
|
if(results.items.length > MAX_TX_QUERY_LIMIT) { //remove items from array when overflown
|
||||||
results.items.sort((a, b) => b.__height - a.__height || a.txid().localeCompare(b.txid()));
|
results.items.sort((a, b) => (b.__height || 0xffffffff) - (a.__height || 0xffffffff) || b.txid().localeCompare(a.txid()));
|
||||||
let del_count = options.old_support ? results.items.length : results.items.length - MAX_TX_QUERY_LIMIT;
|
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;
|
let start_index = options.old_support ? MAX_TX_QUERY_LIMIT : 0;
|
||||||
console.debug("POPED", results.items.splice(start_index, del_count).map(r => r.txid())) ;
|
results.items.splice(start_index, del_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ AddressService.prototype.getAddressHistory = function(addresses, options, stream
|
|||||||
}
|
}
|
||||||
|
|
||||||
//sort items in desc block-height, then asc txid (if same height)
|
//sort items in desc block-height, then asc txid (if same height)
|
||||||
results.items.sort((a, b) => b.__height - a.__height || a.txid().localeCompare(b.txid()));
|
results.items.sort((a, b) => (b.__height || 0xffffffff) - (a.__height || 0xffffffff) || b.txid().localeCompare(a.txid()));
|
||||||
results.totalCount = parseInt(results.totalCount.toFixed());
|
results.totalCount = parseInt(results.totalCount.toFixed());
|
||||||
|
|
||||||
//Quick support for `from` and `to` options (DEPRECATED! Not recommeded to use)
|
//Quick support for `from` and `to` options (DEPRECATED! Not recommeded to use)
|
||||||
@ -848,11 +848,9 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
|
|||||||
//declare the queue to process tx data
|
//declare the queue to process tx data
|
||||||
var tmpTxList = {}; //store processed txid temporarily to ignore duplication
|
var tmpTxList = {}; //store processed txid temporarily to ignore duplication
|
||||||
|
|
||||||
let td_count = 0; //test
|
|
||||||
var q = async.queue(function(id, cb) {
|
var q = async.queue(function(id, cb) {
|
||||||
td_count++; //test
|
|
||||||
//duplication finding
|
|
||||||
|
|
||||||
|
//duplication finding
|
||||||
if(id.txid in tmpTxList){
|
if(id.txid in tmpTxList){
|
||||||
|
|
||||||
tmpTxList[id.txid][0]++;
|
tmpTxList[id.txid][0]++;
|
||||||
@ -881,7 +879,7 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
|
|||||||
|
|
||||||
}, 4);
|
}, 4);
|
||||||
|
|
||||||
//q.pause(); //pause and wait until queue is set
|
//q.pause(); //pause and wait until queue is set (not needed)
|
||||||
|
|
||||||
function chunkCallback(err, tx){
|
function chunkCallback(err, tx){
|
||||||
|
|
||||||
@ -921,8 +919,6 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
|
|||||||
|
|
||||||
self._transaction.getTransaction(options.after, options, function(err, tx) {
|
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) {
|
if(tx && tx.confirmations && tx.height >= options.start) {
|
||||||
|
|
||||||
options.start = tx.height;
|
options.start = tx.height;
|
||||||
@ -960,9 +956,8 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
|
|||||||
|
|
||||||
txIdTransformStream._transform = function(chunk, enc, cb) {
|
txIdTransformStream._transform = function(chunk, enc, cb) {
|
||||||
|
|
||||||
if(options.flag_stop){
|
if(options.flag_stop){//stop data query
|
||||||
//stop data query
|
console.debug("FLAG STOP:", options.flag_stop)
|
||||||
console.debug("FLAG:", options.flag_stop)
|
|
||||||
return txIdTransformStream.unpipe();
|
return txIdTransformStream.unpipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,11 +995,15 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
|
|||||||
|
|
||||||
//wait for queue to complete
|
//wait for queue to complete
|
||||||
function(next) {
|
function(next) {
|
||||||
console.debug("WAITING FOR DRAIN")
|
|
||||||
q.drain = ()=> {
|
console.debug("WAITING FOR QUEUE TO COMPLETE", q.started)
|
||||||
console.debug("END-DRAIN", d_count, td_count);
|
|
||||||
next();
|
if(!q.started) //No tx in query
|
||||||
};
|
return next();
|
||||||
|
|
||||||
|
else
|
||||||
|
q.drain = () => next();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
], callback);
|
], callback);
|
||||||
|
|||||||
@ -100,13 +100,15 @@ WebService.prototype.stop = function(callback) {
|
|||||||
* all of the exposed HTTP routes.
|
* all of the exposed HTTP routes.
|
||||||
*/
|
*/
|
||||||
WebService.prototype.setupAllRoutes = function() {
|
WebService.prototype.setupAllRoutes = function() {
|
||||||
for(var key in this.node.services) {
|
const self = this;
|
||||||
|
|
||||||
|
for(var key in self.node.services) {
|
||||||
var subApp = new express();
|
var subApp = new express();
|
||||||
var service = this.node.services[key];
|
var service = self.node.services[key];
|
||||||
|
|
||||||
if(service.getRoutePrefix && service.setupRoutes) {
|
if(service.getRoutePrefix && service.setupRoutes) {
|
||||||
this.app.use('/' + this.node.services[key].getRoutePrefix(), subApp);
|
self.app.use('/' + self.node.services[key].getRoutePrefix(), subApp);
|
||||||
this.node.services[key].setupRoutes(subApp, express, express_ws);
|
self.node.services[key].setupRoutes(subApp, express, a => express_ws(a, self.server));
|
||||||
} else {
|
} else {
|
||||||
log.debug('No routes defined for: ' + key);
|
log.debug('No routes defined for: ' + key);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user