diff --git a/app/controllers/transactions.js b/app/controllers/transactions.js index 7d32e83..8146d04 100644 --- a/app/controllers/transactions.js +++ b/app/controllers/transactions.js @@ -51,36 +51,40 @@ var getTransaction = function(txid, cb) { }); }; -exports.getTransactionsByBlock = function(req, res, next, bId) { - Block.fromHashWithInfo(bId, function(err, block) { - if (err && !block) { - console.log(err); - res.status(404).send('Not found'); - return next(); - } +exports.transactions = function(req, res, next) { + var bId = req.query.block; + var aId = req.query.address; - async.mapSeries(block.info.tx, getTransaction, - function(err, results) { - res.jsonp(results); - }); - }); -}; - -exports.getTransactionsByAddress = function(req, res, next, aId) { - - var a = Address.new(aId); - - a.update(function(err) { - if (err && !a.totalReceivedSat) { - console.log(err); - res.status(404).send('Invalid address'); - return next(); - } - - async.mapSeries(a.transactions, getTransaction, - function(err, results) { - res.jsonp(results); - }); - }); + if (bId) { + Block.fromHashWithInfo(bId, function(err, block) { + if (err && !block) { + console.log(err); + res.status(404).send('Not found'); + return next(); + } + + async.mapSeries(block.info.tx, getTransaction, + function(err, results) { + res.jsonp(results); + }); + }); + } + else { + var a = Address.new(aId); + + a.update(function(err) { + if (err && !a.totalReceivedSat) { + console.log(err); + res.status(404).send('Invalid address'); + return next(); + } + + async.mapSeries(a.transactions, getTransaction, + function(err, results) { + res.jsonp(results); + }); + }); + + } }; diff --git a/config/routes.js b/config/routes.js index 7ced7c7..51a3413 100644 --- a/config/routes.js +++ b/config/routes.js @@ -19,13 +19,9 @@ module.exports = function(app) { app.get('/api/tx/:txid', transactions.show); app.param('txid', transactions.transaction); - app.get('/api/txb/:bId', transactions.getTransactionsByBlock); - app.param('bId', transactions.getTransactionsByBlock); - - app.get('/api/txa/:aId', transactions.getTransactionsByAddress); - app.param('aId', transactions.getTransactionsByAddress); - + app.get('/api/txs', transactions.transactions); + // Address routes var addresses = require('../app/controllers/addresses'); app.get('/api/addr/:addr', addresses.show); app.param('addr', addresses.address); diff --git a/public/js/controllers/transactions.js b/public/js/controllers/transactions.js index ca1ae7e..10d5f9f 100644 --- a/public/js/controllers/transactions.js +++ b/public/js/controllers/transactions.js @@ -13,7 +13,7 @@ angular.module('mystery.transactions').controller('transactionsController', ['$s $scope.byBlock = function(bId) { TransactionsByBlock.query({ - bId: bId + block: bId }, function(txs) { $scope.txs = txs; }); @@ -21,7 +21,7 @@ angular.module('mystery.transactions').controller('transactionsController', ['$s $scope.byAddress = function(aId) { TransactionsByAddress.query({ - aId: aId + address: aId }, function(txs) { $scope.txs = txs; }); diff --git a/public/js/services/transactions.js b/public/js/services/transactions.js index e51e1ea..d245dbf 100644 --- a/public/js/services/transactions.js +++ b/public/js/services/transactions.js @@ -21,14 +21,14 @@ angular.module('mystery.transactions').factory('Transaction', ['$resource', func }]); angular.module('mystery.transactions').factory('TransactionsByBlock', ['$resource', function($resource) { - return $resource('/api/txb/:bId', { - bId: '@bId' + return $resource('/api/txs', { + block: '@block' }); }]); angular.module('mystery.transactions').factory('TransactionsByAddress', ['$resource', function($resource) { - return $resource('/api/txa/:aId', { - aId: '@aId' + return $resource('/api/txs', { + address: '@address' }); }]);