|
|
@ -224,6 +224,7 @@ WalletService.getInstanceWithAuth = function(opts, cb) { |
|
|
|
server.walletId = copayer.walletId; |
|
|
|
} else { |
|
|
|
server.walletId = opts.walletId || copayer.walletId; |
|
|
|
server.copayerIsSupportStaff = true; |
|
|
|
} |
|
|
|
|
|
|
|
server.copayerId = opts.copayerId; |
|
|
@ -395,6 +396,81 @@ WalletService.prototype.getWallet = function(opts, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Retrieves a wallet from storage. |
|
|
|
* @param {Object} opts |
|
|
|
* @param {string} opts.identifier - The identifier associated with the wallet (one of: walletId, address, txid). |
|
|
|
* @returns {Object} wallet |
|
|
|
*/ |
|
|
|
WalletService.prototype.getWalletFromIdentifier = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var walletId; |
|
|
|
async.parallel([ |
|
|
|
|
|
|
|
function(next) { |
|
|
|
self.storage.fetchWallet(identifier, function(err, wallet) { |
|
|
|
if (wallet) walletId = wallet.id; |
|
|
|
return next(err); |
|
|
|
}); |
|
|
|
}, |
|
|
|
function(next) { |
|
|
|
self.storage.fetchAddress(identifier, function(err, address) { |
|
|
|
if (address) walletId = address.walletId; |
|
|
|
return next(err); |
|
|
|
}); |
|
|
|
}, |
|
|
|
function(next) { |
|
|
|
self.storage.fetchTxByHash(identifier, function(err, tx) { |
|
|
|
if (tx) walletId = tx.walletId; |
|
|
|
return next(err); |
|
|
|
}); |
|
|
|
}, |
|
|
|
], function(err) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (walletId) { |
|
|
|
return self.storage.fetchWallet(walletId, 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); |
|
|
|
|
|
|
|
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); |
|
|
|
walletId = address.walletId; |
|
|
|
return nextAddress(true); |
|
|
|
}); |
|
|
|
}, function() { |
|
|
|
if (walletId) { |
|
|
|
return self.storage.fetchWallet(walletId, cb); |
|
|
|
} |
|
|
|
return cb(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return nextNetwork(); |
|
|
|
}, function(err) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (walletId) { |
|
|
|
return self.storage.fetchWallet(walletId, cb); |
|
|
|
} |
|
|
|
return 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); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Retrieves wallet status. |
|
|
|
* @param {Object} opts |
|
|
@ -2571,7 +2647,7 @@ WalletService.prototype.getNotifications = function(opts, cb) { |
|
|
|
WalletService.prototype._normalizeTxHistory = function(txs) { |
|
|
|
var now = Math.floor(Date.now() / 1000); |
|
|
|
|
|
|
|
return _.map(txs, function(tx) { |
|
|
|
return _.map([].concat(txs), function(tx) { |
|
|
|
var inputs = _.map(tx.vin, function(item) { |
|
|
|
return { |
|
|
|
address: item.addr, |
|
|
|