diff --git a/lib/model/wallet.js b/lib/model/wallet.js index f10c660..7cbe973 100644 --- a/lib/model/wallet.js +++ b/lib/model/wallet.js @@ -25,7 +25,6 @@ Wallet.create = function(opts) { x.m = opts.m; x.n = opts.n; x.status = 'pending'; - x.scanning = false; x.publicKeyRing = []; x.addressIndex = 0; x.copayers = []; @@ -46,7 +45,6 @@ Wallet.fromObj = function(obj) { x.m = obj.m; x.n = obj.n; x.status = obj.status; - x.scanning = obj.scanning; x.publicKeyRing = obj.publicKeyRing; x.copayers = _.map(obj.copayers, function(copayer) { return Copayer.fromObj(copayer); diff --git a/lib/server.js b/lib/server.js index b08bbcc..cf9bc16 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1202,22 +1202,32 @@ WalletService.prototype.scan = function(opts, cb) { if (err) return cb(err); if (!wallet.isComplete()) return cb(new ClientError('Wallet is not complete')); - var derivators = []; - _.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)); - }); - } - }); + wallet.scanStatus = 'running'; + self.storage.storeWallet(wallet, function(err) { + if (err) return cb(err); - async.eachSeries(derivators, function(derivator, next) { - scanBranch(derivator, function(err, addresses) { - if (err) return next(err); - self.storage.storeAddressAndWallet(wallet, addresses, next); + var derivators = []; + _.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)); + }); + } + }); + + async.eachSeries(derivators, function(derivator, next) { + scanBranch(derivator, function(err, addresses) { + if (err) return next(err); + self.storage.storeAddressAndWallet(wallet, addresses, next); + }); + }, function(err) { + wallet.scanStatus = err ? 'error' : 'success'; + self.storage.storeWallet(wallet, function() { + return cb(err); + }); }); - }, cb); + }); }); }); }; @@ -1232,34 +1242,23 @@ WalletService.prototype.startScan = function(opts, cb) { var self = this; function scanFinished(err) { - var result = err ? 'error' : 'success'; var data = { - result: result, + result: err ? 'error' : 'success', }; if (err) data.error = err; - - self.getWallet({}, function(err, wallet) { - wallet.scanStatus = result; - self.storage.storeWallet(wallet, function() { - self._notify('ScanFinished', data, true); - }); - }); + self._notify('ScanFinished', data, true); }; self.getWallet({}, function(err, wallet) { if (err) return cb(err); if (!wallet.isComplete()) return cb(new ClientError('Wallet is not complete')); - wallet.scanStatus = 'running'; - self.storage.storeWallet(wallet, function(err) { - if (err) return cb(err); - setTimeout(function() { - self.scan(opts, scanFinished); - }, 100); + setTimeout(function() { + self.scan(opts, scanFinished); + }, 100); - return cb(null, { - started: true - }); + return cb(null, { + started: true }); }); }; diff --git a/test/integration/server.js b/test/integration/server.js index bfffa87..0db5f9e 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2689,10 +2689,6 @@ describe('Wallet service', function() { }); server.startScan({}, function(err) { should.not.exist(err); - server.getWallet({}, function(err, wallet) { - should.exist(wallet.scanStatus); - wallet.scanStatus.should.equal('running'); - }); }); }); it('should set scan status error when unable to reach blockchain', function(done) {