store after each branch derivation to save progress

This commit is contained in:
Ivan Socolsky 2015-04-01 21:30:05 -03:00
parent d11887ff66
commit 2874f6745b
1 changed files with 8 additions and 9 deletions

View File

@ -1143,8 +1143,6 @@ WalletService.prototype.scan = function(opts, cb) {
opts = opts || {};
var allAddresses = [];
function deriveAddresses(size, derivator, cb) {
async.mapSeries(_.range(size), function(i, next) {
setTimeout(function() {
@ -1160,6 +1158,7 @@ WalletService.prototype.scan = function(opts, cb) {
function scanBranch(derivator, cb) {
var activity = true;
var allAddresses = [];
async.whilst(function() {
return activity;
}, function(next) {
@ -1172,7 +1171,9 @@ WalletService.prototype.scan = function(opts, cb) {
next();
});
});
}, cb);
}, function(err) {
return cb(err, _.flatten(allAddresses));
});
};
@ -1193,13 +1194,11 @@ WalletService.prototype.scan = function(opts, cb) {
});
async.eachSeries(derivators, function(derivator, next) {
scanBranch(derivator, next);
}, function(err) {
if (err) return cb(err);
self.storage.storeAddressAndWallet(wallet, _.flatten(allAddresses), function(err) {
return cb(err);
scanBranch(derivator, function(err, addresses) {
if (err) return next(err);
self.storage.storeAddressAndWallet(wallet, addresses, next);
});
});
}, cb);
});
});