show new blocks in homepage

This commit is contained in:
Manuel Araoz 2014-01-14 19:42:38 -03:00
parent fd90910fc5
commit b6f4aa78bc
5 changed files with 44 additions and 8 deletions

View File

@ -18,3 +18,8 @@ module.exports.init = function(app, io_ext) {
module.exports.broadcast_tx = function(tx) {
io.sockets.emit('tx', tx);
};
module.exports.broadcast_block = function(block) {
io.sockets.emit('block', block);
};

View File

@ -58,7 +58,12 @@ function spec() {
};
Sync.prototype.storeBlock = function(block, cb) {
Block.create(block, cb);
var that = this;
Block.create(block, function(err, b){
if (b && that.opts.broadcast_blocks) {
sockets.broadcast_block(b);
}
});
};
Sync.prototype.storeTxs = function(txids, cb) {

View File

@ -1,14 +1,29 @@
'use strict';
var TRANSACTION_DISPLAYED = 5;
var BLOCKS_DISPLAYED = 5;
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'socket', function($scope, Global, socket) {
$scope.global = Global;
socket.on('tx', function(data) {
var tx = data;
console.log('Transaction received! ' + tx.txid);
$scope.txs.unshift(tx.txid);
console.log('Transaction received! ' + tx);
if ($scope.txs.length === TRANSACTION_DISPLAYED) {
$scope.txs.pop();
}
$scope.txs.unshift(tx);
});
socket.on('block', function(data) {
var block = data;
console.log('Block received! ' + block);
if ($scope.blocks.length === BLOCKS_DISPLAYED) {
$scope.blocks.pop();
}
$scope.blocks.unshift(block);
});
$scope.txs = [];
$scope.blocks = [];
}]);

View File

@ -1,8 +1,18 @@
<section data-ng-controller="IndexController" data-ng-init="">
<div class="">
<h3>New transactions</h3>
<div class="alert alert-info fader" ng-repeat='tx in txs'>
{{tx}}
<div class="container">
<div class="row">
<div class="col-md-6">
<h3> New transactions </h3>
<div class="alert alert-info fader" ng-repeat='tx in txs'>
<a href="#!/tx/{{tx.txid}}">{{tx.txid}}</a>
</div>
</div>
<div class="col-md-6">
<h3> New blocks </h3>
<div class="alert alert-success fader" ng-repeat='b in blocks'>
<a href="#!/block/{{b.hash}}">{{b.hash}}</a>
</div>
</div>
</div>
</div>
</section>

View File

@ -44,7 +44,8 @@ walk(models_path);
var ps = new PeerSync();
ps.init({
skip_db_connection: true,
broadcast_txs: true
broadcast_txs: true,
broadcast_blocks: true
});
ps.run();