diff --git a/app/controllers/status.js b/app/controllers/status.js index 7fbc189..eb2f1ae 100644 --- a/app/controllers/status.js +++ b/app/controllers/status.js @@ -5,12 +5,11 @@ */ var Status = require('../models/Status'); -var async = require('async'); /** * Status */ -exports.show = function(req, res) { +exports.show = function(req, res, next) { if (! req.query.q) { res.status(400).send('Bad Request'); @@ -19,30 +18,37 @@ exports.show = function(req, res) { var s = req.query.q; var d = Status.new(); - if (s == 'getInfo') { + if (s === 'getInfo') { d.getInfo(function(err) { if (err) next(err); res.jsonp(d); }); } - else if (s == 'getDifficulty') { + else if (s === 'getDifficulty') { d.getDifficulty(function(err) { if (err) next(err); res.jsonp(d); }); } - else if (s == 'getTxOutSetInfo') { + else if (s === 'getTxOutSetInfo') { d.getTxOutSetInfo(function(err) { if (err) next(err); res.jsonp(d); }); } - else if (s == 'getBestBlockHash') { + else if (s === 'getBestBlockHash') { d.getBestBlockHash(function(err) { if (err) next(err); res.jsonp(d); }); } + else if (s === 'getLastBlockHash') { + d.getLastBlockHash(function(err) { + if (err) next(err); + res.jsonp(d); + }); + } + else { res.status(400).send('Bad Request'); } diff --git a/app/models/Status.js b/app/models/Status.js index fab5fff..9ab6678 100644 --- a/app/models/Status.js +++ b/app/models/Status.js @@ -13,6 +13,7 @@ function spec() { this.difficulty = {}; this.txoutsetinfo = {}; this.bestblockhash = {}; + this.lastblockhash = {}; } Status.prototype.getInfo = function(next) { @@ -79,6 +80,31 @@ function spec() { }); }; + Status.prototype.getLastBlockHash = function(next) { + var that = this; + + async.waterfall( + [ + function(callback){ + rpc.getBlockCount(function(err, bc){ + if (err) return callback(err); + callback(null, bc.result); + }); + }, + function(bc, callback){ + rpc.getBlockHash(bc, function(err, bh){ + if (err) return callback(err); + callback(null, bh.result); + }); + } + ], + function (err, result) { + that.lastblockhash = result; + return next(); + } + ); + }; + return Status; } diff --git a/app/views/includes/foot.jade b/app/views/includes/foot.jade index 02578ff..0261433 100755 --- a/app/views/includes/foot.jade +++ b/app/views/includes/foot.jade @@ -4,6 +4,7 @@ //script(type='text/javascript', src='/lib/jquery/jquery.min.js') //script(type='text/javascript', src='/lib/bootstrap/dist/js/bootstrap.min.js') +script(type='text/javascript', src='/socket.io/socket.io.js') script(type='text/javascript', src='/lib/momentjs/moment.js') //AngularJS @@ -27,11 +28,11 @@ script(type='text/javascript', src='/js/directives.js') script(type='text/javascript', src='/js/filters.js') //Application Services +script(type='text/javascript', src='/js/services/global.js') script(type='text/javascript', src='/js/services/status.js') script(type='text/javascript', src='/js/services/address.js') script(type='text/javascript', src='/js/services/transactions.js') script(type='text/javascript', src='/js/services/blocks.js') -script(type='text/javascript', src='/js/services/global.js') script(type='text/javascript', src='/js/services/index.js') //Application Controllers diff --git a/app/views/includes/head.jade b/app/views/includes/head.jade index b33ff2b..0afd52f 100755 --- a/app/views/includes/head.jade +++ b/app/views/includes/head.jade @@ -8,10 +8,8 @@ head meta(name="keywords", content="node.js, express, mongoose, mongodb, angularjs") meta(name="description", content="Mystery") - link(href='/img/icons/favicon.ico', rel='shortcut icon', type='image/x-icon') + link(rel='shortcut icon', href='/img/icons/favicon.ico', type='image/x-icon') + link(rel='stylesheet', href='//fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,400italic') link(rel='stylesheet', href='/lib/bootstrap/dist/css/bootstrap.min.css') link(rel='stylesheet', href='/css/common.css') - - script(src='/socket.io/socket.io.js') - diff --git a/public/css/common.css b/public/css/common.css index 8853a57..127e5be 100644 --- a/public/css/common.css +++ b/public/css/common.css @@ -10,6 +10,7 @@ -------------------------------------------------- */ html, body { + color: #373D42; font-family: Ubuntu, sans-serif; height: 100%; /* The html and body elements cannot have any padding or margin. */ @@ -74,12 +75,97 @@ body { line-height: 18px; } +.col-gray { + background-color: #F4F4F4; + padding: 15px; + margin-top: 10px; + width: 360px; + height: 89%; + border-radius: 5px; +} + +.ellipsis { + display: block; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.line20 { + border: 1px solid #D4D4D4; + margin-bottom: 15px; +} + +.line10 { + border: 1px solid #EAEAEA; + margin: 10px 0; +} + +.col-gray .address { + float: right; + width: 150px; +} + +.block-id { + background: #373D42; + border: 3px solid #FFFFFF; + width: 165px; + height: 165px; + margin: 10px auto; + border-radius: :;px; +} + +.block-id h1 { + font-family: Ubuntu-Medium; + font-size: 24px; + color: #FFFFFF; + line-height: 30px; + text-align: center; +} + +.icon-block { + font-size: 27px; + color: white; + margin-top: 20px; +} + +.block-tx { + border-radius: 2px; + background: #F4F4F4; + margin: 20px 0; + padding: 15px; +} + +.btn-primary { + border-radius: 2px; + background: #64920F; + border: 2px solid #557F08; +} + +.btn-primary:hover, .btn-primary:focus, .btn-primary:active, .btn-primary.active, .open .dropdown-toggle.btn-primary { + background: #fff; + border: 2px solid #ccc; + color: #373D42; + font-weight: bold; +} + /* Set the fixed height of the footer here */ #footer { height: 60px; background-color: #f5f5f5; } +.line-bot { + padding: 0 0 10px 0; + margin-bottom: 10px; + border-bottom: 2px solid #EAEAEA; +} + +.line-top { + padding: 10px 0; + margin-top: 10px; + border-top: 1px solid #EAEAEA; +} /* Custom page CSS -------------------------------------------------- */ @@ -102,7 +188,7 @@ body { } .address { - font-size: 10px; + font-size: 11px; } #search { width: 400px; } diff --git a/public/js/app.js b/public/js/app.js index 452ca7c..5f236b9 100755 --- a/public/js/app.js +++ b/public/js/app.js @@ -1,6 +1,6 @@ 'use strict'; -var app = angular.module('mystery', +angular.module('mystery', ['ngAnimate', 'ngCookies', 'ngResource', diff --git a/public/js/controllers/status.js b/public/js/controllers/status.js index b37a5ae..e219cec 100644 --- a/public/js/controllers/status.js +++ b/public/js/controllers/status.js @@ -7,18 +7,22 @@ angular.module('mystery.status').controller('StatusController', ['$scope', '$rou Status.get({ q: q }, function(d) { - if (q == 'getInfo') { + if (q === 'getInfo') { $scope.info = d.info; } - if (q == 'getDifficulty') { + if (q === 'getDifficulty') { $scope.difficulty = d.difficulty; } - if (q == 'getTxOutSetInfo') { + if (q === 'getTxOutSetInfo') { $scope.txoutsetinfo = d.txoutsetinfo; } - if (q == 'getBestBlockHash') { + if (q === 'getBestBlockHash') { $scope.bestblockhash = d.bestblockhash; } + if (q === 'getLastBlockHash') { + $scope.lastblockhash = d.lastblockhash; + } + }); }; diff --git a/public/views/block.html b/public/views/block.html index b843503..a81b42d 100644 --- a/public/views/block.html +++ b/public/views/block.html @@ -1,107 +1,150 @@
- -
-
-
-
-

Summary

+
+
+
+
+ +
+

Block #{{ block.height }}

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Number Of Transactions{{block.tx.length}} -
Height{{block.height}}
Timestamp{{block.time * 1000 | date:'medium'}}
Difficulty{{block.difficulty}}
Bits{{block.bits}}
Size{{block.size}}
Version{{block.version}}
Nonce{{block.nonce}}
+ +
+
+

Hashes

+
+
+ + + + + + + + + + + + + + + + + + + +
Hash{{block.hash}}
Previous Block{{block.previousblockhash}}
Next Block{{block.nextblockhash}}
Merkle Root

{{block.merkleroot}}

+
+
-
-
-
-
-

Hashes

-
-
- + + +
+

Summary

+
+
+
- - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + +
Hash{{block.hash}}
Previous Block{{block.previousblockhash}}
Next Block{{block.nextblockhash}}
Merkle Root{{block.merkleroot}}
Number Of Transactions {{block.tx.length}} +
Output Total--
Estimated Transaction Volume --
Transaction Fees --
Height {{block.height}}
Timestamp {{block.time * 1000 | date:'medium'}}
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Relayed By --
Difficulty {{block.difficulty}}
Bits {{block.bits}}
Size {{block.size}}
Version {{block.version}}
Nonce {{block.nonce}}
+
+
+ +
+

Transactions Transactions contained within this block

+ +
+
+ {{tx.txid}} + {{tx.time * 1000 | date:'medium'}} +
+ +
+
+ Transmitter +
+
+ +
+
+
+
+

Receptor

+

Receptor

+
+
+

Bitcoin of Receptor

+

Bitcoin of Receptor

+
+
+
+
+ +
+ Feeds: {{tx.feeds}} +
+ {{tx.valueOut}} +
+
+
+
-
-

Transactions Transactions contained within this block

- - - - - - - - - - - - - - - - - - - - -
Transaction HashDatetimeFeeTransacted Amount
Loading...
{{tx.txid}}{{tx.time * 1000 | date:'medium'}}{{tx.feeds}}{{tx.valueOut}}
-
diff --git a/public/views/status.html b/public/views/status.html index f28e0e4..9009f92 100644 --- a/public/views/status.html +++ b/public/views/status.html @@ -127,14 +127,14 @@
-

getBestBlockHash

- +

getLastBlockHash

+
- + - +
Loading...
{{bestblockhash}}{{lastblockhash}}
diff --git a/test/model/status.js b/test/model/status.js index 599d701..d3862a2 100644 --- a/test/model/status.js +++ b/test/model/status.js @@ -60,6 +60,16 @@ describe('Status', function(){ }); }); + it('getLastBlockHash', function(done) { + var d = new Status(); + + d.getLastBlockHash(function(err) { + if (err) done(err); + assert.equal('string', typeof d.lastblockhash); + done(); + }); + }); + });