|
|
@ -702,10 +702,31 @@ WalletService.prototype._canCreateAddress = function(ignoreMaxGap, cb) { |
|
|
|
var latestAddresses = _.takeRight(_.reject(addresses, { |
|
|
|
isChange: true |
|
|
|
}), WalletService.MAX_MAIN_ADDRESS_GAP); |
|
|
|
if (latestAddresses.length < WalletService.MAX_MAIN_ADDRESS_GAP) return cb(null, true); |
|
|
|
if (latestAddresses.length < WalletService.MAX_MAIN_ADDRESS_GAP || _.any(latestAddresses, { |
|
|
|
hasActivity: true |
|
|
|
})) return cb(null, true); |
|
|
|
|
|
|
|
var bc = self._getBlockchainExplorer(latestAddresses[0].network); |
|
|
|
bc.getAddressActivity(_.pluck(latestAddresses, 'address'), cb); |
|
|
|
var activityFound = false; |
|
|
|
var i = latestAddresses.length; |
|
|
|
async.whilst(function() { |
|
|
|
return i > 0 && !activityFound; |
|
|
|
}, function(next) { |
|
|
|
bc.getAddressActivity(latestAddresses[--i].address, function(err, res) { |
|
|
|
if (err) return next(err); |
|
|
|
activityFound = !!res; |
|
|
|
return next(); |
|
|
|
}); |
|
|
|
}, function(err) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!activityFound) return cb(null, false); |
|
|
|
|
|
|
|
var address = latestAddresses[i]; |
|
|
|
address.hasActivity = true; |
|
|
|
self.storage.storeAddress(self.walletId, address, function(err) { |
|
|
|
return cb(err, true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|