Browse Source

shuffle outputs

activeAddress
Ivan Socolsky 10 years ago
parent
commit
4a53da8690
  1. 2
      lib/model/txproposal.js
  2. 14
      test/models/txproposal.js

2
lib/model/txproposal.js

@ -32,6 +32,7 @@ TxProposal.create = function(opts) {
x.requiredRejections = opts.requiredRejections; x.requiredRejections = opts.requiredRejections;
x.status = 'pending'; x.status = 'pending';
x.actions = []; x.actions = [];
x.outputOrder = _.shuffle(_.range(2));
return x; return x;
}; };
@ -58,6 +59,7 @@ TxProposal.fromObj = function(obj) {
x.actions = _.map(obj.actions, function(action) { x.actions = _.map(obj.actions, function(action) {
return TxProposalAction.fromObj(action); return TxProposalAction.fromObj(action);
}); });
x.outputOrder = obj.outputOrder;
return x; return x;
}; };

14
test/models/txproposal.js

@ -22,6 +22,17 @@ describe('TXProposal', function() {
var t = txp.getBitcoreTx(); var t = txp.getBitcoreTx();
should.exist(t); should.exist(t);
}); });
it('should order ouputs as specified by outputOrder', function() {
var txp = TXP.fromObj(aTXP());
txp.outputOrder = [0, 1];
var t = txp._getBitcoreTx();
t.getChangeOutput().should.deep.equal(t.outputs[1]);
txp.outputOrder = [1, 0];
var t = txp._getBitcoreTx();
t.getChangeOutput().should.deep.equal(t.outputs[0]);
});
}); });
@ -108,6 +119,7 @@ var aTXP = function() {
"requiredSignatures": 2, "requiredSignatures": 2,
"requiredRejections": 1, "requiredRejections": 1,
"status": "pending", "status": "pending",
"actions": [] "actions": [],
"outputOrder": [0, 1],
} }
}; };

Loading…
Cancel
Save