From 39ac518a618660051be56be2efee7a78075e4db1 Mon Sep 17 00:00:00 2001 From: Gregg Zigler Date: Mon, 27 Jul 2015 08:24:16 -0700 Subject: [PATCH 1/3] let clients see multiple outputs --- lib/server.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/server.js b/lib/server.js index 49dd387..0542910 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1538,6 +1538,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) { fees: tx.fees, time: tx.time, addressTo: addressTo, + outputs: tx.outputs, confirmations: tx.confirmations, }; From 20487ab38aaff5bfb35b94c116f68e90deb78f6d Mon Sep 17 00:00:00 2001 From: Gregg Zigler Date: Tue, 28 Jul 2015 08:45:46 -0700 Subject: [PATCH 2/3] return output.message from txproposal if one exists --- lib/server.js | 13 ++++++++++--- test/integration/server.js | 32 +++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/server.js b/lib/server.js index 0542910..9a959ec 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1502,11 +1502,12 @@ WalletService.prototype.getTxHistory = function(opts, cb) { var amountIn, amountOut, amountOutChange; var amount, action, addressTo; + var inputs, outputs; if (tx.outputs.length || tx.inputs.length) { - var inputs = classify(tx.inputs); - var outputs = classify(tx.outputs); + inputs = classify(tx.inputs); + outputs = classify(tx.outputs); amountIn = sum(inputs, true); amountOut = sum(outputs, true, false); @@ -1538,7 +1539,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) { fees: tx.fees, time: tx.time, addressTo: addressTo, - outputs: tx.outputs, + outputs: _.filter(outputs, { isChange: false }), confirmations: tx.confirmations, }; @@ -1550,6 +1551,12 @@ WalletService.prototype.getTxHistory = function(opts, cb) { newTx.actions = _.map(proposal.actions, function(action) { return _.pick(action, ['createdOn', 'type', 'copayerId', 'copayerName', 'comment']); }); + _.each(newTx.outputs, function(output) { + var query = { toAddress: output.address, amount: output.amount }; + var txpOut = _.find(proposal.outputs, query); + output.message = txpOut ? txpOut.message : null; + } + ); // newTx.sentTs = proposal.sentTs; // newTx.merchant = proposal.merchant; //newTx.paymentAckMemo = proposal.paymentAckMemo; diff --git a/test/integration/server.js b/test/integration/server.js index 9109053..78b9a9d 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -3587,14 +3587,26 @@ describe('Wallet service', function() { tx.action.should.equal('sent'); tx.amount.should.equal(300); tx.fees.should.equal(100); + tx.outputs[0].address.should.equal('external'); + tx.outputs[0].amount.should.equal(300); done(); }); }); it('should get tx history with accepted proposal', function(done) { server._normalizeTxHistory = sinon.stub().returnsArg(0); + var external = '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7'; helpers.stubUtxos(server, wallet, [100, 200], function(utxos) { - var txOpts = helpers.createSimpleProposalOpts(mainAddresses[0].address, 80, 'some message', TestData.copayers[0].privKey_1H_0); + var outputs = [{ + toAddress: external, + amount: 50, + message: undefined // no message + }, { + toAddress: external, + amount: 30, + message: 'message #2' + }]; + var txOpts = helpers.createProposalOpts(Model.TxProposal.Types.MULTIPLEOUTPUTS, outputs, 'some message', TestData.copayers[0].privKey_1H_0); server.createTx(txOpts, function(err, tx) { should.not.exist(err); should.exist(tx); @@ -3624,9 +3636,12 @@ describe('Wallet service', function() { address: changeAddresses[0].address, amount: helpers.toSatoshi(20) - 5460, }, { - address: 'external', - amount: helpers.toSatoshi(80) - 5460, - }], + address: external, + amount: helpers.toSatoshi(50) + }, { + address: external, + amount: helpers.toSatoshi(30) + }] }]; helpers.stubHistory(txs); @@ -3638,10 +3653,17 @@ describe('Wallet service', function() { tx.action.should.equal('sent'); tx.amount.should.equal(helpers.toSatoshi(80)); tx.message.should.equal('some message'); - tx.addressTo.should.equal('external'); + tx.addressTo.should.equal(external); tx.actions.length.should.equal(1); tx.actions[0].type.should.equal('accept'); tx.actions[0].copayerName.should.equal('copayer 1'); + tx.outputs[0].address.should.equal(external); + tx.outputs[0].amount.should.equal(helpers.toSatoshi(50)); + should.not.exist(tx.outputs[0].message); + tx.outputs[1].address.should.equal(external); + tx.outputs[1].amount.should.equal(helpers.toSatoshi(30)); + should.exist(tx.outputs[1].message); + tx.outputs[1].message.should.equal('message #2'); done(); }); }); From 730a3269c9718aff4bc9dca63ee025ec44dfd375 Mon Sep 17 00:00:00 2001 From: Gregg Zigler Date: Tue, 28 Jul 2015 09:25:05 -0700 Subject: [PATCH 3/3] include proposal type, exclude decorations, in txhistory results --- lib/server.js | 4 +++- test/integration/server.js | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index 9a959ec..f57a42d 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1532,6 +1532,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) { amount = 0; } + function outputMap(o) { return { amount: o.amount, address: o.address } }; var newTx = { txid: tx.txid, action: action, @@ -1539,13 +1540,14 @@ WalletService.prototype.getTxHistory = function(opts, cb) { fees: tx.fees, time: tx.time, addressTo: addressTo, - outputs: _.filter(outputs, { isChange: false }), + outputs: _.map(_.filter(outputs, { isChange: false }), outputMap), confirmations: tx.confirmations, }; var proposal = indexedProposals[tx.txid]; if (proposal) { newTx.proposalId = proposal.id; + newTx.proposalType = proposal.type; newTx.creatorName = proposal.creatorName; newTx.message = proposal.message; newTx.actions = _.map(proposal.actions, function(action) { diff --git a/test/integration/server.js b/test/integration/server.js index 78b9a9d..05a25c5 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -3657,9 +3657,12 @@ describe('Wallet service', function() { tx.actions.length.should.equal(1); tx.actions[0].type.should.equal('accept'); tx.actions[0].copayerName.should.equal('copayer 1'); + tx.proposalType.should.equal(Model.TxProposal.Types.MULTIPLEOUTPUTS); tx.outputs[0].address.should.equal(external); tx.outputs[0].amount.should.equal(helpers.toSatoshi(50)); should.not.exist(tx.outputs[0].message); + should.not.exist(tx.outputs[0]['isMine']); + should.not.exist(tx.outputs[0]['isChange']); tx.outputs[1].address.should.equal(external); tx.outputs[1].amount.should.equal(helpers.toSatoshi(30)); should.exist(tx.outputs[1].message);