Browse Source

Merge pull request #698 from isocolsky/fix/support-tool

Bugfix for getWalletFromIdentifier
feat/estimateFee-limit
Matias Alejo Garcia 8 years ago
committed by GitHub
parent
commit
03a61f68f2
  1. 37
      lib/server.js

37
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) {
}, function() {
if (!walletId) return cb();
return self.storage.fetchWallet(walletId, cb);
}
cb();
});
});
};
@ -931,6 +932,7 @@ WalletService.prototype._canCreateAddress = function(ignoreMaxGap, cb) {
})) return cb(null, true);
var bc = self._getBlockchainExplorer(latestAddresses[0].coin, latestAddresses[0].network);
if (!bc) return cb(new Error('Could not get blockchain explorer instance'));
var activityFound = false;
var i = latestAddresses.length;
async.whilst(function() {
@ -1062,7 +1064,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) {
@ -1072,6 +1080,7 @@ WalletService.prototype._getUtxos = function(coin, addresses, cb) {
var networkName = Bitcore.Address(addresses[0]).toObject().network;
var bc = self._getBlockchainExplorer(coin, networkName);
if (!bc) return cb(new Error('Could not get blockchain explorer instance'));
bc.getUtxos(addresses, function(err, utxos) {
if (err) return cb(err);
@ -1501,6 +1510,7 @@ WalletService.prototype._sampleFeeLevels = function(coin, network, points, cb) {
var self = this;
var bc = self._getBlockchainExplorer(coin, network);
if (!bc) return cb(new Error('Could not get blockchain explorer instance'));
bc.estimateFee(points, function(err, result) {
if (err) {
log.error('Error estimating fee', err);
@ -2398,6 +2408,7 @@ WalletService.prototype.removePendingTx = function(opts, cb) {
WalletService.prototype._broadcastRawTx = function(coin, network, raw, cb) {
var bc = this._getBlockchainExplorer(coin, network);
if (!bc) return cb(new Error('Could not get blockchain explorer instance'));
bc.broadcast(raw, function(err, txid) {
if (err) return cb(err);
return cb(null, txid);
@ -2431,6 +2442,7 @@ WalletService.prototype.broadcastRawTx = function(opts, cb) {
WalletService.prototype._checkTxInBlockchain = function(txp, cb) {
if (!txp.txid) return cb();
var bc = this._getBlockchainExplorer(txp.coin, txp.network);
if (!bc) return cb(new Error('Could not get blockchain explorer instance'));
bc.getTransaction(txp.txid, function(err, tx) {
if (err) return cb(err);
return cb(null, !!tx);
@ -2793,6 +2805,7 @@ WalletService.prototype._getBlockchainHeight = function(coin, network, cb) {
function fetchFromBlockchain(cb) {
var bc = self._getBlockchainExplorer(coin, network);
if (!bc) return cb(new Error('Could not get blockchain explorer instance'));
bc.getBlockchainHeight(function(err, height) {
if (!err && height > 0) {
cache.current = height;
@ -2984,6 +2997,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
var addressStrs = _.pluck(addresses, 'address');
var bc = self._getBlockchainExplorer(wallet.coin, wallet.network);
if (!bc) return next(new Error('Could not get blockchain explorer instance'));
bc.getTransactions(addressStrs, from, to, function(err, rawTxs, total) {
if (err) return next(err);
@ -3135,6 +3149,7 @@ WalletService.prototype.scan = function(opts, cb) {
function checkActivity(wallet, address, cb) {
var bc = self._getBlockchainExplorer(wallet.coin, wallet.network);
if (!bc) return cb(new Error('Could not get blockchain explorer instance'));
bc.getAddressActivity(address, cb);
};

Loading…
Cancel
Save