check new client version for paypro txs

This commit is contained in:
Ivan Socolsky 2016-01-15 20:00:33 -03:00
parent 052926eb1a
commit 5c75fde169
3 changed files with 64 additions and 3 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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();
});
});
});
});
});