|
|
@ -866,8 +866,12 @@ WalletService.prototype._getUtxosForCurrentWallet = function(addresses, cb) { |
|
|
|
async.waterfall([ |
|
|
|
|
|
|
|
function(next) { |
|
|
|
if (_.isArray(addresses) && addresses.length > 0) { |
|
|
|
next(null, addresses); |
|
|
|
if (_.isArray(addresses)) { |
|
|
|
if (!_.isEmpty(addresses)) { |
|
|
|
next(null, addresses); |
|
|
|
} else { |
|
|
|
next(null, []); |
|
|
|
} |
|
|
|
} else { |
|
|
|
self.storage.fetchAddresses(self.walletId, next); |
|
|
|
} |
|
|
@ -1002,8 +1006,16 @@ WalletService.prototype._getBalanceOneStep = function(opts, cb) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
// Update cache
|
|
|
|
var active = _.pluck(balance.byAddress, 'address') |
|
|
|
self.storage.storeActiveAddresses(self.walletId, active, function(err) { |
|
|
|
async.series([ |
|
|
|
|
|
|
|
function(next) { |
|
|
|
self.storage.cleanActiveAddresses(self.walletId, next); |
|
|
|
}, |
|
|
|
function(next) { |
|
|
|
var active = _.pluck(balance.byAddress, 'address') |
|
|
|
self.storage.storeActiveAddresses(self.walletId, active, next); |
|
|
|
}, |
|
|
|
], function(err) { |
|
|
|
if (err) { |
|
|
|
log.warn('Could not update wallet cache', err); |
|
|
|
} |
|
|
@ -1020,9 +1032,11 @@ WalletService.prototype._getActiveAddresses = function(cb) { |
|
|
|
self.storage.fetchActiveAddresses(self.walletId, function(err, active) { |
|
|
|
if (err) { |
|
|
|
log.warn('Could not fetch active addresses from cache', err); |
|
|
|
return cb(null, []); |
|
|
|
return cb(); |
|
|
|
} |
|
|
|
|
|
|
|
if (!_.isArray(active)) return cb(); |
|
|
|
|
|
|
|
self.storage.fetchAddresses(self.walletId, function(err, allAddresses) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
@ -1064,7 +1078,7 @@ WalletService.prototype.getBalance = function(opts, cb) { |
|
|
|
|
|
|
|
self._getActiveAddresses(function(err, activeAddresses) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (_.isEmpty(activeAddresses)) { |
|
|
|
if (!_.isArray(activeAddresses)) { |
|
|
|
return self._getBalanceOneStep(opts, cb); |
|
|
|
} else { |
|
|
|
self._getBalanceFromAddresses(activeAddresses, function(err, partialBalance) { |
|
|
|