fix edge case for listBlocks
This commit is contained in:
parent
68a9e92955
commit
50413c8204
7
api/test/app.js
Normal file
7
api/test/app.js
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var BitcoreHTTP = require('../lib/http');
|
||||
|
||||
module.exports = function(nodeMock) {
|
||||
return process.env.INTEGRATION === 'true' ? BitcoreHTTP.create().app : new BitcoreHTTP(nodeMock).app;
|
||||
};
|
||||
@ -205,6 +205,7 @@ BlockService.prototype.listBlocks = function(from, to, offset, limit) {
|
||||
var start = from + offset;
|
||||
var end = Math.min(to, start + limit - 1);
|
||||
var blocks = [];
|
||||
// TODO: optimize: precompute heights and fetch all blocks in parallel?
|
||||
var fetchBlock = function(height) {
|
||||
if (height > end) {
|
||||
return;
|
||||
@ -212,12 +213,11 @@ BlockService.prototype.listBlocks = function(from, to, offset, limit) {
|
||||
console.log('fetching block', height);
|
||||
return self.getBlockByHeight(height)
|
||||
.then(function(block) {
|
||||
if (!block) {
|
||||
// TODO: report?
|
||||
return;
|
||||
}
|
||||
blocks.push(block);
|
||||
blocks.push(block.toObject());
|
||||
return fetchBlock(height + 1);
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
};
|
||||
return fetchBlock(start)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user