From 70244cc413e7a2fdc9c5f31fb83e5cbbdb606291 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 10 Apr 2015 21:19:46 -0300 Subject: [PATCH] select first external output as 'addressTo' --- lib/server.js | 5 ++++- test/integration/server.js | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/server.js b/lib/server.js index 948b7c0..5a8d636 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1058,7 +1058,10 @@ WalletService.prototype.getTxHistory = function(opts, cb) { amount = Math.abs(amount); if (action == 'sent' || action == 'moved') { - addressTo = outputs[0].address; + var firstExternalOutput = _.find(outputs, { + isMine: false + }); + addressTo = firstExternalOutput ? firstExternalOutput.address : 'N/A'; }; var newTx = { diff --git a/test/integration/server.js b/test/integration/server.js index cf65be4..a0db03b 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2408,11 +2408,11 @@ describe('Wallet service', function() { amount: utxos[0].satoshis, }], outputs: [{ - address: 'external', - amount: helpers.toSatoshi(80) - 5460, - }, { address: changeAddresses[0].address, amount: helpers.toSatoshi(20) - 5460, + }, { + address: 'external', + amount: helpers.toSatoshi(80) - 5460, }], }]; helpers.stubHistory(txs); @@ -2425,6 +2425,7 @@ 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.actions.length.should.equal(1); tx.actions[0].type.should.equal('accept'); tx.actions[0].copayerName.should.equal('copayer 1');