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