Merge branch 'feature/leveldb' of github.com:matiu/insight into feature/leveldb
This commit is contained in:
commit
52179a2f4e
|
@ -72,7 +72,7 @@ console.log('[blocks.js.60]: could not get %s from RPC. Orphan? Error?', blockha
|
||||||
* List of blocks by date
|
* List of blocks by date
|
||||||
*/
|
*/
|
||||||
exports.list = function(req, res) {
|
exports.list = function(req, res) {
|
||||||
var limit = req.query.limit || 0;
|
var limit = req.query.limit || -1;
|
||||||
var isToday = false;
|
var isToday = false;
|
||||||
|
|
||||||
//helper to convert timestamps to yyyy-mm-dd format
|
//helper to convert timestamps to yyyy-mm-dd format
|
||||||
|
@ -103,37 +103,27 @@ exports.list = function(req, res) {
|
||||||
var prev = formatTimestamp(new Date((gte - 86400) * 1000));
|
var prev = formatTimestamp(new Date((gte - 86400) * 1000));
|
||||||
var next = formatTimestamp(new Date(lte * 1000));
|
var next = formatTimestamp(new Date(lte * 1000));
|
||||||
|
|
||||||
/*
|
bdb.getBlocksByDate(gte, lte, limit, function(err, blocks) {
|
||||||
Block
|
if (err) {
|
||||||
.find({
|
res.status(500).send(err);
|
||||||
time: {
|
}
|
||||||
'$gte': gte,
|
else {
|
||||||
'$lte': lte
|
var blockshashList = [];
|
||||||
|
for(var i=0;i<blocks.length;i++) {
|
||||||
|
blockshashList.unshift(blocks[i].hash);
|
||||||
}
|
}
|
||||||
})
|
async.mapSeries(blockshashList, getBlock, function(err, allblocks) {
|
||||||
.limit(limit)
|
res.jsonp({
|
||||||
.sort('-time')
|
blocks: allblocks,
|
||||||
.exec(function(err, blocks) {
|
length: allblocks.length,
|
||||||
if (err) {
|
pagination: {
|
||||||
res.status(500).send(err);
|
next: next,
|
||||||
} else {
|
prev: prev,
|
||||||
var blockshashList = [];
|
current: dateStr,
|
||||||
for(var i=0;i<blocks.length;i++) {
|
isToday: isToday
|
||||||
blockshashList.push(blocks[i].hash);
|
}
|
||||||
}
|
|
||||||
async.mapSeries(blockshashList, getBlock, function(err, allblocks) {
|
|
||||||
res.jsonp({
|
|
||||||
blocks: allblocks,
|
|
||||||
length: allblocks.length,
|
|
||||||
pagination: {
|
|
||||||
next: next,
|
|
||||||
prev: prev,
|
|
||||||
current: dateStr,
|
|
||||||
isToday: isToday
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
*/
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -127,11 +127,13 @@ function spec(b) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
BlockDb.prototype.getBlocksByDate = function(start_ts, end_ts, cb) {
|
BlockDb.prototype.getBlocksByDate = function(start_ts, end_ts, limit, cb) {
|
||||||
var list = [];
|
var list = [];
|
||||||
db.createReadStream({
|
db.createReadStream({
|
||||||
start: TIMESTAMP_ROOT + start_ts,
|
start: TIMESTAMP_ROOT + start_ts,
|
||||||
end: TIMESTAMP_ROOT + end_ts
|
end: TIMESTAMP_ROOT + end_ts,
|
||||||
|
fillCache: true,
|
||||||
|
limit: parseInt(limit) // force to int
|
||||||
})
|
})
|
||||||
.on('data', function (data) {
|
.on('data', function (data) {
|
||||||
list.push({
|
list.push({
|
||||||
|
|
|
@ -20,11 +20,11 @@ angular.module('insight').config(function($routeProvider) {
|
||||||
title: 'Home'
|
title: 'Home'
|
||||||
}).
|
}).
|
||||||
when('/blocks', {
|
when('/blocks', {
|
||||||
templateUrl: '/views/blocks_list.html',
|
templateUrl: '/views/block_list.html',
|
||||||
title: 'Bitcoin Blocks solved Today'
|
title: 'Bitcoin Blocks solved Today'
|
||||||
}).
|
}).
|
||||||
when('/blocks-date/:blockDate', {
|
when('/blocks-date/:blockDate', {
|
||||||
templateUrl: '/views/blocks_list.html',
|
templateUrl: '/views/block_list.html',
|
||||||
title: 'Bitcoin Blocks solved '
|
title: 'Bitcoin Blocks solved '
|
||||||
}).
|
}).
|
||||||
when('/address/:addrStr', {
|
when('/address/:addrStr', {
|
||||||
|
|
|
@ -7,6 +7,7 @@ var TESTING_BLOCK0 = '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d7
|
||||||
var TESTING_BLOCK1 = '00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206';
|
var TESTING_BLOCK1 = '00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206';
|
||||||
var START_TS = 1;
|
var START_TS = 1;
|
||||||
var END_TS = '1296688928~'; // 2/2/2011 23:23PM
|
var END_TS = '1296688928~'; // 2/2/2011 23:23PM
|
||||||
|
var LIMIT = 2;
|
||||||
|
|
||||||
var assert = require('assert'),
|
var assert = require('assert'),
|
||||||
BlockDb = require('../../lib/BlockDb').class();
|
BlockDb = require('../../lib/BlockDb').class();
|
||||||
|
@ -23,7 +24,7 @@ describe('BlockDb getBlocksByDate', function(){
|
||||||
|
|
||||||
it('Get Hash by Date', function(done) {
|
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);
|
if (err) done(err);
|
||||||
assert(list, 'returns list');
|
assert(list, 'returns list');
|
||||||
assert.equal(list.length,2, 'list has 2 items');
|
assert.equal(list.length,2, 'list has 2 items');
|
||||||
|
|
Loading…
Reference in New Issue