diff --git a/lib/server.js b/lib/server.js index 054185a..fcdee58 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1062,10 +1062,10 @@ WalletService.prototype.scan = function(opts, cb) { var allAddresses = []; - function deriveAddresses(size, isChange, derivator, cb) { + function deriveAddresses(size, derivator, cb) { async.map(_.range(size), function(i, next) { setTimeout(function() { - next(null, derivator(isChange)); + next(null, derivator()); }, WalletService.scanConfig.DERIVATION_DELAY) }, cb); }; @@ -1075,12 +1075,12 @@ WalletService.prototype.scan = function(opts, cb) { bc.getAddressActivity(addresses, cb); }; - function scanBranch(isChange, derivator, cb) { + function scanBranch(derivator, cb) { var activity = true; async.whilst(function() { return activity; }, function(next) { - deriveAddresses(WalletService.scanConfig.SCAN_WINDOW, isChange, derivator, function(err, addresses) { + deriveAddresses(WalletService.scanConfig.SCAN_WINDOW, derivator, function(err, addresses) { if (err) return next(err); allAddresses.push(addresses); checkActivity(_.pluck(addresses, 'address'), function(err, thereIsActivity) { @@ -1100,28 +1100,17 @@ WalletService.prototype.scan = function(opts, cb) { return cb(new ClientError('Wallet is not complete')); var derivators = []; - derivators.push(_.bind(wallet.createAddress, wallet)); - if (opts.includeCopayerBranches) { - _.each(wallet.copayers, function(copayer) { - derivators.push(_.bind(copayer.createAddress, copayer, wallet)); - }); - } + _.each([false, true], function(isChange) { + derivators.push(_.bind(wallet.createAddress, wallet, isChange)); + if (opts.includeCopayerBranches) { + _.each(wallet.copayers, function(copayer) { + derivators.push(_.bind(copayer.createAddress, copayer, wallet, isChange)); + }); + } + }); - var branches = _.flatten( - _.map(derivators, function(derivator) { - return _.map([false, true], function(isChange) { - return { - derivator: derivator, - isChange: isChange - }; - }) - }) - ); - - async.each(branches, function(branch, next) { - scanBranch(branch.isChange, branch.derivator, function(err) { - next(err); - }); + async.each(derivators, function(derivator, next) { + scanBranch(derivator, next); }, function(err) { if (err) return cb(err); self.storage.storeAddressAndWallet(wallet, _.flatten(allAddresses), function(err) {