@@ -246,16 +246,17 @@ BlockController.prototype.list = function(req, res) {
246246 isToday = true ;
247247 }
248248
249- var gte = Math . round ( ( new Date ( dateStr ) ) . getTime ( ) / 1000 ) ;
249+ var low = Math . round ( ( new Date ( dateStr ) ) . getTime ( ) / 1000 ) ;
250250
251251 //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 ;
255255 var limit = parseInt ( req . query . limit || BLOCK_LIMIT ) ;
256256 var more = false ;
257257
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 ) {
259260 if ( err ) {
260261 return self . common . handleErrors ( err , res ) ;
261262 }
@@ -270,32 +271,28 @@ BlockController.prototype.list = function(req, res) {
270271 async . mapSeries (
271272 hashes ,
272273 function ( hash , next ) {
273- self . _getBlockSummary ( hash , next ) ;
274+ self . _getBlockSummary ( hash . blockhash , next ) ;
274275 } ,
275276 function ( err , blocks ) {
276277 if ( err ) {
277278 return self . common . handleErrors ( err , res ) ;
278279 }
279280
280- blocks . sort ( function ( a , b ) {
281- return b . height - a . height ;
282- } ) ;
283-
284281 var data = {
285282 blocks : blocks ,
286283 length : blocks . length ,
287284 pagination : {
288285 next : next ,
289286 prev : prev ,
290- currentTs : lte - 1 ,
287+ currentTs : high - 1 ,
291288 current : dateStr ,
292289 isToday : isToday ,
293290 more : more
294291 }
295292 } ;
296293
297294 if ( more ) {
298- data . pagination . moreTs = blocks [ blocks . length - 1 ] . time ;
295+ data . pagination . moreTs = hashes [ hashes . length - 1 ] . logicalts - 1 ;
299296 }
300297
301298 res . jsonp ( data ) ;
0 commit comments