|
|
@ -408,22 +408,22 @@ WalletService.prototype.getWalletFromIdentifier = function(opts, cb) { |
|
|
|
var walletId; |
|
|
|
async.parallel([ |
|
|
|
|
|
|
|
function(next) { |
|
|
|
self.storage.fetchWallet(identifier, function(err, wallet) { |
|
|
|
function(done) { |
|
|
|
self.storage.fetchWallet(opts.identifier, function(err, wallet) { |
|
|
|
if (wallet) walletId = wallet.id; |
|
|
|
return next(err); |
|
|
|
return done(err); |
|
|
|
}); |
|
|
|
}, |
|
|
|
function(next) { |
|
|
|
self.storage.fetchAddress(identifier, function(err, address) { |
|
|
|
function(done) { |
|
|
|
self.storage.fetchAddress(opts.identifier, function(err, address) { |
|
|
|
if (address) walletId = address.walletId; |
|
|
|
return next(err); |
|
|
|
return done(err); |
|
|
|
}); |
|
|
|
}, |
|
|
|
function(next) { |
|
|
|
self.storage.fetchTxByHash(identifier, function(err, tx) { |
|
|
|
function(done) { |
|
|
|
self.storage.fetchTxByHash(opts.identifier, function(err, tx) { |
|
|
|
if (tx) walletId = tx.walletId; |
|
|
|
return next(err); |
|
|
|
return done(err); |
|
|
|
}); |
|
|
|
}, |
|
|
|
], function(err) { |
|
|
@ -433,42 +433,31 @@ WalletService.prototype.getWalletFromIdentifier = function(opts, cb) { |
|
|
|
} |
|
|
|
|
|
|
|
// Is identifier a txid form an incomming tx?
|
|
|
|
async.eachSeries(['livenet', 'testnet'], function(network, nextNetwork) { |
|
|
|
var bc = self._getBlockchainExplorer('livenet'); |
|
|
|
bc.getTransaction(identifier, function(err, tx) { |
|
|
|
if (err || !tx) return cb(err); |
|
|
|
async.detectSeries(_.values(Constants.NETWORKS), function(network, nextNetwork) { |
|
|
|
var bc = self._getBlockchainExplorer(network); |
|
|
|
bc.getTransaction(opts.identifier, function(err, tx) { |
|
|
|
if (err || !tx) return nextNetwork(err, false); |
|
|
|
|
|
|
|
var outputs = _.first(self._normalizeTxHistory(tx)).outputs; |
|
|
|
var toAddresses = _.pluck(outputs, 'address'); |
|
|
|
async.detect(toAddresses, function(addressStr, nextAddress) { |
|
|
|
self.storage.fetchAddress(addressStr, function(err, address) { |
|
|
|
if (err || !address) return nextAddress(false); |
|
|
|
if (err || !address) return nextAddress(err, false); |
|
|
|
walletId = address.walletId; |
|
|
|
return nextAddress(true); |
|
|
|
nextAddress(null, true); |
|
|
|
}); |
|
|
|
}, function() { |
|
|
|
if (walletId) { |
|
|
|
return self.storage.fetchWallet(walletId, cb); |
|
|
|
} |
|
|
|
return cb(); |
|
|
|
}, function(err) { |
|
|
|
nextNetwork(err, !!walletId); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return nextNetwork(); |
|
|
|
}, function(err) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (walletId) { |
|
|
|
return self.storage.fetchWallet(walletId, cb); |
|
|
|
} |
|
|
|
return cb(); |
|
|
|
cb(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
self.storage.fetchWallet(self.walletId, function(err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!wallet) return cb(Errors.WALLET_NOT_FOUND); |
|
|
|
return cb(null, wallet); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
@ -1031,19 +1020,17 @@ WalletService.prototype.verifyMessageSignature = function(opts, cb) { |
|
|
|
|
|
|
|
|
|
|
|
WalletService.prototype._getBlockchainExplorer = function(network) { |
|
|
|
if (!this.blockchainExplorer) { |
|
|
|
var opts = {}; |
|
|
|
if (this.blockchainExplorerOpts && this.blockchainExplorerOpts[network]) { |
|
|
|
opts = this.blockchainExplorerOpts[network]; |
|
|
|
} |
|
|
|
// TODO: provider should be configurable
|
|
|
|
opts.provider = 'insight'; |
|
|
|
opts.network = network; |
|
|
|
opts.userAgent = WalletService.getServiceVersion(); |
|
|
|
this.blockchainExplorer = new BlockchainExplorer(opts); |
|
|
|
} |
|
|
|
var opts = {}; |
|
|
|
|
|
|
|
return this.blockchainExplorer; |
|
|
|
if (this.blockchainExplorer) return this.blockchainExplorer; |
|
|
|
if (this.blockchainExplorerOpts && this.blockchainExplorerOpts[network]) { |
|
|
|
opts = this.blockchainExplorerOpts[network]; |
|
|
|
} |
|
|
|
// TODO: provider should be configurable
|
|
|
|
opts.provider = 'insight'; |
|
|
|
opts.network = network; |
|
|
|
opts.userAgent = WalletService.getServiceVersion(); |
|
|
|
return new BlockchainExplorer(opts); |
|
|
|
}; |
|
|
|
|
|
|
|
WalletService.prototype._getUtxos = function(addresses, cb) { |
|
|
|