Fixes: catch error message when importing wallet from different network

This commit is contained in:
Gustavo Cortez 2014-07-02 10:43:00 -03:00
commit f6709c4000
3 changed files with 26 additions and 18 deletions

View file

@ -755,18 +755,19 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
Wallet.prototype.updateIndexes = function(callback) {
var self = this;
var start = self.publicKeyRing.indexes.changeIndex;
self.log('Updating indexes...');
self.indexDiscovery(start, true, 20, function(err, changeIndex) {
if (err) return callback(err);
if (changeIndex != -1)
self.publicKeyRing.indexes.changeIndex = changeIndex + 1;
self.emit('updatingIndexes');
start = self.publicKeyRing.indexes.receiveIndex;
self.indexDiscovery(start, false, 20, function(err, receiveIndex) {
if (err) return callback(err);
if (receiveIndex != -1)
self.publicKeyRing.indexes.receiveIndex = receiveIndex + 1;
self.log('Indexes updated');
self.emit('publicKeyRingUpdated');
self.store();
callback();

View file

@ -74,16 +74,11 @@ WalletFactory.prototype.fromEncryptedObj = function(base64, password) {
return w;
};
WalletFactory.prototype.import = function(base64, password, cb) {
WalletFactory.prototype.import = function(base64, password) {
var self = this;
var w = self.fromEncryptedObj(base64, password);
if (!w) return cb(new Error('wrong password'));
w.updateIndexes(function(err) {
if (err) return cb(err);
self.log('Indexes updated');
cb(null, w);
});
if (!w) throw new Error('Wrong password');
return w;
}