fix homepage. fix streamed new txs.
This commit is contained in:
parent
c5e651d714
commit
fcb892f269
|
@ -15,7 +15,23 @@ module.exports.init = function(app, io_ext) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.broadcastTx = function(tx) {
|
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) {
|
module.exports.broadcastBlock = function(block) {
|
||||||
|
|
|
@ -487,7 +487,7 @@ function spec() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p('Genesis block found. Syncing upto known blocks.');
|
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.reverse = true;
|
||||||
scanOpts.upToExisting = true;
|
scanOpts.upToExisting = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ function spec() {
|
||||||
var tx = info.message.tx.getStandardizedObject();
|
var tx = info.message.tx.getStandardizedObject();
|
||||||
console.log('[p2p_sync] Handle tx: ' + tx.hash);
|
console.log('[p2p_sync] Handle tx: ' + tx.hash);
|
||||||
|
|
||||||
this.sync.storeTxs([tx.hash], function(err) {
|
this.sync.storeTxs([tx], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('[p2p_sync] Error in handle TX: ' + JSON.stringify(err));
|
console.log('[p2p_sync] Error in handle TX: ' + JSON.stringify(err));
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ function spec() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var oldTip, oldNext, needReorg = false;
|
var oldTip, oldNext, needReorg = false;
|
||||||
var newPrev = b.previousblockhash;
|
var newPrev = b.previousblockhash;
|
||||||
var updatedTxs, updatedAddrs;
|
var updatedAddrs;
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
function(c) {
|
function(c) {
|
||||||
|
@ -97,7 +97,6 @@ function spec() {
|
||||||
},
|
},
|
||||||
function(c) {
|
function(c) {
|
||||||
self.txDb.createFromBlock(b, function(err, addrs) {
|
self.txDb.createFromBlock(b, function(err, addrs) {
|
||||||
updatedTxs = b.tx;
|
|
||||||
updatedAddrs = addrs;
|
updatedAddrs = addrs;
|
||||||
return c(err);
|
return c(err);
|
||||||
});
|
});
|
||||||
|
@ -125,7 +124,6 @@ function spec() {
|
||||||
function(c) {
|
function(c) {
|
||||||
if (!needReorg) return c();
|
if (!needReorg) return c();
|
||||||
console.log('NEW TIP: %s NEED REORG (old tip: %s)', b.hash, oldTip);
|
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);
|
self.processReorg(oldTip, oldNext, newPrev, c);
|
||||||
},
|
},
|
||||||
function(c) {
|
function(c) {
|
||||||
|
@ -137,7 +135,7 @@ function spec() {
|
||||||
});
|
});
|
||||||
}],
|
}],
|
||||||
function(err) {
|
function(err) {
|
||||||
if (!err) self._handleBroadcast(b.hash, updatedTxs, updatedAddrs);
|
if (!err) self._handleBroadcast(b.hash, null, updatedAddrs);
|
||||||
if (err && err.toString().match(/WARN/) ) {
|
if (err && err.toString().match(/WARN/) ) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
err=null;
|
err=null;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var TRANSACTION_DISPLAYED = 5;
|
var TRANSACTION_DISPLAYED = 10;
|
||||||
var BLOCKS_DISPLAYED = 5;
|
var BLOCKS_DISPLAYED = 5;
|
||||||
|
|
||||||
angular.module('insight.system').controller('IndexController',
|
angular.module('insight.system').controller('IndexController',
|
||||||
function($scope, $rootScope, Global, getSocket, Blocks, Transaction) {
|
function($scope, $rootScope, Global, getSocket, Blocks) {
|
||||||
$scope.global = Global;
|
$scope.global = Global;
|
||||||
|
|
||||||
var _getBlocks = function() {
|
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);
|
var socket = getSocket($scope);
|
||||||
socket.emit('subscribe', 'inv');
|
socket.emit('subscribe', 'inv');
|
||||||
|
|
||||||
|
@ -31,15 +23,11 @@ angular.module('insight.system').controller('IndexController',
|
||||||
$scope.flashMessage = $rootScope.flashMessage || null;
|
$scope.flashMessage = $rootScope.flashMessage || null;
|
||||||
|
|
||||||
socket.on('tx', function(tx) {
|
socket.on('tx', function(tx) {
|
||||||
console.log('Transaction received! ' + JSON.stringify(tx));
|
console.log('Transaction received! ' + tx.txid);
|
||||||
|
$scope.txs.unshift(tx);
|
||||||
var txStr = tx.toString();
|
if (parseInt($scope.txs.length, 10) >= parseInt(TRANSACTION_DISPLAYED, 10)) {
|
||||||
_getTransaction(txStr, function(res) {
|
$scope.txs = $scope.txs.splice(0, TRANSACTION_DISPLAYED);
|
||||||
$scope.txs.unshift(res);
|
}
|
||||||
if (parseInt($scope.txs.length, 10) >= parseInt(TRANSACTION_DISPLAYED, 10)) {
|
|
||||||
$scope.txs = $scope.txs.splice(0, TRANSACTION_DISPLAYED);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('block', function(block) {
|
socket.on('block', function(block) {
|
||||||
|
|
|
@ -28,18 +28,14 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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">
|
<h2>Latest Transactions</h2>
|
||||||
<h3>Latest Transactions</h3>
|
|
||||||
|
|
||||||
<table class="table" style="table-layout: fixed;">
|
<table class="table" style="table-layout: fixed;">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Hash</th>
|
<th>Hash</th>
|
||||||
<th>Age</th>
|
<th>Size</th>
|
||||||
<th>Value Out</th>
|
<th>Value Out</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -49,11 +45,17 @@
|
||||||
<td>
|
<td>
|
||||||
<a class="ellipsis" href="/tx/{{tx.txid}}">{{tx.txid}}</a>
|
<a class="ellipsis" href="/tx/{{tx.txid}}">{{tx.txid}}</a>
|
||||||
</td>
|
</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>
|
<td><span class="ellipsis">{{tx.valueOut}}</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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> <!-- END OF COL-3 -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue