diff --git a/app/controllers/status.js b/app/controllers/status.js index 47b1f45..eb2f1ae 100644 --- a/app/controllers/status.js +++ b/app/controllers/status.js @@ -42,6 +42,13 @@ exports.show = function(req, res, next) { 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/public/js/controllers/status.js b/public/js/controllers/status.js index cc02da9..e219cec 100644 --- a/public/js/controllers/status.js +++ b/public/js/controllers/status.js @@ -19,6 +19,10 @@ angular.module('mystery.status').controller('StatusController', ['$scope', '$rou if (q === 'getBestBlockHash') { $scope.bestblockhash = d.bestblockhash; } + if (q === 'getLastBlockHash') { + $scope.lastblockhash = d.lastblockhash; + } + }); }; 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(); + }); + }); + });