From b254dea911ec429939a7bf0ca1bd2ac660d51e45 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 6 Aug 2014 11:50:53 -0700 Subject: [PATCH] Revert "paypro: prepare for txp refactor. will stay reverted until #1001 is merged." This reverts commit c826acb3e539c4deb047053fd08a2a5e8fb8f8e8. --- js/controllers/send.js | 2 +- js/models/core/Wallet.js | 25 ++++++++++++++----------- test/test.PayPro.js | 10 +++++----- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 7f5f15a89..30f4a9b58 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -63,7 +63,7 @@ angular.module('copayApp.controllers').controller('SendController', function done(ntxid, merchantData) { if (merchantData && +merchantData.total === 0) { - var txp = w.txProposals.get(ntxid); + var txp = w.txProposals.txps[ntxid]; txp.builder.tx.outs[0].v = bitcore.Bignum(amount + '', 10).toBuffer({ endian: 'little', size: 1 diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 9c0a22194..2558067e2 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -965,7 +965,7 @@ Wallet.prototype.sendPaymentTx = function(ntxid, options, cb) { options = {}; } - var txp = this.txProposals.get(ntxid); + var txp = this.txProposals.txps[ntxid]; if (!txp) return; var tx = txp.builder.build(); @@ -1178,8 +1178,10 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent) b = b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths)); - var keys = priv.getForPaths(inputChainPaths); - var signed = b.sign(keys); + if (priv) { + var keys = priv.getForPaths(inputChainPaths); + var signed = b.sign(keys); + } if (options.fetch) return; @@ -1191,16 +1193,15 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent) var myId = this.getMyCopayerId(); var now = Date.now(); - var tx = b.build(); - if (!tx.countInputSignatures(0)) - throw new Error('Could not sign generated tx'); - var me = {}; - me[myId] = now; + + var tx = b.build(); + if (priv && tx.countInputSignatures(0)) me[myId] = now; + var meSeen = {}; if (priv) meSeen[myId] = now; - var ntxid = this.txProposals.add(new TxProposal({ + var data = { inputChainPaths: inputChainPaths, signedBy: me, seenBy: meSeen, @@ -1209,7 +1210,9 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent) builder: b, comment: options.memo, merchant: merchantData - })); + }; + + var ntxid = this.txProposals.add(data); return ntxid; }; @@ -1221,7 +1224,7 @@ Wallet.prototype.verifyPaymentRequest = function(ntxid) { if (!ntxid) return false; var txp = typeof ntxid !== 'object' - ? this.txProposals.get(ntxid) + ? this.txProposals.txps[ntxid] : ntxid; // If we're not a payment protocol proposal, ignore. diff --git a/test/test.PayPro.js b/test/test.PayPro.js index 09bbf5045..b157870d7 100644 --- a/test/test.PayPro.js +++ b/test/test.PayPro.js @@ -782,7 +782,7 @@ describe('PayPro (in Wallet) model', function() { merchantData.raw = pr.serialize().toString('hex'); var myId = w.getMyCopayerId(); - var txp = w.txProposals.get(ntxid); + var txp = w.txProposals.txps[ntxid]; should.exist(txp); should.exist(txp.signedBy[myId]); should.not.exist(txp.rejectedBy[myId]); @@ -809,7 +809,7 @@ describe('PayPro (in Wallet) model', function() { amount.low = 2; var myId = w.getMyCopayerId(); - var txp = w.txProposals.get(ntxid); + var txp = w.txProposals.txps[ntxid]; should.exist(txp); should.exist(txp.signedBy[myId]); should.not.exist(txp.rejectedBy[myId]); @@ -830,12 +830,12 @@ describe('PayPro (in Wallet) model', function() { should.exist(merchantData); // Tamper with payment request in its abstract form: - var txp = w.txProposals.get(ntxid); + var txp = w.txProposals.txps[ntxid]; var tx = txp.builder.tx || txp.builder.build(); tx.outs[0].v = new Buffer([2, 0, 0, 0, 0, 0, 0, 0]); var myId = w.getMyCopayerId(); - var txp = w.txProposals.get(ntxid); + var txp = w.txProposals.txps[ntxid]; should.exist(txp); should.exist(txp.signedBy[myId]); should.not.exist(txp.rejectedBy[myId]); @@ -856,7 +856,7 @@ describe('PayPro (in Wallet) model', function() { should.exist(merchantData); var myId = w.getMyCopayerId(); - var txp = w.txProposals.get(ntxid); + var txp = w.txProposals.txps[ntxid]; should.exist(txp); should.exist(txp.signedBy[myId]); should.not.exist(txp.rejectedBy[myId]);