show new blocks in homepage
This commit is contained in:
parent
fd90910fc5
commit
b6f4aa78bc
@ -18,3 +18,8 @@ module.exports.init = function(app, io_ext) {
|
|||||||
module.exports.broadcast_tx = function(tx) {
|
module.exports.broadcast_tx = function(tx) {
|
||||||
io.sockets.emit('tx', 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) {
|
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) {
|
Sync.prototype.storeTxs = function(txids, cb) {
|
||||||
|
|||||||
@ -1,14 +1,29 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var TRANSACTION_DISPLAYED = 5;
|
||||||
|
var BLOCKS_DISPLAYED = 5;
|
||||||
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'socket', function($scope, Global, socket) {
|
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'socket', function($scope, Global, socket) {
|
||||||
$scope.global = Global;
|
$scope.global = Global;
|
||||||
socket.on('tx', function(data) {
|
socket.on('tx', function(data) {
|
||||||
var tx = data;
|
var tx = data;
|
||||||
console.log('Transaction received! ' + tx.txid);
|
console.log('Transaction received! ' + tx);
|
||||||
$scope.txs.unshift(tx.txid);
|
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.txs = [];
|
||||||
|
$scope.blocks = [];
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,18 @@
|
|||||||
<section data-ng-controller="IndexController" data-ng-init="">
|
<section data-ng-controller="IndexController" data-ng-init="">
|
||||||
<div class="">
|
<div class="container">
|
||||||
<h3>New transactions</h3>
|
<div class="row">
|
||||||
<div class="alert alert-info fader" ng-repeat='tx in txs'>
|
<div class="col-md-6">
|
||||||
{{tx}}
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user