replaced getBestBlockHash for bot method (getBlockCount + getBlockHash) to get the last block hash.

This commit is contained in:
Gustavo Cortez 2014-01-16 15:33:33 -03:00
parent eafe7bec14
commit ab85012bdf
5 changed files with 51 additions and 4 deletions

View File

@ -42,6 +42,13 @@ exports.show = function(req, res, next) {
res.jsonp(d); res.jsonp(d);
}); });
} }
else if (s === 'getLastBlockHash') {
d.getLastBlockHash(function(err) {
if (err) next(err);
res.jsonp(d);
});
}
else { else {
res.status(400).send('Bad Request'); res.status(400).send('Bad Request');
} }

View File

@ -13,6 +13,7 @@ function spec() {
this.difficulty = {}; this.difficulty = {};
this.txoutsetinfo = {}; this.txoutsetinfo = {};
this.bestblockhash = {}; this.bestblockhash = {};
this.lastblockhash = {};
} }
Status.prototype.getInfo = function(next) { 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; return Status;
} }

View File

@ -19,6 +19,10 @@ angular.module('mystery.status').controller('StatusController', ['$scope', '$rou
if (q === 'getBestBlockHash') { if (q === 'getBestBlockHash') {
$scope.bestblockhash = d.bestblockhash; $scope.bestblockhash = d.bestblockhash;
} }
if (q === 'getLastBlockHash') {
$scope.lastblockhash = d.lastblockhash;
}
}); });
}; };

View File

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