Browse Source

save wallet inside lock

activeAddress
Ivan Socolsky 10 years ago
parent
commit
8195e067c3
  1. 2
      lib/model/wallet.js
  2. 63
      lib/server.js
  3. 4
      test/integration/server.js

2
lib/model/wallet.js

@ -25,7 +25,6 @@ Wallet.create = function(opts) {
x.m = opts.m; x.m = opts.m;
x.n = opts.n; x.n = opts.n;
x.status = 'pending'; x.status = 'pending';
x.scanning = false;
x.publicKeyRing = []; x.publicKeyRing = [];
x.addressIndex = 0; x.addressIndex = 0;
x.copayers = []; x.copayers = [];
@ -46,7 +45,6 @@ Wallet.fromObj = function(obj) {
x.m = obj.m; x.m = obj.m;
x.n = obj.n; x.n = obj.n;
x.status = obj.status; x.status = obj.status;
x.scanning = obj.scanning;
x.publicKeyRing = obj.publicKeyRing; x.publicKeyRing = obj.publicKeyRing;
x.copayers = _.map(obj.copayers, function(copayer) { x.copayers = _.map(obj.copayers, function(copayer) {
return Copayer.fromObj(copayer); return Copayer.fromObj(copayer);

63
lib/server.js

@ -1195,22 +1195,32 @@ WalletService.prototype.scan = function(opts, cb) {
if (err) return cb(err); if (err) return cb(err);
if (!wallet.isComplete()) return cb(new ClientError('Wallet is not complete')); if (!wallet.isComplete()) return cb(new ClientError('Wallet is not complete'));
var derivators = []; wallet.scanStatus = 'running';
_.each([false, true], function(isChange) { self.storage.storeWallet(wallet, function(err) {
derivators.push(_.bind(wallet.createAddress, wallet, isChange)); if (err) return cb(err);
if (opts.includeCopayerBranches) {
_.each(wallet.copayers, function(copayer) {
derivators.push(_.bind(copayer.createAddress, copayer, wallet, isChange));
});
}
});
async.eachSeries(derivators, function(derivator, next) { var derivators = [];
scanBranch(derivator, function(err, addresses) { _.each([false, true], function(isChange) {
if (err) return next(err); derivators.push(_.bind(wallet.createAddress, wallet, isChange));
self.storage.storeAddressAndWallet(wallet, addresses, next); 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; var self = this;
function scanFinished(err) { function scanFinished(err) {
var result = err ? 'error' : 'success';
var data = { var data = {
result: result, result: err ? 'error' : 'success',
}; };
if (err) data.error = err; if (err) data.error = err;
self._notify('ScanFinished', data, true);
self.getWallet({}, function(err, wallet) {
wallet.scanStatus = result;
self.storage.storeWallet(wallet, function() {
self._notify('ScanFinished', data, true);
});
});
}; };
self.getWallet({}, function(err, wallet) { self.getWallet({}, function(err, wallet) {
if (err) return cb(err); if (err) return cb(err);
if (!wallet.isComplete()) return cb(new ClientError('Wallet is not complete')); 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() { setTimeout(function() {
self.scan(opts, scanFinished); self.scan(opts, scanFinished);
}, 100); }, 100);
return cb(null, { return cb(null, {
started: true started: true
});
}); });
}); });
}; };

4
test/integration/server.js

@ -2689,10 +2689,6 @@ describe('Wallet service', function() {
}); });
server.startScan({}, function(err) { server.startScan({}, function(err) {
should.not.exist(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) { it('should set scan status error when unable to reach blockchain', function(done) {

Loading…
Cancel
Save