promisify getTransaction

This commit is contained in:
Manuel Araoz 2015-03-06 18:02:51 -03:00
parent cd2e1d8b8a
commit 2a17f8076a
2 changed files with 10 additions and 9 deletions

View File

@ -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);
};

View File

@ -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]) {