diff --git a/api/lib/notification_parser.js b/api/lib/notification_parser.js index 94e39a2e..49ba08cb 100644 --- a/api/lib/notification_parser.js +++ b/api/lib/notification_parser.js @@ -18,7 +18,7 @@ var ripple = require('ripple-lib'); */ function NotificationParser() {} -NotificationParser.prototype.parse = function(notification_details) { +NotificationParser.prototype.parse = function(notification_details, urlBase) { var transaction = notification_details.transaction; var account = notification_details.account; var previous_transaction_identifier = @@ -87,6 +87,14 @@ NotificationParser.prototype.parse = function(notification_details) { previous_transaction_identifier; } + // Add urlBase to each url in notification + Object.keys(notification).forEach(function(key) { + if (/url/.test(key) && notification[key]) { + notification[key] = urlBase + + notification[key]; + } + }); + return notification; }; diff --git a/api/notifications.js b/api/notifications.js index fd27e553..049b50c9 100644 --- a/api/notifications.js +++ b/api/notifications.js @@ -26,10 +26,9 @@ var validate = require('./lib/validate.js'); * * @callback * @param {Error} error - * @param {Object with fields "account", "transaction", - * "next_transaction_identifier", "next_hash", - * "previous_transaction_identifier", "previous_hash"} notificationDetails - */ + * @param {Object} notificationDetails + **/ + function attachPreviousAndNextTransactionIdentifiers(api, notificationDetails, topCallback) { @@ -168,7 +167,7 @@ function attachPreviousAndNextTransactionIdentifiers(api, * @param {Error} error * @param {Notification} notification */ -function getNotificationHelper(api, account, identifier, topCallback) { +function getNotificationHelper(api, account, identifier, urlBase, topCallback) { function getTransaction(callback) { try { @@ -214,7 +213,7 @@ function getNotificationHelper(api, account, identifier, topCallback) { // Parse the Notification object from the notificationDetails function parseNotificationDetails(notificationDetails, callback) { - callback(null, NotificationParser.parse(notificationDetails)); + callback(null, NotificationParser.parse(notificationDetails, urlBase)); } var steps = [ @@ -227,7 +226,6 @@ function getNotificationHelper(api, account, identifier, topCallback) { async.waterfall(steps, topCallback); } - /** * Get a notification corresponding to the specified * account and transaction identifier. Uses the res.json @@ -243,7 +241,7 @@ function getNotification(account, identifier, urlBase, callback) { validate.address(account); validate.paymentIdentifier(identifier); - getNotificationHelper(this, account, identifier, + getNotificationHelper(this, account, identifier, urlBase, function(error, notification) { if (error) { return callback(error); @@ -253,14 +251,6 @@ function getNotification(account, identifier, urlBase, callback) { notification: notification }; - // Add urlBase to each url in notification - Object.keys(responseBody.notification).forEach(function(key) { - if (/url/.test(key) && responseBody.notification[key]) { - responseBody.notification[key] = urlBase + - responseBody.notification[key]; - } - }); - // Move client_resource_id to response body instead of inside // the Notification var client_resource_id = responseBody.notification.client_resource_id; diff --git a/api/transactions.js b/api/transactions.js index cee419f5..66625d46 100644 --- a/api/transactions.js +++ b/api/transactions.js @@ -547,7 +547,11 @@ function transactionFilter(transactions, options) { * @param {Array of transactions in JSON format} transactions */ function getAccountTransactions(api, options, callback) { - validate.address(options.account); + try { + validate.address(options.account); + } catch(err) { + return callback(err); + } if (!options.min) { options.min = module.exports.DEFAULT_RESULTS_PER_PAGE;