Browse Source

fix signatures for same address utxos

activeAddress
Ivan Socolsky 10 years ago
parent
commit
5af3ec8839
  1. 8
      lib/client/api.js
  2. 10
      lib/server.js
  3. 54
      test/integration/server.js

8
lib/client/api.js

@ -501,10 +501,10 @@ API.prototype.signTxProposal = function(txp, cb) {
.change(txp.changeAddress.address) .change(txp.changeAddress.address)
.sign(privs); .sign(privs);
var signatures = []; var signatures = _.map(privs, function(priv, i) {
_.each(privs, function(p) { return _.find(t.getSignatures(priv), {
var s = t.getSignatures(p)[0].signature.toDER().toString('hex'); inputIndex: i
signatures.push(s); }).signature.toDER().toString('hex');
}); });
var url = '/v1/txproposals/' + txp.id + '/signatures/'; var url = '/v1/txproposals/' + txp.id + '/signatures/';

10
lib/server.js

@ -363,16 +363,18 @@ WalletService.prototype._getUtxos = function(cb) {
self.getPendingTxs({}, function(err, txps) { self.getPendingTxs({}, function(err, txps) {
if (err) return cb(err); if (err) return cb(err);
var utxoKey = function(utxo) {
return utxo.txid + '|' + utxo.vout
};
var inputs = _.chain(txps) var inputs = _.chain(txps)
.pluck('inputs') .pluck('inputs')
.flatten() .flatten()
.map(function(utxo) { .map(utxoKey)
return utxo.txid + '|' + utxo.vout
})
.value(); .value();
var dictionary = _.reduce(utxos, function(memo, utxo) { var dictionary = _.reduce(utxos, function(memo, utxo) {
memo[utxo.txid + '|' + utxo.vout] = utxo; memo[utxoKey(utxo)] = utxo;
return memo; return memo;
}, {}); }, {});

54
test/integration/server.js

@ -91,27 +91,29 @@ helpers.toSatoshi = function(btc) {
helpers.stubUtxos = function(server, wallet, amounts, cb) { helpers.stubUtxos = function(server, wallet, amounts, cb) {
var amounts = [].concat(amounts); var amounts = [].concat(amounts);
async.map(amounts, function(a, next) { async.map(_.range(Math.ceil(amounts.length / 2)), function(i, next) {
server.createAddress({}, function(err, address) { // async.map(_.range(amounts.length), function(i, next) {
next(err, address); // async.map(_.range(2), function(i, next) {
}); server.createAddress({}, function(err, address) {
}, next(err, address);
function(err, addresses) { });
var i = 0; }, function(err, addresses) {
var utxos = _.map(amounts, function(amount) { if (err) throw new Error('Could not generate addresses');
return {
txid: helpers.randomTXID(), var utxos = _.map(amounts, function(amount, i) {
vout: Math.floor((Math.random() * 10) + 1), var address = addresses[i % addresses.length];
satoshis: helpers.toSatoshi(amount).toString(), return {
scriptPubKey: addresses[i].getScriptPubKey(wallet.m).toBuffer().toString('hex'), txid: helpers.randomTXID(),
address: addresses[i++].address, vout: Math.floor((Math.random() * 10) + 1),
}; satoshis: helpers.toSatoshi(amount).toString(),
}); scriptPubKey: address.getScriptPubKey(wallet.m).toBuffer().toString('hex'),
address: address.address,
blockExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos); };
return cb(utxos);
}); });
blockExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos);
return cb(utxos);
});
}; };
helpers.stubBroadcast = function(txid) { helpers.stubBroadcast = function(txid) {
@ -146,12 +148,12 @@ helpers.clientSign = function(tx, xprivHex) {
.change(tx.changeAddress.address) .change(tx.changeAddress.address)
.sign(privs); .sign(privs);
var signatures = []; var signatures = _.map(privs, function(priv, i) {
_.each(privs, function(p) { return _.find(t.getSignatures(priv), {
var s = t.getSignatures(p)[0].signature.toDER().toString('hex'); inputIndex: i
signatures.push(s); }).signature.toDER().toString('hex');
}); });
//
return signatures; return signatures;
}; };
@ -1078,7 +1080,7 @@ describe('Copay server', function() {
}); });
}); });
it('should sign and broadcast a tx', function(done) { it.only('should sign and broadcast a tx', function(done) {
helpers.stubBroadcast('1122334455'); helpers.stubBroadcast('1122334455');
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, TestData.copayers[0].privKey); var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, TestData.copayers[0].privKey);
server.createTx(txOpts, function(err, txp) { server.createTx(txOpts, function(err, txp) {

Loading…
Cancel
Save