From fd9a2ad8398cd4d41ee4abcccf023ab708dd2cc4 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 8 Sep 2017 12:46:46 -0300 Subject: [PATCH] fix check for txid --- lib/server.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/server.js b/lib/server.js index 0ec28bd..973e4eb 100644 --- a/lib/server.js +++ b/lib/server.js @@ -444,6 +444,9 @@ WalletService.prototype.getWalletFromIdentifier = function(opts, cb) { return self.storage.fetchWallet(walletId, cb); } + var re = /^[\da-f]+$/gi; + if (!re.test(opts.identifier)) return cb(); + // Is identifier a txid form an incomming tx? var coinNetworkPairs = []; _.each(_.values(Constants.COINS), function(coin) { @@ -456,26 +459,24 @@ WalletService.prototype.getWalletFromIdentifier = function(opts, cb) { }); async.detectSeries(coinNetworkPairs, function(coinNetwork, nextCoinNetwork) { var bc = self._getBlockchainExplorer(coinNetwork.coin, coinNetwork.network); + if (!bc) return nextCoinNetwork(false); bc.getTransaction(opts.identifier, function(err, tx) { - if (err || !tx) return nextCoinNetwork(err, false); + if (err || !tx) return nextCoinNetwork(false); var outputs = _.first(self._normalizeTxHistory(tx)).outputs; var toAddresses = _.pluck(outputs, 'address'); async.detect(toAddresses, function(addressStr, nextAddress) { self.storage.fetchAddressByCoin(coinNetwork.coin, addressStr, function(err, address) { - if (err || !address) return nextAddress(err, false); + if (err || !address) return nextAddress(false); walletId = address.walletId; - nextAddress(null, true); + nextAddress(true); }); - }, function(err) { - nextCoinNetwork(err, !!walletId); + }, function() { + nextCoinNetwork(!!walletId); }); }); - }, function(err) { - if (err) return cb(err); - if (walletId) { - return self.storage.fetchWallet(walletId, cb); - } - cb(); + }, function(walletId) { + if (!walletId) return cb(); + return self.storage.fetchWallet(walletId, cb); }); }); }; @@ -1062,7 +1063,13 @@ WalletService.prototype._getBlockchainExplorer = function(coin, network) { opts.coin = coin; opts.network = network; opts.userAgent = WalletService.getServiceVersion(); - return new BlockchainExplorer(opts); + var bc; + try { + bc = new BlockchainExplorer(opts); + } catch (ex) { + log.warn('Could not instantiate blockchain explorer', ex); + } + return bc; }; WalletService.prototype._getUtxos = function(coin, addresses, cb) {