Merge pull request #209 from cmgustavo/feature/01streamed
Feature/01streamed
This commit is contained in:
commit
e00b5edf48
|
@ -72,7 +72,6 @@ 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 || -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,14 +102,18 @@ 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) {
|
bdb.getBlocksByDate(gte, lte, function(err, blocks) {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(500).send(err);
|
res.status(500).send(err);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var blockshashList = [];
|
var blockshashList = [];
|
||||||
for(var i=0;i<blocks.length;i++) {
|
var limit = parseInt(req.query.limit || blocks.length);
|
||||||
blockshashList.unshift(blocks[i].hash);
|
if (blocks.length < limit) {
|
||||||
|
limit = blocks.length;
|
||||||
|
}
|
||||||
|
for(var i=0;i<limit;i++) {
|
||||||
|
blockshashList.push(blocks[i].hash);
|
||||||
}
|
}
|
||||||
async.mapSeries(blockshashList, getBlock, function(err, allblocks) {
|
async.mapSeries(blockshashList, getBlock, function(err, allblocks) {
|
||||||
res.jsonp({
|
res.jsonp({
|
||||||
|
|
|
@ -153,13 +153,12 @@ function spec(b) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
BlockDb.prototype.getBlocksByDate = function(start_ts, end_ts, limit, cb) {
|
BlockDb.prototype.getBlocksByDate = function(start_ts, end_ts, cb) {
|
||||||
var list = [];
|
var list = [];
|
||||||
db.createReadStream({
|
db.createReadStream({
|
||||||
start: TIMESTAMP_PREFIX + start_ts,
|
start: TIMESTAMP_PREFIX + start_ts,
|
||||||
end: TIMESTAMP_PREFIX + end_ts,
|
end: TIMESTAMP_PREFIX + end_ts,
|
||||||
fillCache: true,
|
fillCache: true
|
||||||
limit: parseInt(limit) // force to int
|
|
||||||
})
|
})
|
||||||
.on('data', function (data) {
|
.on('data', function (data) {
|
||||||
list.push({
|
list.push({
|
||||||
|
@ -171,7 +170,7 @@ function spec(b) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
})
|
})
|
||||||
.on('end', function () {
|
.on('end', function () {
|
||||||
return cb(null, list);
|
return cb(null, list.reverse());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ function spec(b) {
|
||||||
var RpcClient = require('bitcore/RpcClient').class(),
|
var RpcClient = require('bitcore/RpcClient').class(),
|
||||||
// networks = require('bitcore/network'),
|
// networks = require('bitcore/network'),
|
||||||
BitcoreTransaction = require('bitcore/Transaction').class(),
|
BitcoreTransaction = require('bitcore/Transaction').class(),
|
||||||
BitcoreBlock = require('bitcore/Block').class(),
|
// BitcoreBlock = require('bitcore/Block').class(),
|
||||||
util = require('bitcore/util/util'),
|
// util = require('bitcore/util/util'),
|
||||||
config = require('../config/config');
|
config = require('../config/config');
|
||||||
|
|
||||||
var rpc = b.rpc || new RpcClient(config.bitcoind);
|
var rpc = b.rpc || new RpcClient(config.bitcoind);
|
||||||
|
|
|
@ -4,9 +4,18 @@ var TRANSACTION_DISPLAYED = 5;
|
||||||
var BLOCKS_DISPLAYED = 5;
|
var BLOCKS_DISPLAYED = 5;
|
||||||
|
|
||||||
angular.module('insight.system').controller('IndexController',
|
angular.module('insight.system').controller('IndexController',
|
||||||
function($scope, $rootScope, Global, getSocket, Blocks, Block, Transactions, Transaction) {
|
function($scope, $rootScope, Global, getSocket, Blocks, Transaction) {
|
||||||
$scope.global = Global;
|
$scope.global = Global;
|
||||||
|
|
||||||
|
var _getBlocks = function() {
|
||||||
|
Blocks.get({
|
||||||
|
limit: BLOCKS_DISPLAYED
|
||||||
|
}, function(res) {
|
||||||
|
$scope.blocks = res.blocks;
|
||||||
|
$scope.blocksLength = res.lenght;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var _getTransaction = function(txid, cb) {
|
var _getTransaction = function(txid, cb) {
|
||||||
Transaction.get({
|
Transaction.get({
|
||||||
txId: txid
|
txId: txid
|
||||||
|
@ -15,14 +24,6 @@ angular.module('insight.system').controller('IndexController',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var _getBlock = function(hash) {
|
|
||||||
Block.get({
|
|
||||||
blockHash: hash
|
|
||||||
}, function(res) {
|
|
||||||
$scope.blocks.unshift(res);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var socket = getSocket($scope);
|
var socket = getSocket($scope);
|
||||||
socket.emit('subscribe', 'inv');
|
socket.emit('subscribe', 'inv');
|
||||||
|
|
||||||
|
@ -42,14 +43,9 @@ angular.module('insight.system').controller('IndexController',
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('block', function(block) {
|
socket.on('block', function(block) {
|
||||||
console.log('Block received! ' + JSON.stringify(block));
|
|
||||||
|
|
||||||
var blockHash = block.toString();
|
var blockHash = block.toString();
|
||||||
if (parseInt($scope.blocks.length, 10) > parseInt(BLOCKS_DISPLAYED, 10) - 1) {
|
console.log('Block received! ' + JSON.stringify(blockHash));
|
||||||
$scope.blocks.pop();
|
_getBlocks();
|
||||||
}
|
|
||||||
|
|
||||||
_getBlock(blockHash);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.humanSince = function(time) {
|
$scope.humanSince = function(time) {
|
||||||
|
@ -58,18 +54,7 @@ angular.module('insight.system').controller('IndexController',
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.index = function() {
|
$scope.index = function() {
|
||||||
Blocks.get({
|
_getBlocks();
|
||||||
limit: BLOCKS_DISPLAYED
|
|
||||||
}, function(res) {
|
|
||||||
$scope.blocks = res.blocks;
|
|
||||||
$scope.blocksLength = res.lenght;
|
|
||||||
});
|
|
||||||
|
|
||||||
Transactions.get({
|
|
||||||
limit: TRANSACTION_DISPLAYED
|
|
||||||
}, function(res) {
|
|
||||||
$scope.txs = res.txs;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.txs = [];
|
$scope.txs = [];
|
||||||
|
|
|
@ -46,13 +46,13 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr data-ng-show="!txs.length"><td colspan="5">Waiting for transactions...</td></tr>
|
<tr data-ng-show="!txs.length"><td colspan="3">Waiting for transactions...</td></tr>
|
||||||
<tr class="fader" data-ng-repeat='tx in txs'>
|
<tr class="fader" data-ng-repeat='tx in txs'>
|
||||||
<td>
|
<td>
|
||||||
<a class="ellipsis" href="/tx/{{tx.txid}}">{{tx.txid}}</a>
|
<a class="ellipsis" href="/tx/{{tx.txid}}">{{tx.txid}}</a>
|
||||||
</td>
|
</td>
|
||||||
<td><span class="ellipsis">{{humanSince(tx.time)}}</span></td>
|
<td><span class="ellipsis">{{humanSince(tx.time)}}</span></td>
|
||||||
<td>{{tx.valueOut}}</td>
|
<td><span class="ellipsis">{{tx.valueOut}}</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -3,11 +3,10 @@
|
||||||
|
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
var TESTING_BLOCK0 = '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943';
|
var TESTING_BLOCK0 = '00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206';
|
||||||
var TESTING_BLOCK1 = '00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206';
|
var TESTING_BLOCK1 = '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943';
|
||||||
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();
|
||||||
|
@ -24,7 +23,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, LIMIT, function(err, list) {
|
bDb.getBlocksByDate(START_TS, END_TS, 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