Browse Source

fix check for txid

feat/estimateFee-limit
Ivan Socolsky 8 years ago
parent
commit
fd9a2ad839
No known key found for this signature in database GPG Key ID: FAECE6A05FAA4F56
  1. 31
      lib/server.js

31
lib/server.js

@ -444,6 +444,9 @@ WalletService.prototype.getWalletFromIdentifier = function(opts, cb) {
return self.storage.fetchWallet(walletId, 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? // Is identifier a txid form an incomming tx?
var coinNetworkPairs = []; var coinNetworkPairs = [];
_.each(_.values(Constants.COINS), function(coin) { _.each(_.values(Constants.COINS), function(coin) {
@ -456,26 +459,24 @@ WalletService.prototype.getWalletFromIdentifier = function(opts, cb) {
}); });
async.detectSeries(coinNetworkPairs, function(coinNetwork, nextCoinNetwork) { async.detectSeries(coinNetworkPairs, function(coinNetwork, nextCoinNetwork) {
var bc = self._getBlockchainExplorer(coinNetwork.coin, coinNetwork.network); var bc = self._getBlockchainExplorer(coinNetwork.coin, coinNetwork.network);
if (!bc) return nextCoinNetwork(false);
bc.getTransaction(opts.identifier, function(err, tx) { 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 outputs = _.first(self._normalizeTxHistory(tx)).outputs;
var toAddresses = _.pluck(outputs, 'address'); var toAddresses = _.pluck(outputs, 'address');
async.detect(toAddresses, function(addressStr, nextAddress) { async.detect(toAddresses, function(addressStr, nextAddress) {
self.storage.fetchAddressByCoin(coinNetwork.coin, addressStr, function(err, address) { 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; walletId = address.walletId;
nextAddress(null, true); nextAddress(true);
}); });
}, function(err) { }, function() {
nextCoinNetwork(err, !!walletId); nextCoinNetwork(!!walletId);
}); });
}); });
}, function(err) { }, function(walletId) {
if (err) return cb(err); if (!walletId) return cb();
if (walletId) { return self.storage.fetchWallet(walletId, cb);
return self.storage.fetchWallet(walletId, cb);
}
cb();
}); });
}); });
}; };
@ -1062,7 +1063,13 @@ WalletService.prototype._getBlockchainExplorer = function(coin, network) {
opts.coin = coin; opts.coin = coin;
opts.network = network; opts.network = network;
opts.userAgent = WalletService.getServiceVersion(); 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) { WalletService.prototype._getUtxos = function(coin, addresses, cb) {

Loading…
Cancel
Save