Streamed multiutxos.
This commit is contained in:
parent
f862a7696b
commit
9e216a818a
@ -152,10 +152,13 @@ AddressController.prototype.utxo = function(req, res) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// this call could take a while to run depending on what addresses are used
|
||||||
|
// considering memory constraints, we will streaming out the results for addresses
|
||||||
|
// not necessarily in the order we received them
|
||||||
AddressController.prototype.multiutxo = function(req, res) {
|
AddressController.prototype.multiutxo = function(req, res) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var finalUtxos = [];
|
var sep = ',';
|
||||||
|
|
||||||
var addresses;
|
var addresses;
|
||||||
if (_.isArray(req.addrs)) {
|
if (_.isArray(req.addrs)) {
|
||||||
@ -164,6 +167,9 @@ AddressController.prototype.multiutxo = function(req, res) {
|
|||||||
addresses = req.addrs.split(',');
|
addresses = req.addrs.split(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var addressesLeft = addresses.length;
|
||||||
|
res.write('[');
|
||||||
|
|
||||||
async.eachLimit(addresses, 4, function(addr, next) {
|
async.eachLimit(addresses, 4, function(addr, next) {
|
||||||
|
|
||||||
self._address.getAddressUnspentOutputs(addr, {}, function(err, utxos) {
|
self._address.getAddressUnspentOutputs(addr, {}, function(err, utxos) {
|
||||||
@ -172,20 +178,28 @@ AddressController.prototype.multiutxo = function(req, res) {
|
|||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
finalUtxos = finalUtxos.concat(utxos);
|
for(var i = 0; i < utxos.length; i++) {
|
||||||
|
|
||||||
|
if (--addressesLeft <= 0 && utxos[i] === utxos[utxos.length - 1] ) {
|
||||||
|
sep = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
res.write(JSON.stringify(self.transformUtxo(utxos[i])) + sep);
|
||||||
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return self.common.handleErrors(err, res);
|
return self.common.handleErrors(err, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
var finalRes = finalUtxos.map(self.transformUtxo.bind(self));
|
|
||||||
res.jsonp(finalRes);
|
|
||||||
|
|
||||||
|
res.write(']');
|
||||||
|
res.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressController.prototype.transformUtxo = function(utxoArg) {
|
AddressController.prototype.transformUtxo = function(utxoArg) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user