From 1007ad1b05919f36852a7a9136a05c134ee0375d Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 18 Aug 2015 18:22:43 -0300 Subject: [PATCH] includeExtendedInfo switch --- lib/server.js | 13 +++++++++++++ test/integration/server.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/server.js b/lib/server.js index a3f0631..b7f99d8 100644 --- a/lib/server.js +++ b/lib/server.js @@ -275,17 +275,30 @@ WalletService.prototype.getWallet = function(opts, cb) { /** * Retrieves wallet status. * @param {Object} opts + * @param {Object} opts.includeExtendedInfo - Include PKR info & address managers for wallet & copayers * @returns {Object} status */ WalletService.prototype.getStatus = function(opts, cb) { var self = this; + opts = opts || {}; + var status = {}; async.parallel([ function(next) { self.getWallet({}, function(err, wallet) { if (err) return next(err); + + var walletExtendedKeys = ['publicKeyRing', 'pubKey', 'addressManager']; + var copayerExtendedKeys = ['xPubKey', 'requestPubKey', 'signature', 'addressManager']; + + if (!opts.includeExtendedInfo) { + wallet = _.omit(wallet, walletExtendedKeys); + wallet.copayers = _.map(wallet.copayers, function(copayer) { + return _.omit(copayer, copayerExtendedKeys); + }); + } status.wallet = wallet; next(); }); diff --git a/test/integration/server.js b/test/integration/server.js index 3fba9fc..2fc2c91 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1140,6 +1140,34 @@ describe('Wallet service', function() { should.exist(status.preferences); should.exist(status.pendingTxps); status.pendingTxps.should.be.empty; + + should.not.exist(status.wallet.publicKeyRing); + should.not.exist(status.wallet.pubKey); + should.not.exist(status.wallet.addressManager); + should.not.exist(status.wallet.copayers[0].xPubKey); + should.not.exist(status.wallet.copayers[0].requestPubKey); + should.not.exist(status.wallet.copayers[0].signature); + should.not.exist(status.wallet.copayers[0].requestPubKey); + should.not.exist(status.wallet.copayers[0].addressManager); + + done(); + }); + }); + it('should get status including extended info', function(done) { + server.getStatus({ + includeExtendedInfo: true + }, function(err, status) { + should.not.exist(err); + should.exist(status); + should.exist(status.wallet.publicKeyRing); + should.exist(status.wallet.pubKey); + should.exist(status.wallet.addressManager); + should.exist(status.wallet.copayers[0].xPubKey); + should.exist(status.wallet.copayers[0].requestPubKey); + should.exist(status.wallet.copayers[0].signature); + should.exist(status.wallet.copayers[0].requestPubKey); + should.exist(status.wallet.copayers[0].addressManager); + done(); }); });