Cleaned code a bit.
This commit is contained in:
parent
65089302bb
commit
230f3681bd
@ -115,6 +115,7 @@ TimestampService.prototype.getBlockHeights = function(timestamps, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var hashes = [];
|
var hashes = [];
|
||||||
|
var hashTuple = [];
|
||||||
var streamErr = null;
|
var streamErr = null;
|
||||||
|
|
||||||
stream.on('data', function(data) {
|
stream.on('data', function(data) {
|
||||||
@ -127,10 +128,9 @@ TimestampService.prototype.getBlockHeights = function(timestamps, callback) {
|
|||||||
|
|
||||||
stream.on('end', function() {
|
stream.on('end', function() {
|
||||||
if (!streamErr && hashes.length > 1) {
|
if (!streamErr && hashes.length > 1) {
|
||||||
var hashTuple = [ hashes[0], hashes[hashes.length - 1] ];
|
hashTuple = [ hashes[0], hashes[hashes.length - 1] ];
|
||||||
return callback(null, hashTuple);
|
|
||||||
}
|
}
|
||||||
callback(streamErr);
|
callback(streamErr, hashTuple);
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -585,25 +585,36 @@ WalletService.prototype._endpointPostAddresses = function() {
|
|||||||
WalletService.prototype._endpointGetTransactions = function() {
|
WalletService.prototype._endpointGetTransactions = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return function(req, res) {
|
return function(req, res) {
|
||||||
req.setTimeout(600000);
|
|
||||||
var walletId = req.params.walletId;
|
var walletId = req.params.walletId;
|
||||||
|
|
||||||
self._processStartEndOptions(req, function(err, heights) {
|
self._processStartEndOptions(req, function(err, heights) {
|
||||||
|
|
||||||
|
if(err) {
|
||||||
|
return utils.sendError(err, res);
|
||||||
|
}
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
start: heights[0],
|
start: heights[0] || 0,
|
||||||
end : heights[1],
|
end : heights[1] || 0xffffffff,
|
||||||
from: req.query.from,
|
from: req.query.from,
|
||||||
to: req.query.to
|
to: req.query.to
|
||||||
};
|
};
|
||||||
self._getTransactions(walletId, options, function(err, transactions) {
|
self._getTransactions(walletId, options, function(err, transactions) {
|
||||||
|
|
||||||
if(err) {
|
if(err) {
|
||||||
return utils.sendError(err, res);
|
return utils.sendError(err, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
var rs = new Readable;
|
var rs = new Readable;
|
||||||
|
|
||||||
transactions.forEach(function(transaction) {
|
transactions.forEach(function(transaction) {
|
||||||
rs.push(JSON.stringify(self._formatTransaction(transaction)));
|
rs.push(JSON.stringify(self._formatTransaction(transaction)));
|
||||||
});
|
});
|
||||||
|
|
||||||
rs.push(null);
|
rs.push(null);
|
||||||
rs.pipe(res);
|
rs.pipe(res);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -1058,13 +1069,21 @@ WalletService.prototype._storeBalance = function(walletId, balance, callback) {
|
|||||||
|
|
||||||
WalletService.prototype._processStartEndOptions = function(req, callback) {
|
WalletService.prototype._processStartEndOptions = function(req, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (!(req.query.start && req.query.start < (500 * 1E6))) {
|
if (!(req.query.start && req.query.start < (500 * 1E6))) {
|
||||||
|
|
||||||
var heights = [];
|
var heights = [];
|
||||||
self.node.services.timestamp.getBlockHeights([
|
self.node.services.timestamp.getBlockHeights([
|
||||||
utils.normalizeTimeStamp(req.query.start),
|
utils.normalizeTimeStamp(req.query.start),
|
||||||
utils.normalizeTimeStamp(req.query.end)
|
utils.normalizeTimeStamp(req.query.end)
|
||||||
],
|
],
|
||||||
|
|
||||||
function(err, hashTuple) {
|
function(err, hashTuple) {
|
||||||
|
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
hashTuple.forEach(function(hash) {
|
hashTuple.forEach(function(hash) {
|
||||||
self.node.services.bitcoind._tryAllClients(function(client, done) {
|
self.node.services.bitcoind._tryAllClients(function(client, done) {
|
||||||
client.getBlock(hash, function(err, response) {
|
client.getBlock(hash, function(err, response) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user