|
@ -1277,21 +1277,24 @@ WalletService.prototype._getBalanceFromAddresses = function(opts, cb) { |
|
|
WalletService.prototype._getBalanceOneStep = function(opts, cb) { |
|
|
WalletService.prototype._getBalanceOneStep = function(opts, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
self.storage.fetchAddresses(self.walletId, function(err, addresses) { |
|
|
// This lock is to prevent server starvation on big wallets
|
|
|
if (err) return cb(err); |
|
|
self._runLocked(cb, function(cb) { |
|
|
self._getBalanceFromAddresses({ |
|
|
self.storage.fetchAddresses(self.walletId, function(err, addresses) { |
|
|
coin: opts.coin, |
|
|
|
|
|
addresses: addresses |
|
|
|
|
|
}, function(err, balance) { |
|
|
|
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
|
|
|
|
self._getBalanceFromAddresses({ |
|
|
|
|
|
coin: opts.coin, |
|
|
|
|
|
addresses: addresses |
|
|
|
|
|
}, function(err, balance) { |
|
|
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
|
// Update cache
|
|
|
// Update cache
|
|
|
var withBalance = _.map(balance.byAddress, 'address') |
|
|
var withBalance = _.map(balance.byAddress, 'address') |
|
|
self.storage.storeAddressesWithBalance(self.walletId, withBalance, function(err) { |
|
|
self.storage.storeAddressesWithBalance(self.walletId, withBalance, function(err) { |
|
|
if (err) { |
|
|
if (err) { |
|
|
log.warn('Could not update wallet cache', err); |
|
|
log.warn('Could not update wallet cache', err); |
|
|
} |
|
|
} |
|
|
return cb(null, balance); |
|
|
return cb(null, balance); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|