|
@ -263,6 +263,7 @@ WalletService.prototype.getWallet = function(opts, cb) { |
|
|
/** |
|
|
/** |
|
|
* Retrieves wallet status. |
|
|
* Retrieves wallet status. |
|
|
* @param {Object} opts |
|
|
* @param {Object} opts |
|
|
|
|
|
* @param {Object} opts.twoStep[=false] - Optional: use 2-step balance computation for improved performance |
|
|
* @param {Object} opts.includeExtendedInfo - Include PKR info & address managers for wallet & copayers |
|
|
* @param {Object} opts.includeExtendedInfo - Include PKR info & address managers for wallet & copayers |
|
|
* @returns {Object} status |
|
|
* @returns {Object} status |
|
|
*/ |
|
|
*/ |
|
@ -296,7 +297,7 @@ WalletService.prototype.getStatus = function(opts, cb) { |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
function(next) { |
|
|
function(next) { |
|
|
self.getBalance({}, function(err, balance) { |
|
|
self.getBalance(opts, function(err, balance) { |
|
|
if (err) return next(err); |
|
|
if (err) return next(err); |
|
|
status.balance = balance; |
|
|
status.balance = balance; |
|
|
next(); |
|
|
next(); |
|
@ -992,12 +993,7 @@ WalletService.prototype._getBalanceFromAddresses = function(addresses, cb) { |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
WalletService.prototype._getBalanceOneStep = function(opts, cb) { |
|
|
* Get wallet balance. |
|
|
|
|
|
* @param {Object} opts |
|
|
|
|
|
* @returns {Object} balance - Total amount & locked amount. |
|
|
|
|
|
*/ |
|
|
|
|
|
WalletService.prototype.getBalance = function(opts, cb) { |
|
|
|
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
self.storage.fetchAddresses(self.walletId, function(err, addresses) { |
|
|
self.storage.fetchAddresses(self.walletId, function(err, addresses) { |
|
@ -1049,27 +1045,33 @@ WalletService.prototype._getActiveAddresses = function(cb) { |
|
|
/** |
|
|
/** |
|
|
* Get wallet balance. |
|
|
* Get wallet balance. |
|
|
* @param {Object} opts |
|
|
* @param {Object} opts |
|
|
|
|
|
* @param {Boolean} opts.twoStep[=false] - Optional - Use 2 step balance computation for improved performance |
|
|
* @returns {Object} balance - Total amount & locked amount. |
|
|
* @returns {Object} balance - Total amount & locked amount. |
|
|
*/ |
|
|
*/ |
|
|
WalletService.prototype.getBalance2Steps = function(opts, cb) { |
|
|
WalletService.prototype.getBalance = function(opts, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
|
|
|
|
if (!opts.twoStep) |
|
|
|
|
|
return self._getBalanceOneStep(opts, cb); |
|
|
|
|
|
|
|
|
self.storage.countAddresses(self.walletId, function(err, nbAddresses) { |
|
|
self.storage.countAddresses(self.walletId, function(err, nbAddresses) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
|
if (nbAddresses < Defaults.TWO_STEP_BALANCE_THRESHOLD) { |
|
|
if (nbAddresses < Defaults.TWO_STEP_BALANCE_THRESHOLD) { |
|
|
return self.getBalance(opts, cb); |
|
|
return self._getBalanceOneStep(opts, cb); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self._getActiveAddresses(function(err, activeAddresses) { |
|
|
self._getActiveAddresses(function(err, activeAddresses) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
|
if (_.isEmpty(activeAddresses)) { |
|
|
if (_.isEmpty(activeAddresses)) { |
|
|
return self.getBalance(opts, cb); |
|
|
return self._getBalanceOneStep(opts, cb); |
|
|
} else { |
|
|
} else { |
|
|
self._getBalanceFromAddresses(activeAddresses, function(err, partialBalance) { |
|
|
self._getBalanceFromAddresses(activeAddresses, function(err, partialBalance) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
|
cb(null, partialBalance); |
|
|
cb(null, partialBalance); |
|
|
setTimeout(function() { |
|
|
setTimeout(function() { |
|
|
self.getBalance(opts, function(err, fullBalance) { |
|
|
self._getBalanceOneStep(opts, function(err, fullBalance) { |
|
|
if (err) return; |
|
|
if (err) return; |
|
|
if (!_.isEqual(partialBalance, fullBalance)) { |
|
|
if (!_.isEqual(partialBalance, fullBalance)) { |
|
|
log.debug('Cache miss: balance in active addresses differs from final balance'); |
|
|
log.debug('Cache miss: balance in active addresses differs from final balance'); |
|
@ -1084,7 +1086,6 @@ WalletService.prototype.getBalance2Steps = function(opts, cb) { |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WalletService.prototype._sampleFeeLevels = function(network, points, cb) { |
|
|
WalletService.prototype._sampleFeeLevels = function(network, points, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|