fix homepage. fix streamed new txs.

This commit is contained in:
Gustavo Cortez 2014-02-10 19:11:13 -03:00
parent c5e651d714
commit fcb892f269
6 changed files with 38 additions and 34 deletions

View File

@ -15,7 +15,23 @@ module.exports.init = function(app, io_ext) {
};
module.exports.broadcastTx = function(tx) {
if (ios) ios.sockets.in('inv').emit('tx', tx);
if (ios) {
var t = {};
if (typeof tx === 'string') {
t = { txid: tx };
}
else {
t = tx;
// Outputs
var valueOut = 0;
t.vout.forEach( function(o) {
valueOut += o.value * 100000000;
});
t.valueOut = valueOut / 100000000;
}
ios.sockets.in('inv').emit('tx', t);
}
};
module.exports.broadcastBlock = function(block) {

View File

@ -487,7 +487,7 @@ function spec() {
}
else {
p('Genesis block found. Syncing upto known blocks.');
p('Got %d out of %d blocks', count, self.blockChainHeight);
p('Got ' + count + ' out of ' + self.blockChainHeight + ' blocks');
scanOpts.reverse = true;
scanOpts.upToExisting = true;
}

View File

@ -53,7 +53,7 @@ function spec() {
var tx = info.message.tx.getStandardizedObject();
console.log('[p2p_sync] Handle tx: ' + tx.hash);
this.sync.storeTxs([tx.hash], function(err) {
this.sync.storeTxs([tx], function(err) {
if (err) {
console.log('[p2p_sync] Error in handle TX: ' + JSON.stringify(err));
}

View File

@ -77,7 +77,7 @@ function spec() {
var self = this;
var oldTip, oldNext, needReorg = false;
var newPrev = b.previousblockhash;
var updatedTxs, updatedAddrs;
var updatedAddrs;
async.series([
function(c) {
@ -97,7 +97,6 @@ function spec() {
},
function(c) {
self.txDb.createFromBlock(b, function(err, addrs) {
updatedTxs = b.tx;
updatedAddrs = addrs;
return c(err);
});
@ -125,7 +124,6 @@ function spec() {
function(c) {
if (!needReorg) return c();
console.log('NEW TIP: %s NEED REORG (old tip: %s)', b.hash, oldTip);
// TODO should modify updatedTxs and addrs.
self.processReorg(oldTip, oldNext, newPrev, c);
},
function(c) {
@ -137,7 +135,7 @@ function spec() {
});
}],
function(err) {
if (!err) self._handleBroadcast(b.hash, updatedTxs, updatedAddrs);
if (!err) self._handleBroadcast(b.hash, null, updatedAddrs);
if (err && err.toString().match(/WARN/) ) {
console.log(err);
err=null;

View File

@ -1,10 +1,10 @@
'use strict';
var TRANSACTION_DISPLAYED = 5;
var TRANSACTION_DISPLAYED = 10;
var BLOCKS_DISPLAYED = 5;
angular.module('insight.system').controller('IndexController',
function($scope, $rootScope, Global, getSocket, Blocks, Transaction) {
function($scope, $rootScope, Global, getSocket, Blocks) {
$scope.global = Global;
var _getBlocks = function() {
@ -16,14 +16,6 @@ angular.module('insight.system').controller('IndexController',
});
};
var _getTransaction = function(txid, cb) {
Transaction.get({
txId: txid
}, function(res) {
cb(res);
});
};
var socket = getSocket($scope);
socket.emit('subscribe', 'inv');
@ -31,15 +23,11 @@ angular.module('insight.system').controller('IndexController',
$scope.flashMessage = $rootScope.flashMessage || null;
socket.on('tx', function(tx) {
console.log('Transaction received! ' + JSON.stringify(tx));
var txStr = tx.toString();
_getTransaction(txStr, function(res) {
$scope.txs.unshift(res);
if (parseInt($scope.txs.length, 10) >= parseInt(TRANSACTION_DISPLAYED, 10)) {
$scope.txs = $scope.txs.splice(0, TRANSACTION_DISPLAYED);
}
});
console.log('Transaction received! ' + tx.txid);
$scope.txs.unshift(tx);
if (parseInt($scope.txs.length, 10) >= parseInt(TRANSACTION_DISPLAYED, 10)) {
$scope.txs = $scope.txs.splice(0, TRANSACTION_DISPLAYED);
}
});
socket.on('block', function(block) {

View File

@ -28,18 +28,14 @@
</tr>
</tbody>
</table>
<h2> About </h2>
<p class="text-muted">Insight is a bitcoin blockchain API for writing web wallets and other apps that need more advanced blockchain queries than provided by bitcoind RPC. Check out the <a href="http://github.com/bitpay/insight" target="_blank">source code</a>.</p>
</div>
<div class="col-xs-12 col-md-4 col-gray">
<h3>Latest Transactions</h3>
<h2>Latest Transactions</h2>
<table class="table" style="table-layout: fixed;">
<thead>
<tr>
<th>Hash</th>
<th>Age</th>
<th>Size</th>
<th>Value Out</th>
</tr>
</thead>
@ -49,11 +45,17 @@
<td>
<a class="ellipsis" href="/tx/{{tx.txid}}">{{tx.txid}}</a>
</td>
<td><span class="ellipsis">{{humanSince(tx.time)}}</span></td>
<td><span class="ellipsis">{{tx.size}}</span></td>
<td><span class="ellipsis">{{tx.valueOut}}</span></td>
</tr>
</tbody>
</table>
</div>
<div class="col-xs-12 col-md-4 col-gray">
<h2> About </h2>
<p>Insight is a bitcoin blockchain API for writing web wallets and other apps that need more advanced blockchain queries than provided by bitcoind RPC. Check out the <a href="http://github.com/bitpay/insight" target="_blank">source code</a>.</p>
</div> <!-- END OF COL-3 -->
</div>
</div>