diff --git a/app/views/sockets/main.js b/app/views/sockets/main.js index d4b0452..b8b3f52 100644 --- a/app/views/sockets/main.js +++ b/app/views/sockets/main.js @@ -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); +}; diff --git a/lib/Sync.js b/lib/Sync.js index 35c66ab..588e8d6 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -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) { diff --git a/public/js/controllers/index.js b/public/js/controllers/index.js index 06d4b7d..50738ae 100755 --- a/public/js/controllers/index.js +++ b/public/js/controllers/index.js @@ -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 = []; }]); diff --git a/public/views/index.html b/public/views/index.html index 09d5d07..e9192bb 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -1,8 +1,18 @@
-
-

New transactions

-
- {{tx}} +
+
+
+

New transactions

+ +
+
+

New blocks

+ +
diff --git a/server.js b/server.js index b7ded02..3c9aa54 100644 --- a/server.js +++ b/server.js @@ -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();