From 36c3466f32499d7e1b8aae40926c06163e11c947 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Tue, 21 Jan 2014 17:58:29 -0300 Subject: [PATCH 1/5] API: get all info about blocks and transactions in list methods. Fix transaction list on homepage --- app/controllers/blocks.js | 38 ++++++++++++++++++++++++--------- app/controllers/transactions.js | 24 +++++++++++++++++++++ public/js/controllers/index.js | 6 +++--- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/app/controllers/blocks.js b/app/controllers/blocks.js index b41b67f..a0d2d1e 100644 --- a/app/controllers/blocks.js +++ b/app/controllers/blocks.js @@ -3,9 +3,10 @@ /** * Module dependencies. */ -var mongoose = require('mongoose'), - Block = mongoose.model('Block'), - common = require('./common'); +var mongoose = require('mongoose'), + Block = mongoose.model('Block'), + common = require('./common'), + async = require('async'); /** @@ -47,6 +48,16 @@ exports.blockindex = function(req, res, next, height) { }); }; +var getBlock = function(blockhash, cb) { + Block.fromHashWithInfo(blockhash, function(err, block) { + if (err) { + console.log(err); + return cb(err); + } + return cb(err, block.info); + }); +}; + /** * List of blocks by date */ @@ -89,13 +100,20 @@ exports.list = function(req, res) { if (err) { res.status(500).send(err); } else { - res.jsonp({ - blocks: blocks, - pagination: { - next: next, - prev: prev, - current: dateStr - } + var blockshash = []; + for(var i=0;i Date: Tue, 21 Jan 2014 18:38:02 -0300 Subject: [PATCH 2/5] homepage: show blocks and transactions --- public/views/index.html | 65 ++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/public/views/index.html b/public/views/index.html index 0e4de2b..7ae3dda 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -4,21 +4,58 @@
-
-

New transactions

- +
+

Blocks

+ + + + + + + + + + + + + + + + + + + + +
HeightAgeTransactionsSizeConfirmations
Loading...
+ {{b.height}} + {{human_since(b.time)}}{{b.tx.length}}{{b.size}}{{b.confirmations}}
+
-
-

New blocks

- + +
+

Transactions

+ + + + + + + + + + + + + + + + + + + +
HashAgeValue OutSize
Loading...
+ {{tx.txid}} + {{human_since(tx.time)}}{{tx.valueOut}}{{tx.size}}
From 13c9d0075a4c0c6b2397bcb52a97b4f8e3be7c4f Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Tue, 21 Jan 2014 23:15:44 -0300 Subject: [PATCH 3/5] fixed lasts conflicts in block/list --- public/js/controllers/header.js | 20 +++++++++++++++++++- public/js/controllers/index.js | 31 +++++++++++++++++++++++++------ public/views/blocks/list.html | 30 ++++++++++++++++++++++-------- public/views/header.html | 2 +- public/views/index.html | 5 ++--- 5 files changed, 69 insertions(+), 19 deletions(-) diff --git a/public/js/controllers/header.js b/public/js/controllers/header.js index 8b3b4f7..ec3e878 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, Global) { + function ($scope, get_socket, Global, Block) { $scope.global = Global; $scope.menu = [ @@ -15,5 +15,23 @@ angular.module('insight.system').controller('HeaderController', } ]; + var socket = get_socket($scope); + socket.emit('subscribe', 'inv'); + + var getBlock = function(hash) { + Block.get({ + blockHash: hash + }, function(res) { + $scope.totalBlocks = res.height; + }); + }; + + socket.on('block', function(block) { + var blockHash = block.hash.toString(); + console.log('Update Height'); + getBlock(blockHash); + }); + + $scope.isCollapsed = false; }); diff --git a/public/js/controllers/index.js b/public/js/controllers/index.js index bd1cdcd..7621cbf 100755 --- a/public/js/controllers/index.js +++ b/public/js/controllers/index.js @@ -3,9 +3,25 @@ var TRANSACTION_DISPLAYED = 5; var BLOCKS_DISPLAYED = 5; angular.module('insight.system').controller('IndexController', - function($scope, $rootScope, Global, get_socket, Blocks, Transactions) { + function($scope, $rootScope, Global, get_socket, Blocks, Block, Transactions, Transaction) { $scope.global = Global; + var getTransaction = function(txid) { + Transaction.get({ + txId: txid + }, function(res) { + $scope.txs.unshift(res); + }); + }; + + var getBlock = function(hash) { + Block.get({ + blockHash: hash + }, function(res) { + $scope.blocks.unshift(res); + }); + }; + var socket = get_socket($scope); socket.emit('subscribe', 'inv'); @@ -13,19 +29,21 @@ angular.module('insight.system').controller('IndexController', $scope.flashMessage = $rootScope.flashMessage || null; socket.on('tx', function(tx) { + var txStr = tx.txid.toString(); console.log('Transaction received! ' + JSON.stringify(tx)); if ($scope.txs.length === TRANSACTION_DISPLAYED) { $scope.txs.pop(); } - $scope.txs.unshift(tx); + getTransaction(txStr); }); socket.on('block', function(block) { + var blockHash = block.hash.toString(); console.log('Block received! ' + JSON.stringify(block)); - if ($scope.blocks.length === BLOCKS_DISPLAYED) { - $scope.blocks.pop(); - } - $scope.blocks.unshift(block); + if ($scope.blocks.length === BLOCKS_DISPLAYED) { + $scope.blocks.pop(); + } + getBlock(blockHash); }); $scope.human_since = function(time) { @@ -38,6 +56,7 @@ angular.module('insight.system').controller('IndexController', limit: BLOCKS_DISPLAYED }, function(res) { $scope.blocks = res.blocks; + $scope.blocksLength = res.lenght; }); Transactions.get({ diff --git a/public/views/blocks/list.html b/public/views/blocks/list.html index abdcf85..40b90fc 100644 --- a/public/views/blocks/list.html +++ b/public/views/blocks/list.html @@ -11,33 +11,47 @@

{{pagination.current}}

-
+
- +
- - + + + + + - - - + + + + + + +
HashSolved atHeightTimestampTransactionsSizeConfirmations
{{block.hash}}{{block.time * 1000 | date:'medium'}}
Waiting for blocks...
+ {{b.height}} + {{b.time * 1000 | date:'medium'}}{{b.tx.length}}{{b.size}}{{b.confirmations}}
+

No blocks yet.

diff --git a/public/views/header.html b/public/views/header.html index baf6f77..b9f2a51 100755 --- a/public/views/header.html +++ b/public/views/header.html @@ -35,7 +35,7 @@ Conn: {{info.connections}} - Height: {{info.blocks}} + Height: {{totalBlocks || info.blocks}} diff --git a/public/views/index.html b/public/views/index.html index 7ae3dda..6a3fdf1 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -17,7 +17,7 @@ - Loading... + Waiting for blocks... {{b.height}} @@ -29,7 +29,6 @@ -
@@ -45,7 +44,7 @@ - Loading... + Waiting for transactions... {{tx.txid}} From 0cf69ddd134bbb5b1b474fc732bb62dcbdded8e0 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Wed, 22 Jan 2014 00:18:29 -0300 Subject: [PATCH 4/5] homepage: fixed, only show 5 elements --- public/js/controllers/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/js/controllers/index.js b/public/js/controllers/index.js index 7621cbf..fe0560e 100755 --- a/public/js/controllers/index.js +++ b/public/js/controllers/index.js @@ -31,7 +31,7 @@ angular.module('insight.system').controller('IndexController', socket.on('tx', function(tx) { var txStr = tx.txid.toString(); console.log('Transaction received! ' + JSON.stringify(tx)); - if ($scope.txs.length === TRANSACTION_DISPLAYED) { + if (parseInt($scope.txs.length) === parseInt(TRANSACTION_DISPLAYED)) { $scope.txs.pop(); } getTransaction(txStr); @@ -40,7 +40,7 @@ angular.module('insight.system').controller('IndexController', socket.on('block', function(block) { var blockHash = block.hash.toString(); console.log('Block received! ' + JSON.stringify(block)); - if ($scope.blocks.length === BLOCKS_DISPLAYED) { + if (parseInt($scope.blocks.length) === parseInt(BLOCKS_DISPLAYED)) { $scope.blocks.pop(); } getBlock(blockHash); From fe517b33a5be58f1e7d4ea72a91d8e8bf24b9061 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Wed, 22 Jan 2014 00:22:04 -0300 Subject: [PATCH 5/5] homepage: fixed, only show 5 elements (it is!) --- public/js/controllers/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/js/controllers/index.js b/public/js/controllers/index.js index fe0560e..8879afb 100755 --- a/public/js/controllers/index.js +++ b/public/js/controllers/index.js @@ -31,7 +31,7 @@ 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)) { + if (parseInt($scope.txs.length) > parseInt(TRANSACTION_DISPLAYED) - 1) { $scope.txs.pop(); } getTransaction(txStr); @@ -40,7 +40,7 @@ angular.module('insight.system').controller('IndexController', 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)) { + if (parseInt($scope.blocks.length) > parseInt(BLOCKS_DISPLAYED) - 1) { $scope.blocks.pop(); } getBlock(blockHash);