Merge pull request #303 from greggzigler/feature/multi-outputs-history
getTxHistory for multiple outputs
This commit is contained in:
commit
5b6ade382e
|
@ -1504,11 +1504,12 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
||||||
|
|
||||||
var amountIn, amountOut, amountOutChange;
|
var amountIn, amountOut, amountOutChange;
|
||||||
var amount, action, addressTo;
|
var amount, action, addressTo;
|
||||||
|
var inputs, outputs;
|
||||||
|
|
||||||
if (tx.outputs.length || tx.inputs.length) {
|
if (tx.outputs.length || tx.inputs.length) {
|
||||||
|
|
||||||
var inputs = classify(tx.inputs);
|
inputs = classify(tx.inputs);
|
||||||
var outputs = classify(tx.outputs);
|
outputs = classify(tx.outputs);
|
||||||
|
|
||||||
amountIn = sum(inputs, true);
|
amountIn = sum(inputs, true);
|
||||||
amountOut = sum(outputs, true, false);
|
amountOut = sum(outputs, true, false);
|
||||||
|
@ -1533,6 +1534,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
||||||
amount = 0;
|
amount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function outputMap(o) { return { amount: o.amount, address: o.address } };
|
||||||
var newTx = {
|
var newTx = {
|
||||||
txid: tx.txid,
|
txid: tx.txid,
|
||||||
action: action,
|
action: action,
|
||||||
|
@ -1540,17 +1542,25 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
||||||
fees: tx.fees,
|
fees: tx.fees,
|
||||||
time: tx.time,
|
time: tx.time,
|
||||||
addressTo: addressTo,
|
addressTo: addressTo,
|
||||||
|
outputs: _.map(_.filter(outputs, { isChange: false }), outputMap),
|
||||||
confirmations: tx.confirmations,
|
confirmations: tx.confirmations,
|
||||||
};
|
};
|
||||||
|
|
||||||
var proposal = indexedProposals[tx.txid];
|
var proposal = indexedProposals[tx.txid];
|
||||||
if (proposal) {
|
if (proposal) {
|
||||||
newTx.proposalId = proposal.id;
|
newTx.proposalId = proposal.id;
|
||||||
|
newTx.proposalType = proposal.type;
|
||||||
newTx.creatorName = proposal.creatorName;
|
newTx.creatorName = proposal.creatorName;
|
||||||
newTx.message = proposal.message;
|
newTx.message = proposal.message;
|
||||||
newTx.actions = _.map(proposal.actions, function(action) {
|
newTx.actions = _.map(proposal.actions, function(action) {
|
||||||
return _.pick(action, ['createdOn', 'type', 'copayerId', 'copayerName', 'comment']);
|
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.sentTs = proposal.sentTs;
|
||||||
// newTx.merchant = proposal.merchant;
|
// newTx.merchant = proposal.merchant;
|
||||||
//newTx.paymentAckMemo = proposal.paymentAckMemo;
|
//newTx.paymentAckMemo = proposal.paymentAckMemo;
|
||||||
|
|
|
@ -3597,14 +3597,26 @@ describe('Wallet service', function() {
|
||||||
tx.action.should.equal('sent');
|
tx.action.should.equal('sent');
|
||||||
tx.amount.should.equal(300);
|
tx.amount.should.equal(300);
|
||||||
tx.fees.should.equal(100);
|
tx.fees.should.equal(100);
|
||||||
|
tx.outputs[0].address.should.equal('external');
|
||||||
|
tx.outputs[0].amount.should.equal(300);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should get tx history with accepted proposal', function(done) {
|
it('should get tx history with accepted proposal', function(done) {
|
||||||
server._normalizeTxHistory = sinon.stub().returnsArg(0);
|
server._normalizeTxHistory = sinon.stub().returnsArg(0);
|
||||||
|
var external = '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7';
|
||||||
|
|
||||||
helpers.stubUtxos(server, wallet, [100, 200], function(utxos) {
|
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) {
|
server.createTx(txOpts, function(err, tx) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
should.exist(tx);
|
should.exist(tx);
|
||||||
|
@ -3634,9 +3646,12 @@ describe('Wallet service', function() {
|
||||||
address: changeAddresses[0].address,
|
address: changeAddresses[0].address,
|
||||||
amount: helpers.toSatoshi(20) - 5460,
|
amount: helpers.toSatoshi(20) - 5460,
|
||||||
}, {
|
}, {
|
||||||
address: 'external',
|
address: external,
|
||||||
amount: helpers.toSatoshi(80) - 5460,
|
amount: helpers.toSatoshi(50)
|
||||||
}],
|
}, {
|
||||||
|
address: external,
|
||||||
|
amount: helpers.toSatoshi(30)
|
||||||
|
}]
|
||||||
}];
|
}];
|
||||||
helpers.stubHistory(txs);
|
helpers.stubHistory(txs);
|
||||||
|
|
||||||
|
@ -3648,10 +3663,20 @@ describe('Wallet service', function() {
|
||||||
tx.action.should.equal('sent');
|
tx.action.should.equal('sent');
|
||||||
tx.amount.should.equal(helpers.toSatoshi(80));
|
tx.amount.should.equal(helpers.toSatoshi(80));
|
||||||
tx.message.should.equal('some message');
|
tx.message.should.equal('some message');
|
||||||
tx.addressTo.should.equal('external');
|
tx.addressTo.should.equal(external);
|
||||||
tx.actions.length.should.equal(1);
|
tx.actions.length.should.equal(1);
|
||||||
tx.actions[0].type.should.equal('accept');
|
tx.actions[0].type.should.equal('accept');
|
||||||
tx.actions[0].copayerName.should.equal('copayer 1');
|
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);
|
||||||
|
tx.outputs[1].message.should.equal('message #2');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue