diff --git a/js/models/TxProposal.js b/js/models/TxProposal.js index 9e6842818..1bfbf6c23 100644 --- a/js/models/TxProposal.js +++ b/js/models/TxProposal.js @@ -44,9 +44,6 @@ function TxProposal(opts) { TxProposal.prototype._checkPayPro = function() { if (!this.merchant) return; -console.log('[TxProposal.js.46]', - this.paymentProtocolURL , this.merchant.request_url); - if (this.paymentProtocolURL !== this.merchant.request_url) throw new Error('PayPro: Mismatch on Payment URLs'); @@ -59,12 +56,12 @@ console.log('[TxProposal.js.46]', if (!this.merchant.total || !this.merchant.outs[0].amountSatStr || !this.merchant.outs[0].address) throw new Error('PayPro: Missing amount'); - if (this.builder.vanilla.outs.length != 1) + var outs = JSON.parse(this.builder.vanilla.outs); + if (_.size(outs) != 1) throw new Error('PayPro: Wrong outs in Tx'); - var ppOut = this.merchant.outs[0]; - var txOut = this.builder.vanilla.outs[0]; + var txOut = outs[0]; if (ppOut.address !== txOut.address) throw new Error('PayPro: Wrong out address in Tx'); diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 4e1aee4c2..908dd0259 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -1328,11 +1328,15 @@ Wallet.prototype.getTxProposals = function() { var copayers = this.getRegisteredCopayerIds(); for (var ntxid in this.txProposals.txps) { var txp = this.txProposals.getTxProposal(ntxid, copayers); + txp.signedByUs = txp.signedBy[this.getMyCopayerId()] ? true : false; txp.rejectedByUs = txp.rejectedBy[this.getMyCopayerId()] ? true : false; txp.finallyRejected = this.totalCopayers - txp.rejectCount < this.requiredCopayers; txp.isPending = !txp.finallyRejected && !txp.sentTxid; + // si no gastada + // y si no esta expirada; + if (!txp.readonly || txp.finallyRejected || txp.sentTs) { ret.push(txp); } @@ -1682,21 +1686,17 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) { }; return this.getUnspent(function(err, safeUnspent, unspent) { + if (options.fetch) { if (!unspent || !unspent.length) { return cb(new Error('No unspent outputs available.')); } + var err; try { self.createPaymentTxSync(options, merchantData, safeUnspent); - } catch (e) { - var msg = e.message || ''; - if (msg.indexOf('not enough unspent tx outputs to fulfill')) { - e = new Error('No unspent outputs available.'); - return cb(e); - } - } - return cb(null, merchantData, pr); + } catch (e) { err = e;} + return cb(err, merchantData, pr); } var ntxid = self.createPaymentTxSync(options, merchantData, safeUnspent); @@ -1972,18 +1972,20 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent) })); }); - if (Object.keys(outs) > 1) + // TODO, for now we only support PayPro with 1 output. + if (_.size(outs) !== 1) throw new Error('PayPro: Unsupported outputs'); - merchantData.outs = outs; + var out = _.pairs(outs)[0]; + merchantData.outs = [{ + address: out[0], + amountSatStr: out[1].toString(10), + }]; merchantData.total = merchantData.total.toString(10); var b = new Builder(opts) .setUnspent(unspent) - .setOutputs({ - address: _.keys(outs)[0], - amountSatStr: _.values(outs)[0].toString(10), - }); + .setOutputs(merchantData.outs); merchantData.pr.pd.outputs.forEach(function(output, i) { var script = { @@ -2031,7 +2033,6 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent) var meSeen = {}; if (priv) meSeen[myId] = now; - console.log('[Wallet.js.2043]', options, merchantData); //TODO var ntxid = this.txProposals.add(new TxProposal({ inputChainPaths: inputChainPaths, signedBy: me, diff --git a/js/plugins/InsightStorage.js b/js/plugins/InsightStorage.js index c65ccbfe2..25a125be8 100644 --- a/js/plugins/InsightStorage.js +++ b/js/plugins/InsightStorage.js @@ -156,6 +156,8 @@ InsightStorage.prototype.setItem = function(name, value, callback) { var passphrase = this.getPassphrase(); var authHeader = new buffers.Buffer(this.email + ':' + passphrase).toString('base64'); var registerUrl = this.storeUrl + '/save'; + + log.debug('setItem ' + name + ' size:'+ (value.length/1024).toFixed(1) + 'kb' ); this.request.post({ url: registerUrl, headers: { diff --git a/test/PayPro.js b/test/PayPro.js index 5ce1d9164..21e272842 100644 --- a/test/PayPro.js +++ b/test/PayPro.js @@ -137,11 +137,7 @@ describe('PayPro (in Wallet) model', function() { var w = cachedCreateW2(); unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString(); unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey); - w.getUnspent = function(cb) { - return setTimeout(function() { - return cb(null, unspentTest, unspentTest); - }, 1); - }; + w.getUnspent = sinon.stub().yields(null, unspentTest, unspentTest); return w; }; diff --git a/test/mocks/FakeBuilder.js b/test/mocks/FakeBuilder.js index ae2d0affe..f066ceec2 100644 --- a/test/mocks/FakeBuilder.js +++ b/test/mocks/FakeBuilder.js @@ -34,10 +34,10 @@ function FakeBuilder() { this.vanilla = { scriptSig: [VALID_SCRIPTSIG_BUF], - outs: [{ + outs: JSON.stringify([{ address: '2NDJbzwzsmRgD2o5HHXPhuq5g6tkKTjYkd6', amountSatStr: '123', - }] + }]), } }