|
|
@ -1224,27 +1224,35 @@ WalletService.prototype.scan = function(opts, cb) { |
|
|
|
WalletService.prototype.startScan = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
function scanFinished(err) { |
|
|
|
var data = {}; |
|
|
|
if (err) { |
|
|
|
data.result = 'error'; |
|
|
|
data.error = err; |
|
|
|
} else { |
|
|
|
data.result = 'success'; |
|
|
|
} |
|
|
|
self._notify('ScanFinished', data, true); |
|
|
|
function scanFinished(wallet, err) { |
|
|
|
var result = err ? 'error' : 'success'; |
|
|
|
var data = { |
|
|
|
result: result, |
|
|
|
}; |
|
|
|
if (err) data.error = err; |
|
|
|
|
|
|
|
self.getWallet({}, function(err, wallet) { |
|
|
|
wallet.scanStatus = result; |
|
|
|
self.storage.storeWallet(wallet, function() { |
|
|
|
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, _.bind(scanFinished, self, wallet)); |
|
|
|
}, 100); |
|
|
|
|
|
|
|
return cb(null, { |
|
|
|
started: true |
|
|
|
return cb(null, { |
|
|
|
started: true |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|