Merge pull request #373 from braydonf/statusinfo
Added handlers for getting status of the block chain.
This commit is contained in:
commit
d1f7349ac5
@ -13,14 +13,14 @@ StatusController.prototype.show = function(req, res) {
|
|||||||
res.jsonp(this.getDifficulty());
|
res.jsonp(this.getDifficulty());
|
||||||
break;
|
break;
|
||||||
case 'getTxOutSetInfo':
|
case 'getTxOutSetInfo':
|
||||||
// TODO
|
res.jsonp(this.getTxOutSetInfo());
|
||||||
// break;
|
break;
|
||||||
case 'getLastBlockHash':
|
case 'getLastBlockHash':
|
||||||
// TODO
|
res.jsonp(this.getLastBlockHash());
|
||||||
// break;
|
break;
|
||||||
case 'getBestBlockHash':
|
case 'getBestBlockHash':
|
||||||
// TODO
|
res.jsonp(this.getBestBlockHash());
|
||||||
// break;
|
break;
|
||||||
case 'getInfo':
|
case 'getInfo':
|
||||||
default:
|
default:
|
||||||
res.jsonp(this.getInfo());
|
res.jsonp(this.getInfo());
|
||||||
@ -34,6 +34,35 @@ StatusController.prototype.getInfo = function() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
StatusController.prototype.getTxOutSetInfo = function() {
|
||||||
|
var hash = this.node.services.bitcoind.getBestBlockHash();
|
||||||
|
if (hash === this.lastTxOutSetInfo) {
|
||||||
|
return {
|
||||||
|
txoutsetinfo: this.txOutSetInfo
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.txOutSetInfo = this.node.services.bitcoind.getTxOutSetInfo();
|
||||||
|
this.lastTxOutSetInfo = this.txOutSetInfo.bestblock;
|
||||||
|
return {
|
||||||
|
txoutsetinfo: this.txOutSetInfo
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
StatusController.prototype.getLastBlockHash = function() {
|
||||||
|
var hash = this.node.services.db.tip.hash;
|
||||||
|
return {
|
||||||
|
syncTipHash: hash,
|
||||||
|
lastblockhash: hash
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
StatusController.prototype.getBestBlockHash = function() {
|
||||||
|
var hash = this.node.services.bitcoind.getBestBlockHash();
|
||||||
|
return {
|
||||||
|
bestblockhash: hash
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
StatusController.prototype.getDifficulty = function() {
|
StatusController.prototype.getDifficulty = function() {
|
||||||
var info = this.node.services.bitcoind.getInfo();
|
var info = this.node.services.bitcoind.getInfo();
|
||||||
return {
|
return {
|
||||||
@ -73,6 +102,6 @@ StatusController.prototype.version = function(req, res) {
|
|||||||
res.jsonp({
|
res.jsonp({
|
||||||
version: pjson.version
|
version: pjson.version
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = StatusController;
|
module.exports = StatusController;
|
||||||
@ -18,10 +18,27 @@ describe('Status', function() {
|
|||||||
errors: ''
|
errors: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var outSetInfo = {
|
||||||
|
height: 151,
|
||||||
|
bestblock: '20b6cc0600037171b8bb634bbd04ea754945be44db8d9199b74798f1abdb382d',
|
||||||
|
transactions: 151,
|
||||||
|
txouts: 151,
|
||||||
|
bytes_serialized: 10431,
|
||||||
|
hash_serialized: 'c165d5dcb22a897745ee2ee274b47133b995bbcf8dd4a7572fedad87541c7df8',
|
||||||
|
total_amount: 750000000000
|
||||||
|
};
|
||||||
|
|
||||||
var node = {
|
var node = {
|
||||||
services: {
|
services: {
|
||||||
bitcoind: {
|
bitcoind: {
|
||||||
getInfo: sinon.stub().returns(info)
|
getInfo: sinon.stub().returns(info),
|
||||||
|
getTxOutSetInfo: sinon.stub().returns(outSetInfo),
|
||||||
|
getBestBlockHash: sinon.stub().returns(outSetInfo.bestblock)
|
||||||
|
},
|
||||||
|
db: {
|
||||||
|
tip: {
|
||||||
|
hash: outSetInfo.bestblock
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -64,6 +81,69 @@ describe('Status', function() {
|
|||||||
|
|
||||||
status.show(req, res);
|
status.show(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getTxOutSetInfo', function(done) {
|
||||||
|
var req = {
|
||||||
|
query: {
|
||||||
|
q: 'getTxOutSetInfo'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var res = {
|
||||||
|
jsonp: function(data) {
|
||||||
|
data.txoutsetinfo.should.equal(outSetInfo);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
status.show(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTxOutSetInfo (cached)', function(done) {
|
||||||
|
var req = {
|
||||||
|
query: {
|
||||||
|
q: 'getTxOutSetInfo'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var res = {
|
||||||
|
jsonp: function(data) {
|
||||||
|
data.txoutsetinfo.should.equal(outSetInfo);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
status.node.services.bitcoind.getTxOutSetInfo.callCount.should.equal(1);
|
||||||
|
status.show(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getBestBlockHash', function(done) {
|
||||||
|
var req = {
|
||||||
|
query: {
|
||||||
|
q: 'getBestBlockHash'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var res = {
|
||||||
|
jsonp: function(data) {
|
||||||
|
data.bestblockhash.should.equal(outSetInfo.bestblock);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
status.show(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getLastBlockHash', function(done) {
|
||||||
|
var req = {
|
||||||
|
query: {
|
||||||
|
q: 'getLastBlockHash'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var res = {
|
||||||
|
jsonp: function(data) {
|
||||||
|
data.syncTipHash.should.equal(outSetInfo.bestblock);
|
||||||
|
data.lastblockhash.should.equal(outSetInfo.bestblock);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
status.show(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('/sync', function() {
|
describe('/sync', function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user