From fcb892f269115c1ad133a478adf6afc0e0a39acb Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Mon, 10 Feb 2014 19:11:13 -0300 Subject: [PATCH] fix homepage. fix streamed new txs. --- app/controllers/socket.js | 18 +++++++++++++++++- lib/HistoricSync.js | 2 +- lib/PeerSync.js | 2 +- lib/Sync.js | 6 ++---- public/src/js/controllers/index.js | 26 +++++++------------------- public/views/index.html | 18 ++++++++++-------- 6 files changed, 38 insertions(+), 34 deletions(-) diff --git a/app/controllers/socket.js b/app/controllers/socket.js index ec9ba60a..603c7ee1 100644 --- a/app/controllers/socket.js +++ b/app/controllers/socket.js @@ -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) { diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index 800587f5..4b8dcf3f 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -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; } diff --git a/lib/PeerSync.js b/lib/PeerSync.js index 091b50cc..828bb5df 100644 --- a/lib/PeerSync.js +++ b/lib/PeerSync.js @@ -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)); } diff --git a/lib/Sync.js b/lib/Sync.js index 67189538..d69bc120 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -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; diff --git a/public/src/js/controllers/index.js b/public/src/js/controllers/index.js index 0412c663..c76f85ef 100644 --- a/public/src/js/controllers/index.js +++ b/public/src/js/controllers/index.js @@ -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) { diff --git a/public/views/index.html b/public/views/index.html index a6fb7380..7856b4e5 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -28,18 +28,14 @@ -

About

-

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 source code.

- - -
-

Latest Transactions

+ +

Latest Transactions

- + @@ -49,11 +45,17 @@ - +
HashAgeSize Value Out
{{tx.txid}} {{humanSince(tx.time)}}{{tx.size}} {{tx.valueOut}}
+ +
+ +
+

About

+

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 source code.