From c0a7121d290c12bd39a0b53aed4e4e38dbc9939d Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 24 Feb 2015 14:58:23 -0300 Subject: [PATCH 1/2] fix die --- bit-wallet/bit-create | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bit-wallet/bit-create b/bit-wallet/bit-create index ddb4195..ebbe5ee 100755 --- a/bit-wallet/bit-create +++ b/bit-wallet/bit-create @@ -24,7 +24,7 @@ var mn; try { mn = utils.parseMN(args[1]); } catch (ex) { - die(ex); + utils.die(ex); } var client = utils.getClient(program); From ebbf493935e736708f2eaf423221ca9d451a1935 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 24 Feb 2015 16:06:07 -0300 Subject: [PATCH 2/2] noent fix --- bit-wallet/cli-utils.js | 20 +++++++++++++++++++- lib/client/api.js | 19 +++++++++++++++---- test/integration/clientApi.js | 7 +++++-- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/bit-wallet/cli-utils.js b/bit-wallet/cli-utils.js index 429423b..91dc89f 100644 --- a/bit-wallet/cli-utils.js +++ b/bit-wallet/cli-utils.js @@ -53,12 +53,30 @@ Utils.getClient = function(args) { if (args.password) { return cb(args.password); } else { - read({ prompt: 'Password: ', silent: true }, function(er, password) { + read({ + prompt: 'Password for ' + args.file + ' : ', + silent: true + }, function(er, password) { return cb(password); }) } }); + c.on('needNewPassword', function(cb) { + if (args.password) { + return cb(args.password); + } else { + read({ + prompt: 'New Password: ', + silent: true + }, function(er, password) { + return cb(password); + }) + } + }); + + + return c; } diff --git a/lib/client/api.js b/lib/client/api.js index 0077028..2dfc0f7 100644 --- a/lib/client/api.js +++ b/lib/client/api.js @@ -238,7 +238,7 @@ API.prototype._processWcdBeforeWrite = function(wcd, cb) { if (this.noPasswdAccess == 'full') { return cb(null, wcd); } else { - this.emit('needPassword', function(password) { + this.emit('needNewPassword', function(password) { if (!password) return cb('No password given'); var ewcd = WalletUtils.encryptWallet(wcd, self.noPasswdAccess, password); return cb(null, ewcd); @@ -254,7 +254,8 @@ API.prototype._load = function(opts, cb) { this.storage.load(function(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); }); @@ -382,7 +383,12 @@ API.prototype.createWallet = function(walletName, copayerName, m, n, network, cb if (!_.contains(['testnet', 'livenet'], 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) 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) { 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) return cb(self.storage.getName() + ' already contains a wallet'); diff --git a/test/integration/clientApi.js b/test/integration/clientApi.js index c132c0d..11d8cbb 100644 --- a/test/integration/clientApi.js +++ b/test/integration/clientApi.js @@ -65,7 +65,7 @@ var fsmock = {}; var content = {}; fsmock.readFile = function(name, enc, cb) { if (!content || _.isEmpty(content[name])) - return cb('empty'); + return cb('NOTFOUND'); return cb(null, content[name]); }; @@ -227,6 +227,10 @@ describe('client API ', function() { clients[i].on('needPassword', function(cb) { return cb('1234#$@#%F,./.**'); }); + clients[i].on('needNewPassword', function(cb) { + return cb('1234#$@#%F,./.**'); + }); + }); }); @@ -637,7 +641,6 @@ describe('client API ', function() { }, function(err, str) { proxy.import(str, function(err) { should.not.exist(err); - proxy.createWallet('1', '2', 1, 1, 'testnet', function(err) { should.not.exist(err);