diff --git a/public/js/controllers/address.js b/public/js/controllers/address.js index 016da8b..9b46cba 100644 --- a/public/js/controllers/address.js +++ b/public/js/controllers/address.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('insight.address').controller('AddressController', -function($scope, $rootScope, $routeParams, $location, Global, Address, get_socket) { +function($scope, $rootScope, $routeParams, $location, Global, Address, getSocket) { $scope.global = Global; $scope.findOne = function() { @@ -24,7 +24,8 @@ function($scope, $rootScope, $routeParams, $location, Global, Address, get_socke $location.path('/'); }); }; - var socket = get_socket($scope); + + var socket = getSocket($scope); socket.emit('subscribe', $routeParams.addrStr); socket.on($routeParams.addrStr, function(tx) { console.log('atx ' + tx.txid); @@ -33,7 +34,6 @@ function($scope, $rootScope, $routeParams, $location, Global, Address, get_socke $rootScope.$broadcast('tx', tx.txid); }); - $scope.params = $routeParams; -}); +}); diff --git a/public/js/controllers/blocks.js b/public/js/controllers/blocks.js index 2013db3..f599b7e 100644 --- a/public/js/controllers/blocks.js +++ b/public/js/controllers/blocks.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('insight.blocks').controller('BlocksController', - function ($scope, $rootScope, $routeParams, $location, Global, Block, Blocks, BlockByHeight) { + function($scope, $rootScope, $routeParams, $location, Global, Block, Blocks, BlockByHeight) { $scope.global = Global; if ($routeParams.blockHeight) { @@ -44,4 +44,5 @@ angular.module('insight.blocks').controller('BlocksController', }; $scope.params = $routeParams; + }); diff --git a/public/js/controllers/footer.js b/public/js/controllers/footer.js index 354f584..6aa1d87 100644 --- a/public/js/controllers/footer.js +++ b/public/js/controllers/footer.js @@ -1,15 +1,15 @@ 'use strict'; angular.module('insight.system').controller('FooterController', - function ($scope, get_socket, Version) { + function($scope, Version) { - var getVersion = function() { + var _getVersion = function() { Version.get({}, function(res) { $scope.version = res.version; }); }; - $scope.version = getVersion(); + $scope.version = _getVersion(); }); diff --git a/public/js/controllers/header.js b/public/js/controllers/header.js index 08659e7..0fc60c8 100755 --- a/public/js/controllers/header.js +++ b/public/js/controllers/header.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('insight.system').controller('HeaderController', - function ($scope, get_socket, Global, Block) { + function($scope, getSocket, Global, Block) { $scope.global = Global; $scope.menu = [ @@ -15,10 +15,10 @@ angular.module('insight.system').controller('HeaderController', } ]; - var socket = get_socket($scope); + var socket = getSocket($scope); socket.emit('subscribe', 'inv'); - var getBlock = function(hash) { + var _getBlock = function(hash) { Block.get({ blockHash: hash }, function(res) { @@ -29,7 +29,7 @@ angular.module('insight.system').controller('HeaderController', socket.on('block', function(block) { var blockHash = block.hash.toString(); console.log('Updated Blocks Height!'); - getBlock(blockHash); + _getBlock(blockHash); }); diff --git a/public/js/controllers/index.js b/public/js/controllers/index.js index 8879afb..a45fa2f 100755 --- a/public/js/controllers/index.js +++ b/public/js/controllers/index.js @@ -2,11 +2,12 @@ var TRANSACTION_DISPLAYED = 5; var BLOCKS_DISPLAYED = 5; + angular.module('insight.system').controller('IndexController', - function($scope, $rootScope, Global, get_socket, Blocks, Block, Transactions, Transaction) { + function($scope, $rootScope, Global, getSocket, Blocks, Block, Transactions, Transaction) { $scope.global = Global; - var getTransaction = function(txid) { + var _getTransaction = function(txid) { Transaction.get({ txId: txid }, function(res) { @@ -14,7 +15,7 @@ angular.module('insight.system').controller('IndexController', }); }; - var getBlock = function(hash) { + var _getBlock = function(hash) { Block.get({ blockHash: hash }, function(res) { @@ -22,7 +23,7 @@ angular.module('insight.system').controller('IndexController', }); }; - var socket = get_socket($scope); + var socket = getSocket($scope); socket.emit('subscribe', 'inv'); //show errors @@ -31,22 +32,24 @@ angular.module('insight.system').controller('IndexController', socket.on('tx', function(tx) { var txStr = tx.txid.toString(); console.log('Transaction received! ' + JSON.stringify(tx)); - if (parseInt($scope.txs.length) > parseInt(TRANSACTION_DISPLAYED) - 1) { + if (parseInt($scope.txs.length, 10) > parseInt(TRANSACTION_DISPLAYED, 10) - 1) { $scope.txs.pop(); } - getTransaction(txStr); + + _getTransaction(txStr); }); socket.on('block', function(block) { var blockHash = block.hash.toString(); console.log('Block received! ' + JSON.stringify(block)); - if (parseInt($scope.blocks.length) > parseInt(BLOCKS_DISPLAYED) - 1) { + if (parseInt($scope.blocks.length, 10) > parseInt(BLOCKS_DISPLAYED, 10) - 1) { $scope.blocks.pop(); } - getBlock(blockHash); + + _getBlock(blockHash); }); - $scope.human_since = function(time) { + $scope.humanSince = function(time) { var m = moment.unix(time); return m.max().fromNow(); }; diff --git a/public/js/controllers/search.js b/public/js/controllers/search.js index 07af17b..eef77c5 100644 --- a/public/js/controllers/search.js +++ b/public/js/controllers/search.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('insight.search').controller('SearchController', - function ($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) { + function($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) { $scope.global = Global; $scope.search = function() { @@ -36,8 +36,8 @@ angular.module('insight.search').controller('SearchController', }, 2000); $scope.q = q; }); - }); - }); + }); + }); }); }; diff --git a/public/js/controllers/status.js b/public/js/controllers/status.js index 56c823a..7054480 100644 --- a/public/js/controllers/status.js +++ b/public/js/controllers/status.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('insight.status').controller('StatusController', -function($scope, $routeParams, $location, $rootScope, Global, Status, Sync, get_socket) { +function($scope, $routeParams, $location, $rootScope, Global, Status, Sync, getSocket) { $scope.global = Global; $scope.getStatus = function(q) { @@ -22,25 +22,25 @@ function($scope, $routeParams, $location, $rootScope, Global, Status, Sync, get_ }); }; - var on_sync_update = function(sync) { + var _onSyncUpdate = function(sync) { $scope.sync = sync; }; $scope.getSync = function() { Sync.get({}, function(sync) { - on_sync_update(sync); + _onSyncUpdate(sync); }, function(e) { $scope.sync = { error: 'Could not get sync information' + e }; }); }; - var socket = get_socket($scope); + var socket = getSocket($scope); socket.emit('subscribe', 'sync'); socket.on('status', function(sync) { -console.log('[status.js.55::] sync status update received!'); - on_sync_update(sync); + console.log('[status.js.55::] sync status update received!'); + _onSyncUpdate(sync); }); }); diff --git a/public/js/controllers/transactions.js b/public/js/controllers/transactions.js index 05d54ff..0fcbbcb 100644 --- a/public/js/controllers/transactions.js +++ b/public/js/controllers/transactions.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('insight.transactions').controller('transactionsController', -function ($scope, $rootScope, $routeParams, $location, Global, Transaction, TransactionsByBlock, TransactionsByAddress) { +function($scope, $rootScope, $routeParams, $location, Global, Transaction, TransactionsByBlock, TransactionsByAddress) { $scope.global = Global; $scope.loading = false; $scope.loadedBy = null; @@ -9,18 +9,15 @@ function ($scope, $rootScope, $routeParams, $location, Global, Transaction, Tran var pageNum = 0; var pagesTotal = 1; - $scope.findThis = function() { - $scope.findTx($routeParams.txId); - }; - - $scope.aggregateItems = function(items) { + var _aggregateItems = function(items) { if (!items) return []; var l = items.length; var ret = []; var tmp = {}; - var u=0; + var u = 0; + // TODO multiple output address // for(var i=0; i < l; i++) { @@ -29,14 +26,14 @@ function ($scope, $rootScope, $routeParams, $location, Global, Transaction, Tran // non standard input if (items[i].scriptSig && !items[i].addr) { - items[i].addr = 'Unparsed address [' + u++ + ']'; + items[i].addr = 'Unparsed address [' + u++ + ']'; items[i].notAddr = true; notAddr = true; } // non standard output if (items[i].scriptPubKey && !items[i].scriptPubKey.addresses) { - items[i].scriptPubKey.addresses = ['Unparsed address [' + u++ + ']']; + items[i].scriptPubKey.addresses = ['Unparsed address [' + u++ + ']']; items[i].notAddr = true; notAddr = true; } @@ -48,7 +45,7 @@ function ($scope, $rootScope, $routeParams, $location, Global, Transaction, Tran continue; } - var addr = items[i].addr || (items[i].scriptPubKey && items[i].scriptPubKey.addresses[0] ); + var addr = items[i].addr || (items[i].scriptPubKey && items[i].scriptPubKey.addresses[0]); if (!tmp[addr]) { tmp[addr] = {}; @@ -57,6 +54,7 @@ function ($scope, $rootScope, $routeParams, $location, Global, Transaction, Tran tmp[addr].addr = addr; tmp[addr].items = []; } + tmp[addr].valueSat += items[i].valueSat; tmp[addr].value = tmp[addr].valueSat / 100000000; tmp[addr].items.push(items[i]); @@ -67,12 +65,47 @@ function ($scope, $rootScope, $routeParams, $location, Global, Transaction, Tran angular.forEach(tmp, function(v) { ret.push(v); }); - return (ret); + + return ret; }; - $scope.processTX = function(tx) { - tx.vinSimple = $scope.aggregateItems(tx.vin); - tx.voutSimple = $scope.aggregateItems(tx.vout); + var _processTX = function(tx) { + tx.vinSimple = _aggregateItems(tx.vin); + tx.voutSimple = _aggregateItems(tx.vout); + }; + + var _paginate = function (data) { + $scope.loading = false; + + pagesTotal = data.pagesTotal; + pageNum += 1; + + data.txs.forEach(function(tx) { + _processTX(tx); + $scope.txs.push(tx); + }); + }; + + var _byBlock = function() { + TransactionsByBlock.get({ + block: $routeParams.blockHash, + pageNum: pageNum + }, function(data) { + _paginate(data); + }); + }; + + var _byAddress = function () { + TransactionsByAddress.get({ + address: $routeParams.addrStr, + pageNum: pageNum + }, function(data) { + _paginate(data); + }); + }; + + $scope.findThis = function() { + $scope.findTx($routeParams.txId); }; $scope.findTx = function(txid) { @@ -80,7 +113,7 @@ function ($scope, $rootScope, $routeParams, $location, Global, Transaction, Tran txId: txid }, function(tx) { $scope.tx = tx; - $scope.processTX(tx); + _processTX(tx); $scope.txs.unshift(tx); }, function(e) { if (e.status === 400) { @@ -92,58 +125,32 @@ function ($scope, $rootScope, $routeParams, $location, Global, Transaction, Tran else { $rootScope.flashMessage = 'Transaction Not Found'; } + $location.path('/'); }); }; - $scope.byBlock = function() { - TransactionsByBlock.get({ - block: $routeParams.blockHash, - pageNum: pageNum - }, function(data) { - $scope.paginate(data); - }); - }; - - $scope.byAddress = function () { - TransactionsByAddress.get({ - address: $routeParams.addrStr, - pageNum: pageNum - }, function(data) { - $scope.paginate(data); - }); - }; - - $scope.paginate = function (data) { - $scope.loading = false; - - pagesTotal = data.pagesTotal; - pageNum += 1; - - data.txs.forEach(function(tx) { - $scope.processTX(tx); - $scope.txs.push(tx); - }); - }; - + //Initial load $scope.load = function(from) { $scope.loadedBy = from; $scope.loadMore(); }; + //Load more transactions for pagination $scope.loadMore = function() { if (pageNum < pagesTotal && !$scope.loading) { $scope.loading = true; if ($scope.loadedBy === 'address') { - $scope.byAddress(); + _byAddress(); } else { - $scope.byBlock(); + _byBlock(); } } }; + //Init without txs $scope.txs = []; $scope.$on('tx', function(event, txid) { diff --git a/public/js/init.js b/public/js/init.js index 51e012e..5f49071 100755 --- a/public/js/init.js +++ b/public/js/init.js @@ -1,9 +1,6 @@ 'use strict'; angular.element(document).ready(function() { - //Fixing facebook bug with redirect - if (window.location.hash === '#_=_') window.location.hash = '#!'; - //Then init the app angular.bootstrap(document, ['insight']); }); diff --git a/public/js/services/blocks.js b/public/js/services/blocks.js index 12d1da1..aa89df5 100644 --- a/public/js/services/blocks.js +++ b/public/js/services/blocks.js @@ -1,33 +1,31 @@ 'use strict'; -angular.module('insight.blocks').factory('Block', - function($resource) { - return $resource('/api/block/:blockHash', { - blockHash: '@blockHash' - }, { - get: { - method: 'GET', - interceptor: { - response: function (res) { - return res.data; - }, - responseError: function (res) { - if (res.status === 404) { - return res; +angular.module('insight.blocks') + .factory('Block', + function($resource) { + return $resource('/api/block/:blockHash', { + blockHash: '@blockHash' + }, { + get: { + method: 'GET', + interceptor: { + response: function (res) { + return res.data; + }, + responseError: function (res) { + if (res.status === 404) { + return res; + } } } } - } + }); + }) + .factory('Blocks', + function($resource) { + return $resource('/api/blocks'); + }) + .factory('BlockByHeight', + function($resource) { + return $resource('/api/block-index/:blockHeight'); }); -}); - -angular.module('insight.blocks').factory('Blocks', - function($resource) { - return $resource('/api/blocks'); -}); - -angular.module('insight.blocks').factory('BlockByHeight', - function($resource) { - return $resource('/api/block-index/:blockHeight'); -}); - diff --git a/public/js/services/global.js b/public/js/services/global.js index f78c621..4bbd022 100755 --- a/public/js/services/global.js +++ b/public/js/services/global.js @@ -1,13 +1,12 @@ 'use strict'; //Global service for global variables -angular.module('insight.system').factory('Global',[ +angular.module('insight.system') + .factory('Global',[ function() { } -]); - -angular.module('insight.system').factory('Version', - function($resource) { - return $resource('/api/version'); -}); - + ]) + .factory('Version', + function($resource) { + return $resource('/api/version'); + }); diff --git a/public/js/services/socket.js b/public/js/services/socket.js index b1efff4..9a2d459 100644 --- a/public/js/services/socket.js +++ b/public/js/services/socket.js @@ -46,7 +46,7 @@ ScopedSocket.prototype.emit = function(event, data, callback) { }); }; -angular.module('insight.socket').factory('get_socket', +angular.module('insight.socket').factory('getSocket', function($rootScope) { var socket = io.connect(); return function(scope) { @@ -59,4 +59,3 @@ function($rootScope) { return scopedSocket; }; }); - diff --git a/public/js/services/status.js b/public/js/services/status.js index eb80762..e8f0f24 100644 --- a/public/js/services/status.js +++ b/public/js/services/status.js @@ -1,14 +1,13 @@ 'use strict'; -angular.module('insight.status').factory('Status', - function($resource) { - return $resource('/api/status', { - q: '@q' +angular.module('insight.status') + .factory('Status', + function($resource) { + return $resource('/api/status', { + q: '@q' + }); + }) + .factory('Sync', + function($resource) { + return $resource('/api/sync'); }); -}); - -angular.module('insight.status').factory('Sync', - function($resource) { - return $resource('/api/sync'); -}); - diff --git a/public/js/services/transactions.js b/public/js/services/transactions.js index 2520246..d1243ea 100644 --- a/public/js/services/transactions.js +++ b/public/js/services/transactions.js @@ -1,41 +1,39 @@ 'use strict'; -angular.module('insight.transactions').factory('Transaction', - function($resource) { - return $resource('/api/tx/:txId', { - txId: '@txId' - }, { - get: { - method: 'GET', - interceptor: { - response: function (res) { - return res.data; - }, - responseError: function (res) { - if (res.status === 404) { - return res; +angular.module('insight.transactions') + .factory('Transaction', + function($resource) { + return $resource('/api/tx/:txId', { + txId: '@txId' + }, { + get: { + method: 'GET', + interceptor: { + response: function (res) { + return res.data; + }, + responseError: function (res) { + if (res.status === 404) { + return res; + } } } } - } + }); + }) + .factory('TransactionsByBlock', + function($resource) { + return $resource('/api/txs', { + block: '@block' + }); + }) + .factory('TransactionsByAddress', + function($resource) { + return $resource('/api/txs', { + address: '@address' + }); + }) + .factory('Transactions', + function($resource) { + return $resource('/api/txs'); }); -}); - -angular.module('insight.transactions').factory('TransactionsByBlock', - function($resource) { - return $resource('/api/txs', { - block: '@block' - }); -}); - -angular.module('insight.transactions').factory('TransactionsByAddress', - function($resource) { - return $resource('/api/txs', { - address: '@address' - }); -}); - -angular.module('insight.transactions').factory('Transactions', - function($resource) { - return $resource('/api/txs'); -}); diff --git a/public/views/index.html b/public/views/index.html index 0c8c850..0a9dca8 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -22,7 +22,7 @@ {{b.height}} - {{human_since(b.time)}} + {{humanSince(b.time)}} {{b.tx.length}} {{b.size}} {{b.confirmations}} @@ -53,7 +53,7 @@ {{tx.txid}} - {{human_since(tx.time)}} + {{humanSince(tx.time)}} {{tx.valueOut}} @@ -61,28 +61,28 @@

Other Bitcoin Links

diff --git a/public/views/transaction/list.html b/public/views/transaction/list.html index 1df90c3..76bf5b4 100644 --- a/public/views/transaction/list.html +++ b/public/views/transaction/list.html @@ -1,8 +1,8 @@ -
There are not transactions
+
There are not transactions
-
+
Loading...