commit
8c420d6780
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue