|
@ -238,7 +238,7 @@ API.prototype._processWcdBeforeWrite = function(wcd, cb) { |
|
|
if (this.noPasswdAccess == 'full') { |
|
|
if (this.noPasswdAccess == 'full') { |
|
|
return cb(null, wcd); |
|
|
return cb(null, wcd); |
|
|
} else { |
|
|
} else { |
|
|
this.emit('needPassword', function(password) { |
|
|
this.emit('needNewPassword', function(password) { |
|
|
if (!password) return cb('No password given'); |
|
|
if (!password) return cb('No password given'); |
|
|
var ewcd = WalletUtils.encryptWallet(wcd, self.noPasswdAccess, password); |
|
|
var ewcd = WalletUtils.encryptWallet(wcd, self.noPasswdAccess, password); |
|
|
return cb(null, ewcd); |
|
|
return cb(null, ewcd); |
|
@ -254,7 +254,8 @@ API.prototype._load = function(opts, cb) { |
|
|
|
|
|
|
|
|
this.storage.load(function(err, rawdata) { |
|
|
this.storage.load(function(err, rawdata) { |
|
|
if (err || !rawdata) { |
|
|
if (err || !rawdata) { |
|
|
return cb(err || 'wcd file not found.'); |
|
|
if (err && err.code == 'ENOENT') err = 'NOTFOUND'; |
|
|
|
|
|
return cb(err || 'NOTFOUND'); |
|
|
} |
|
|
} |
|
|
self._processWcdAfterRead(rawdata, opts.requiredAccess, cb); |
|
|
self._processWcdAfterRead(rawdata, opts.requiredAccess, cb); |
|
|
}); |
|
|
}); |
|
@ -382,7 +383,12 @@ API.prototype.createWallet = function(walletName, copayerName, m, n, network, cb |
|
|
if (!_.contains(['testnet', 'livenet'], network)) |
|
|
if (!_.contains(['testnet', 'livenet'], network)) |
|
|
return cb('Invalid network'); |
|
|
return cb('Invalid network'); |
|
|
|
|
|
|
|
|
this.storage.load(function(err, wcd) { |
|
|
this._load({ |
|
|
|
|
|
requiredAccess: 'readonly', |
|
|
|
|
|
}, function(err, wcd) { |
|
|
|
|
|
if (err && err != 'NOTFOUND') |
|
|
|
|
|
return cb(err); |
|
|
|
|
|
|
|
|
if (wcd && wcd.n) |
|
|
if (wcd && wcd.n) |
|
|
return cb(self.storage.getName() + ' already contains a wallet'); |
|
|
return cb(self.storage.getName() + ' already contains a wallet'); |
|
|
|
|
|
|
|
@ -457,7 +463,12 @@ API.prototype.reCreateWallet = function(walletName, cb) { |
|
|
API.prototype.joinWallet = function(secret, copayerName, cb) { |
|
|
API.prototype.joinWallet = function(secret, copayerName, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
this.storage.load(function(err, wcd) { |
|
|
this._load({ |
|
|
|
|
|
requiredAccess: 'readonly' |
|
|
|
|
|
}, function(err, wcd) { |
|
|
|
|
|
if (err && err != 'NOTFOUND') |
|
|
|
|
|
return cb(err); |
|
|
|
|
|
|
|
|
if (wcd && wcd.n) |
|
|
if (wcd && wcd.n) |
|
|
return cb(self.storage.getName() + ' already contains a wallet'); |
|
|
return cb(self.storage.getName() + ' already contains a wallet'); |
|
|
|
|
|
|
|
|