Merge pull request #403 from isocolsky/fix/multi-output-no-change
Fix/multi output no change
This commit is contained in:
commit
f8248a0eba
|
@ -194,9 +194,12 @@ TxProposal.prototype._buildTx = function() {
|
|||
|
||||
// Shuffle outputs for improved privacy
|
||||
if (t.outputs.length > 1) {
|
||||
$.checkState(t.outputs.length == self.outputOrder.length);
|
||||
var outputOrder = _.reject(self.outputOrder, function(order) {
|
||||
return order >= t.outputs.length;
|
||||
});
|
||||
$.checkState(t.outputs.length == outputOrder.length);
|
||||
t.sortOutputs(function(outputs) {
|
||||
return _.map(self.outputOrder, function(i) {
|
||||
return _.map(outputOrder, function(i) {
|
||||
return outputs[i];
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1705,6 +1705,21 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should support creating a tx with no change address', function(done) {
|
||||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var max = 3 - (7200 / 1e8); // Fees for this tx at 100bits/kB = 7200 sat
|
||||
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', max, TestData.copayers[0].privKey_1H_0);
|
||||
server.createTx(txOpts, function(err, txp) {
|
||||
should.not.exist(err);
|
||||
should.exist(txp);
|
||||
var t = txp.getBitcoreTx().toObject();
|
||||
t.outputs.length.should.equal(1);
|
||||
t.outputs[0].satoshis.should.equal(max * 1e8);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a tx using confirmed utxos first', function(done) {
|
||||
helpers.stubUtxos(server, wallet, [1.3, 'u0.5', 'u0.1', 1.2], function(utxos) {
|
||||
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 1.5, TestData.copayers[0].privKey_1H_0, {
|
||||
|
@ -2131,6 +2146,34 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should support creating a multiple output tx with no change address', function(done) {
|
||||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var max = 3 - (7560 / 1e8); // Fees for this tx at 100bits/kB = 7560 sat
|
||||
var outputs = [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
amount: 1,
|
||||
message: 'message #1'
|
||||
}, {
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
amount: max - 1,
|
||||
message: 'message #2'
|
||||
}];
|
||||
var txOpts = helpers.createProposalOpts(Model.TxProposal.Types.MULTIPLEOUTPUTS, outputs, TestData.copayers[0].privKey_1H_0, {
|
||||
message: 'some message'
|
||||
});
|
||||
server.createTx(txOpts, function(err, txp) {
|
||||
should.not.exist(err);
|
||||
should.exist(txp);
|
||||
|
||||
var t = txp.getBitcoreTx().toObject();
|
||||
t.outputs.length.should.equal(2);
|
||||
_.sum(t.outputs, 'satoshis').should.equal(max * 1e8);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should fail to create tx for type multiple_outputs with missing output argument', function(done) {
|
||||
helpers.stubUtxos(server, wallet, [100, 200], function() {
|
||||
var outputs = [{
|
||||
|
|
Loading…
Reference in New Issue