|
|
@ -832,7 +832,7 @@ WalletService.prototype._getBlockchainExplorer = function(network) { |
|
|
|
return this.blockchainExplorer; |
|
|
|
}; |
|
|
|
|
|
|
|
WalletService.prototype._getUtxosForAddresses = function(addresses, cb) { |
|
|
|
WalletService.prototype._getUtxos = function(addresses, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
if (addresses.length == 0) return cb(null, []); |
|
|
@ -875,7 +875,7 @@ WalletService.prototype._getUtxosForCurrentWallet = function(addresses, cb) { |
|
|
|
if (addresses.length == 0) return next(null, []); |
|
|
|
|
|
|
|
var addressStrs = _.pluck(addresses, 'address'); |
|
|
|
self._getUtxosForAddresses(addressStrs, function(err, utxos) { |
|
|
|
self._getUtxos(addressStrs, function(err, utxos) { |
|
|
|
if (err) return next(err); |
|
|
|
if (utxos.length == 0) return next(null, []); |
|
|
|
|
|
|
@ -918,7 +918,7 @@ WalletService.prototype.getUtxos = function(opts, cb) { |
|
|
|
if (_.isUndefined(opts.addresses)) { |
|
|
|
self._getUtxosForCurrentWallet(null, cb); |
|
|
|
} else { |
|
|
|
self._getUtxosForAddresses(opts.addresses, cb); |
|
|
|
self._getUtxos(opts.addresses, cb); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
@ -958,16 +958,12 @@ WalletService.prototype._computeBytesToSendMax = function(utxos, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Creates a new transaction proposal. |
|
|
|
* @param {Object} opts |
|
|
|
* @returns {Object} balance - Total amount & locked amount. |
|
|
|
*/ |
|
|
|
WalletService.prototype.getBalance = function(opts, cb) { |
|
|
|
WalletService.prototype._getBalanceFromAddresses = function(addresses, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
self.getUtxos({}, function(err, utxos) { |
|
|
|
self._getUtxosForCurrentWallet(addresses, function(err, utxos) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
var balance = self._totalizeUtxos(utxos); |
|
|
|
|
|
|
|
// Compute balance by address
|
|
|
@ -996,6 +992,59 @@ WalletService.prototype.getBalance = function(opts, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
var prioritaryAddresses; |
|
|
|
|
|
|
|
/** |
|
|
|
* Get wallet balance. |
|
|
|
* @param {Object} opts |
|
|
|
* @returns {Object} balance - Total amount & locked amount. |
|
|
|
*/ |
|
|
|
WalletService.prototype.getBalance = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
self.storage.fetchAddresses(self.walletId, function(err, addresses) { |
|
|
|
if (err) return cb(err); |
|
|
|
self._getBalanceFromAddresses(addresses, function(err, balance) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
// Update cache
|
|
|
|
var addressIndex = _.indexBy(addresses, 'address'); |
|
|
|
prioritaryAddresses = _.map(_.pluck(balance.byAddress, 'address'), function(addrStr) { |
|
|
|
return addressIndex[addrStr]; |
|
|
|
}); |
|
|
|
|
|
|
|
return cb(null, balance); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Get wallet balance. |
|
|
|
* @param {Object} opts |
|
|
|
* @returns {Object} balance - Total amount & locked amount. |
|
|
|
*/ |
|
|
|
WalletService.prototype.getBalance2Steps = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
if (!prioritaryAddresses) return self.getBalance(opts, cb); |
|
|
|
|
|
|
|
self._getBalanceFromAddresses(prioritaryAddresses, function(err, partialBalance) { |
|
|
|
if (err) return cb(err); |
|
|
|
cb(null, partialBalance); |
|
|
|
setTimeout(function() { |
|
|
|
self.getBalance(opts, function(err, fullBalance) { |
|
|
|
if (err) return; |
|
|
|
if (!_.isEqual(partialBalance, fullBalance)) { |
|
|
|
console.log('*** [server.js ln1015] ACTUALIZAR BALANCE!!!!, partialBalance, fullBalance:', partialBalance, fullBalance); // TODO
|
|
|
|
} |
|
|
|
}); |
|
|
|
}, 1); |
|
|
|
return; |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
WalletService.prototype._sampleFeeLevels = function(network, points, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
@ -1110,7 +1159,7 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) { |
|
|
|
return _.pluck(_.sortBy(list, 'order'), 'utxo'); |
|
|
|
}; |
|
|
|
|
|
|
|
self.getUtxos({}, function(err, utxos) { |
|
|
|
self._getUtxosForCurrentWallet(null, function(err, utxos) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
var excludeIndex = _.reduce(utxosToExclude, function(res, val) { |
|
|
|