From 2a17f8076a19bf4851e470546a9a88d5dcaed59c Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 6 Mar 2015 18:02:51 -0300 Subject: [PATCH] promisify getTransaction --- api/controllers/transactions.js | 17 +++++++++-------- api/test/v1/transactions.js | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/api/controllers/transactions.js b/api/controllers/transactions.js index 70bb0f98..ec280637 100644 --- a/api/controllers/transactions.js +++ b/api/controllers/transactions.js @@ -21,14 +21,15 @@ Transactions.setNode = function(aNode) { * Finds a transaction by its hash */ Transactions.txHashParam = function(req, res, next, txHash) { - var tx = node.getTransaction(txHash); - - if (_.isUndefined(tx)) { - res.status(404).send('Transaction with id ' + txHash + ' not found'); - return; - } - req.tx = tx; - next(); + node.getTransaction(txHash) + .then(function(tx) { + if (_.isUndefined(tx)) { + res.status(404).send('Transaction with id ' + txHash + ' not found'); + return; + } + req.tx = tx; + }) + .then(next); }; diff --git a/api/test/v1/transactions.js b/api/test/v1/transactions.js index 1883586f..a186e4d2 100644 --- a/api/test/v1/transactions.js +++ b/api/test/v1/transactions.js @@ -22,7 +22,7 @@ describe('BitcoreHTTP v1 transactions routes', function() { beforeEach(function() { nodeMock = new EventEmitter(); nodeMock.getTransaction = function(txHash) { - return mockTransactions[txHash]; + return Promise.resolve(mockTransactions[txHash]); }; nodeMock.broadcast = function(tx) { if (mockTransactions[tx.id]) {