fix import / logs

This commit is contained in:
Matias Alejo Garcia 2014-11-30 04:42:39 -03:00
parent 436aeda1c3
commit 49205a76a0
6 changed files with 27 additions and 61 deletions

View File

@ -18,18 +18,10 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
var password = $scope.password; var password = $scope.password;
updateStatus('Importing profile - Setting things up...'); updateStatus('Importing profile - Setting things up...');
identityService.importProfile(str,password, function(err){ identityService.importProfile(str,password, function(err, iden) {
}) $scope.loading = false;
copay.Identity.importFromEncryptedFullJson(str, password, {
pluginManager: pluginManager,
network: config.network,
networkName: config.networkName,
walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig,
}, function(err, iden) {
if (err) { if (err) {
$scope.loading = false; copay.logger.warn(err);
if ((err.toString() || '').match('BADSTR')) { if ((err.toString() || '').match('BADSTR')) {
$scope.error = 'Bad password or corrupt profile file'; $scope.error = 'Bad password or corrupt profile file';
} else if ((err.toString() || '').match('EEXISTS')) { } else if ((err.toString() || '').match('EEXISTS')) {
@ -37,11 +29,7 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
} else { } else {
$scope.error = 'Unknown error'; $scope.error = 'Unknown error';
} }
$scope.$digest(); $rootScope.$digest();
} else {
var firstWallet = iden.getLastFocusedWallet();
root.bind($scope, iden, firstWallet);
} }
}); });
}; };

View File

@ -108,7 +108,7 @@ Identity.create = function(opts, cb) {
* *
* After opening a profile, and setting its wallet event handlers, * After opening a profile, and setting its wallet event handlers,
* the client must run .netStart on each * the client must run .netStart on each
* wallet (or call Identity.netStart()) * (probably on iden's newWallet handler
* *
* @param {Object} opts * @param {Object} opts
* @param {Object} opts.storage * @param {Object} opts.storage
@ -322,7 +322,6 @@ Identity.prototype.close = function() {
}; };
// TODO: Add feedback function
Identity.prototype.importWalletFromObj = function(obj, opts, cb) { Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
var self = this; var self = this;
preconditions.checkArgument(cb); preconditions.checkArgument(cb);
@ -336,28 +335,30 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
var w = importFunction(obj, readOpts); var w = importFunction(obj, readOpts);
if (!w) return cb(new Error('Could not decrypt')); if (!w) return cb(new Error('Could not decrypt'));
log.debug('Wallet decryped:' + w.getName()); log.debug('Wallet decrypted:' + w.getName());
self._checkVersion(w.version); self._checkVersion(w.version);
log.debug('Updating Indexes for wallet:' + w.getName()); log.debug('Updating Indexes for wallet:' + w.getName());
w.updateIndexes(function(err) { w.updateIndexes(function(err) {
log.debug('Adding wallet to profile:' + w.getName()); log.debug('Adding wallet to profile:' + w.getName());
self.bindWallet(w); self.bindWallet(w);
self.updateFocusedTimestamp(w.getId()); self.storeWallet(w, cb);
var writeOpts = _.extend({
noWallets: true
}, opts);
self.storeWallet(w, function(err) {
if (err) return cb(err);
self.store(writeOpts, function(err) {
return cb(err, w);
});
});
}); });
}; };
Identity.prototype.importMultipleWalletsFromObj = function(objs, opts) {
var self = this;
opts = opts || {};
async.eachSeries(objs, function(walletData, cb) {
if (!walletData)
return cb();
self.importWalletFromObj(walletData, opts, cb);
});
};
/** /**
* @param {Wallet} wallet * @param {Wallet} wallet
* @param {Function} cb * @param {Function} cb
@ -414,30 +415,11 @@ Identity.importFromFullJson = function(str, password, opts, cb) {
iden.store(opts, function(err) { iden.store(opts, function(err) {
if (err) return cb(err); //profile already exists if (err) return cb(err); //profile already exists
opts.failIfExists = false; return cb(null, iden, json.wallets);
async.map(json.wallets, function(walletData, cb) {
if (!walletData)
return cb();
iden.importWalletFromObj(walletData, opts, function(err, w) {
if (err) return cb(err);
log.debug('Wallet ' + w.getId() + ' imported');
cb();
});
}, function(err, results) {
if (err) return cb(err);
iden.store(opts, function(err) {
return cb(err, iden);
});
});
}); });
}; };
/** /**
* @desc binds a wallet's events and emits 'newWallet' * @desc binds a wallet's events and emits 'newWallet'
* @param {string} walletId Wallet id to be binded * @param {string} walletId Wallet id to be binded

View File

@ -220,8 +220,7 @@ Insight.prototype.subscribe = function(addresses) {
if (!self.subscribed[address]) { if (!self.subscribed[address]) {
var handler = handlerFor(self, address); var handler = handlerFor(self, address);
self.subscribed[address] = handler; self.subscribed[address] = handler;
log.debug('Subscribe to: ', address); // log.debug('Subscribe to: ', address);
s.emit('subscribe', address); s.emit('subscribe', address);
s.on(address, handler); s.on(address, handler);
} }

View File

@ -497,8 +497,6 @@ PublicKeyRing.prototype.getCosigner = function(pubKey) {
PublicKeyRing.prototype.buildAddressCache = function() { PublicKeyRing.prototype.buildAddressCache = function() {
var ret = []; var ret = [];
var self = this; var self = this;
log.info('Rebuilding Address Cache...this will take a while');
_.each(this.indexes, function(index) { _.each(this.indexes, function(index) {
for (var i = 0; i < index.receiveIndex; i++) { for (var i = 0; i < index.receiveIndex; i++) {
self._getAddress(i, false, index.copayerIndex); self._getAddress(i, false, index.copayerIndex);
@ -507,7 +505,6 @@ PublicKeyRing.prototype.buildAddressCache = function() {
self._getAddress(i, true, index.copayerIndex); self._getAddress(i, true, index.copayerIndex);
} }
}); });
log.info('...done!');
}; };

View File

@ -1986,7 +1986,7 @@ Wallet.prototype.subscribeToAddresses = function() {
var addresses = this.getAddresses(); var addresses = this.getAddresses();
this.blockchain.subscribe(addresses); this.blockchain.subscribe(addresses);
log.debug('Subscribed to ' + addresses.length + ' addresses'); log.debug('Wallet:' + this.getName() + ' Subscribed to:' + addresses.length + ' addresses');
}; };
/** /**

View File

@ -310,10 +310,10 @@ angular.module('copayApp.services')
networkName: config.networkName, networkName: config.networkName,
walletDefaults: config.wallet, walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig, passphraseConfig: config.passphraseConfig,
}, function(err, iden) { }, function(err, iden, walletObjs) {
if (err) return cb(err); if (err) return cb(err);
root.bind(iden); root.bind(iden);
iden.openWallets(); iden.importMultipleWalletsFromObj(walletObjs);
return cb(); return cb();
}); });
}; };