Skip to content

Commit

Permalink
Use logical timestamp to display blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Chethan Krishna committed Jul 28, 2016
1 parent e650561 commit ccd11d6
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions lib/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,17 @@ BlockController.prototype.list = function(req, res) {
isToday = true;
}

var gte = Math.round((new Date(dateStr)).getTime() / 1000);
var low = Math.round((new Date(dateStr)).getTime() / 1000);

//pagination
var lte = parseInt(req.query.startTimestamp) || gte + 86400;
var prev = this.formatTimestamp(new Date((gte - 86400) * 1000));
var next = lte ? this.formatTimestamp(new Date(lte * 1000)) : null;
var high = parseInt(req.query.startTimestamp) || low + 86399;
var prev = this.formatTimestamp(new Date((low - 86400) * 1000));
var next = high ? this.formatTimestamp(new Date(high * 1000)) : null;
var limit = parseInt(req.query.limit || BLOCK_LIMIT);
var more = false;

self.node.services.bitcoind.getBlockHashesByTimestamp(lte, gte, function(err, hashes) {
var options = {'noOrphans':false, 'logicalTimes':true};
self.node.services.bitcoind.getBlockHashesByTimestamp(high, low, options, function(err, hashes) {
if(err) {
return self.common.handleErrors(err, res);
}
Expand All @@ -270,32 +271,28 @@ BlockController.prototype.list = function(req, res) {
async.mapSeries(
hashes,
function(hash, next) {
self._getBlockSummary(hash, next);
self._getBlockSummary(hash.blockhash, next);
},
function(err, blocks) {
if(err) {
return self.common.handleErrors(err, res);
}

blocks.sort(function(a, b) {
return b.height - a.height;
});

var data = {
blocks: blocks,
length: blocks.length,
pagination: {
next: next,
prev: prev,
currentTs: lte - 1,
currentTs: high - 1,
current: dateStr,
isToday: isToday,
more: more
}
};

if(more) {
data.pagination.moreTs = blocks[blocks.length - 1].time;
data.pagination.moreTs = hashes[hashes.length - 1].logicalts - 1;
}

res.jsonp(data);
Expand Down

0 comments on commit ccd11d6

Please sign in to comment.