promisify Blocks.getLatest

This commit is contained in:
Manuel Araoz 2015-03-09 18:13:56 -03:00
parent 591f28f56b
commit a09f939b02
2 changed files with 7 additions and 3 deletions

View File

@ -54,14 +54,18 @@ Blocks.heightParam = function(req, res, next, height) {
*/ */
Blocks.getLatest = function(req, res) { Blocks.getLatest = function(req, res) {
req.block = node.getLatestBlock(); node.getLatestBlock()
Blocks.get(req, res); .then(function(block) {
req.block = block;
Blocks.get(req, res);
});
}; };
Blocks.get = function(req, res) { Blocks.get = function(req, res) {
$.checkState(req.block instanceof Block); $.checkState(req.block instanceof Block);
res.send(req.block.toObject()); res.send(req.block.toObject());
}; };
Blocks.getBlockError = function(req, res) { Blocks.getBlockError = function(req, res) {
res.status(422); res.status(422);
res.send('/v1/blocks/ parameter must be a 64 digit hex or block height integer'); res.send('/v1/blocks/ parameter must be a 64 digit hex or block height integer');

View File

@ -37,7 +37,7 @@ describe('BitcoreHTTP v1 blocks routes', function() {
}; };
nodeMock.getLatestBlock = function() { nodeMock.getLatestBlock = function() {
return mockBlocks[Object.keys(mockBlocks).splice(-1)[0]]; return Promise.resolve(mockBlocks[Object.keys(mockBlocks).splice(-1)[0]]);
}; };
app = new BitcoreHTTP(nodeMock).app; app = new BitcoreHTTP(nodeMock).app;
agent = request(app); agent = request(app);