added limit to method blocks by date

This commit is contained in:
Gustavo Cortez 2014-02-05 14:17:19 -03:00
parent 11aa379bb4
commit f1c52a97a0
2 changed files with 5 additions and 3 deletions

View File

@ -128,11 +128,12 @@ function spec(b) {
});
};
BlockDb.prototype.getBlocksByDate = function(start_ts, end_ts, cb) {
BlockDb.prototype.getBlocksByDate = function(start_ts, end_ts, limit, cb) {
var list = [];
db.createReadStream({
start: TIMESTAMP_ROOT + start_ts,
end: TIMESTAMP_ROOT + end_ts
end: TIMESTAMP_ROOT + end_ts,
limit: limit
})
.on('data', function (data) {
list.push({

View File

@ -7,6 +7,7 @@ var TESTING_BLOCK0 = '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d7
var TESTING_BLOCK1 = '00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206';
var START_TS = 1;
var END_TS = '1296688928~'; // 2/2/2011 23:23PM
var LIMIT = 2;
var assert = require('assert'),
BlockDb = require('../../lib/BlockDb').class();
@ -23,7 +24,7 @@ describe('BlockDb getBlocksByDate', function(){
it('Get Hash by Date', function(done) {
bDb.getBlocksByDate(START_TS, END_TS, function(err, list) {
bDb.getBlocksByDate(START_TS, END_TS, LIMIT, function(err, list) {
if (err) done(err);
assert(list, 'returns list');
assert.equal(list.length,2, 'list has 2 items');