@@ -246,16 +246,17 @@ BlockController.prototype.list = function(req, res) {
246
246
isToday = true ;
247
247
}
248
248
249
- var gte = Math . round ( ( new Date ( dateStr ) ) . getTime ( ) / 1000 ) ;
249
+ var low = Math . round ( ( new Date ( dateStr ) ) . getTime ( ) / 1000 ) ;
250
250
251
251
//pagination
252
- var lte = parseInt ( req . query . startTimestamp ) || gte + 86400 ;
253
- var prev = this . formatTimestamp ( new Date ( ( gte - 86400 ) * 1000 ) ) ;
254
- var next = lte ? this . formatTimestamp ( new Date ( lte * 1000 ) ) : null ;
252
+ var high = parseInt ( req . query . startTimestamp ) || low + 86399 ;
253
+ var prev = this . formatTimestamp ( new Date ( ( low - 86400 ) * 1000 ) ) ;
254
+ var next = high ? this . formatTimestamp ( new Date ( high * 1000 ) ) : null ;
255
255
var limit = parseInt ( req . query . limit || BLOCK_LIMIT ) ;
256
256
var more = false ;
257
257
258
- self . node . services . bitcoind . getBlockHashesByTimestamp ( lte , gte , function ( err , hashes ) {
258
+ var options = { 'noOrphans' :false , 'logicalTimes' :true } ;
259
+ self . node . services . bitcoind . getBlockHashesByTimestamp ( high , low , options , function ( err , hashes ) {
259
260
if ( err ) {
260
261
return self . common . handleErrors ( err , res ) ;
261
262
}
@@ -270,32 +271,28 @@ BlockController.prototype.list = function(req, res) {
270
271
async . mapSeries (
271
272
hashes ,
272
273
function ( hash , next ) {
273
- self . _getBlockSummary ( hash , next ) ;
274
+ self . _getBlockSummary ( hash . blockhash , next ) ;
274
275
} ,
275
276
function ( err , blocks ) {
276
277
if ( err ) {
277
278
return self . common . handleErrors ( err , res ) ;
278
279
}
279
280
280
- blocks . sort ( function ( a , b ) {
281
- return b . height - a . height ;
282
- } ) ;
283
-
284
281
var data = {
285
282
blocks : blocks ,
286
283
length : blocks . length ,
287
284
pagination : {
288
285
next : next ,
289
286
prev : prev ,
290
- currentTs : lte - 1 ,
287
+ currentTs : high - 1 ,
291
288
current : dateStr ,
292
289
isToday : isToday ,
293
290
more : more
294
291
}
295
292
} ;
296
293
297
294
if ( more ) {
298
- data . pagination . moreTs = blocks [ blocks . length - 1 ] . time ;
295
+ data . pagination . moreTs = hashes [ hashes . length - 1 ] . logicalts - 1 ;
299
296
}
300
297
301
298
res . jsonp ( data ) ;
0 commit comments