fix check for txid
This commit is contained in:
parent
f81b5484c5
commit
fd9a2ad839
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue