From 5c75fde169083a1b53aef5bc779746ec3b606c2e Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 15 Jan 2016 20:00:33 -0300 Subject: [PATCH] check new client version for paypro txs --- lib/server.js | 14 ++++++++++ test/integration/helpers.js | 2 +- test/integration/server.js | 51 +++++++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/lib/server.js b/lib/server.js index 68f0578..fed64fe 100644 --- a/lib/server.js +++ b/lib/server.js @@ -580,6 +580,14 @@ WalletService.prototype._clientSupportsTXPv3 = function() { return true; }; +WalletService.prototype._clientSupportsPayProRefund = function() { + var version = this._parseClientVersion(); + if (!version) return false; + if (version.agent != 'bwc') return true; + if (version.major < 1 || (version.major == 1 && version.minor < 2)) return false; + return true; +}; + WalletService._getCopayerHash = function(name, xPubKey, requestPubKey) { return [name, xPubKey, requestPubKey].join('|'); }; @@ -1418,6 +1426,12 @@ WalletService.prototype.createTxLegacy = function(opts, cb) { if (err) return cb(err); if (!wallet.isComplete()) return cb(Errors.WALLET_NOT_COMPLETE); + if (opts.payProUrl) { + if (wallet.addressType == Constants.SCRIPT_TYPES.P2PKH && !self._clientSupportsPayProRefund()) { + return cb(new ClientError(Errors.codes.UPGRADE_NEEDED, 'To sign this spend proposal you need to upgrade your client app.')); + } + } + var copayer = wallet.getCopayer(self.copayerId); var hash; if (!opts.type || opts.type == Model.TxProposalLegacy.Types.SIMPLE) { diff --git a/test/integration/helpers.js b/test/integration/helpers.js index 3aa1b13..a89cb4d 100644 --- a/test/integration/helpers.js +++ b/test/integration/helpers.js @@ -444,7 +444,7 @@ helpers.createProposalOpts = function(type, outputs, signingKey, moreOpts, input }; if (moreOpts) { - moreOpts = _.pick(moreOpts, ['feePerKb', 'customData', 'message']); + moreOpts = _.pick(moreOpts, ['feePerKb', 'customData', 'message', 'payProUrl']); opts = _.assign(opts, moreOpts); } diff --git a/test/integration/server.js b/test/integration/server.js index bbc09ca..fa4c7b5 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1952,6 +1952,7 @@ describe('Wallet service', function() { describe('Legacy', function() { var server, wallet; + beforeEach(function(done) { helpers.createAndJoinWallet(2, 3, function(s, w) { server = s; @@ -1964,7 +1965,7 @@ describe('Wallet service', function() { helpers.stubUtxos(server, wallet, [100, 200], function() { var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, TestData.copayers[0].privKey_1H_0, { message: 'some message', - customData: 'some custom data' + customData: 'some custom data', }); server.createTxLegacy(txOpts, function(err, tx) { should.not.exist(err); @@ -4652,7 +4653,9 @@ describe('Wallet service', function() { }]; var txOpts = helpers.createProposalOpts(Model.TxProposalLegacy.Types.MULTIPLEOUTPUTS, outputs, TestData.copayers[0].privKey_1H_0, { message: 'some message', - customData: { "test": true } + customData: { + "test": true + } }); server.createTxLegacy(txOpts, function(err, tx) { should.not.exist(err); @@ -5404,4 +5407,48 @@ describe('Wallet service', function() { }); }); }); + + describe('PayPro', function() { + var server, wallet; + + beforeEach(function(done) { + helpers.createAndJoinWallet(1, 1, function(s, w) { + server = s; + wallet = w; + done(); + }); + }); + + it('should create a paypro tx', function(done) { + helpers.stubUtxos(server, wallet, [100, 200], function() { + var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, TestData.copayers[0].privKey_1H_0, { + message: 'some message', + customData: 'some custom data', + payProUrl: 'http:/fakeurl.com', + }); + server.createTxLegacy(txOpts, function(err, tx) { + should.not.exist(err); + should.exist(tx); + tx.payProUrl.should.equal('http:/fakeurl.com'); + done(); + }); + }); + }); + it('should fail to create a paypro tx for a P2PKH wallet from an old client (bwc < 1.2.0)', function(done) { + helpers.stubUtxos(server, wallet, [100, 200], function() { + var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, TestData.copayers[0].privKey_1H_0, { + message: 'some message', + customData: 'some custom data', + payProUrl: 'http:/fakeurl.com', + }); + server._setClientVersion('bwc-1.1.99'); + server.createTxLegacy(txOpts, function(err, tx) { + should.exist(err); + should.not.exist(tx); + err.code.should.equal('UPGRADE_NEEDED'); + done(); + }); + }); + }); + }); });