Merge pull request #65 from cmgustavo/bug/02status

good boy!
This commit is contained in:
Mario Colque 2014-01-16 10:35:04 -08:00
commit 8c420d6780
5 changed files with 51 additions and 4 deletions

View File

@ -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');
}

View File

@ -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;
}

View File

@ -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;
}
});
};

View File

@ -127,14 +127,14 @@
</table>
</div>
<div class="col-lg-6">
<h3>getBestBlockHash</h3>
<table class="table table-striped" data-ng-init="getData('getBestBlockHash')">
<h3>getLastBlockHash</h3>
<table class="table table-striped" data-ng-init="getData('getLastBlockHash')">
<tbody>
<tr data-ng-show="!bestblockhash">
<tr data-ng-show="!lastblockhash">
<td colspan="1" class="text-center">Loading...</td>
</tr>
<tr>
<td>{{bestblockhash}}</td>
<td>{{lastblockhash}}</td>
</tr>
</tbody>
</table>

View File

@ -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();
});
});
});