Skip to content

Commit 8c420d6

Browse files
author
Mario Colque
committed
Merge pull request #65 from cmgustavo/bug/02status
good boy!
2 parents 1efd5e6 + ab85012 commit 8c420d6

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

app/controllers/status.js

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ exports.show = function(req, res, next) {
4242
res.jsonp(d);
4343
});
4444
}
45+
else if (s === 'getLastBlockHash') {
46+
d.getLastBlockHash(function(err) {
47+
if (err) next(err);
48+
res.jsonp(d);
49+
});
50+
}
51+
4552
else {
4653
res.status(400).send('Bad Request');
4754
}

app/models/Status.js

+26
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function spec() {
1313
this.difficulty = {};
1414
this.txoutsetinfo = {};
1515
this.bestblockhash = {};
16+
this.lastblockhash = {};
1617
}
1718

1819
Status.prototype.getInfo = function(next) {
@@ -79,6 +80,31 @@ function spec() {
7980
});
8081
};
8182

83+
Status.prototype.getLastBlockHash = function(next) {
84+
var that = this;
85+
86+
async.waterfall(
87+
[
88+
function(callback){
89+
rpc.getBlockCount(function(err, bc){
90+
if (err) return callback(err);
91+
callback(null, bc.result);
92+
});
93+
},
94+
function(bc, callback){
95+
rpc.getBlockHash(bc, function(err, bh){
96+
if (err) return callback(err);
97+
callback(null, bh.result);
98+
});
99+
}
100+
],
101+
function (err, result) {
102+
that.lastblockhash = result;
103+
return next();
104+
}
105+
);
106+
};
107+
82108
return Status;
83109

84110
}

public/js/controllers/status.js

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ angular.module('mystery.status').controller('StatusController', ['$scope', '$rou
1919
if (q === 'getBestBlockHash') {
2020
$scope.bestblockhash = d.bestblockhash;
2121
}
22+
if (q === 'getLastBlockHash') {
23+
$scope.lastblockhash = d.lastblockhash;
24+
}
25+
2226
});
2327
};
2428

public/views/status.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ <h3>getDifficulty</h3>
127127
</table>
128128
</div>
129129
<div class="col-lg-6">
130-
<h3>getBestBlockHash</h3>
131-
<table class="table table-striped" data-ng-init="getData('getBestBlockHash')">
130+
<h3>getLastBlockHash</h3>
131+
<table class="table table-striped" data-ng-init="getData('getLastBlockHash')">
132132
<tbody>
133-
<tr data-ng-show="!bestblockhash">
133+
<tr data-ng-show="!lastblockhash">
134134
<td colspan="1" class="text-center">Loading...</td>
135135
</tr>
136136
<tr>
137-
<td>{{bestblockhash}}</td>
137+
<td>{{lastblockhash}}</td>
138138
</tr>
139139
</tbody>
140140
</table>

test/model/status.js

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ describe('Status', function(){
6060
});
6161
});
6262

63+
it('getLastBlockHash', function(done) {
64+
var d = new Status();
65+
66+
d.getLastBlockHash(function(err) {
67+
if (err) done(err);
68+
assert.equal('string', typeof d.lastblockhash);
69+
done();
70+
});
71+
});
72+
6373

6474
});
6575

0 commit comments

Comments
 (0)