|
|
@ -1195,22 +1195,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); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
@ -1225,34 +1235,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 |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|