Merge pull request #45 from maraoz/feature/stream-blocks
show new blocks in homepage < Nice!
This commit is contained in:
commit
162e989b65
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 = [];
|
||||
|
||||
}]);
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue