diff --git a/lib/client/api.js b/lib/client/api.js index 8d73cfa..d4e8635 100644 --- a/lib/client/api.js +++ b/lib/client/api.js @@ -501,10 +501,10 @@ API.prototype.signTxProposal = function(txp, cb) { .change(txp.changeAddress.address) .sign(privs); - var signatures = []; - _.each(privs, function(p) { - var s = t.getSignatures(p)[0].signature.toDER().toString('hex'); - signatures.push(s); + var signatures = _.map(privs, function(priv, i) { + return _.find(t.getSignatures(priv), { + inputIndex: i + }).signature.toDER().toString('hex'); }); var url = '/v1/txproposals/' + txp.id + '/signatures/'; diff --git a/lib/server.js b/lib/server.js index 6090b33..0404d5e 100644 --- a/lib/server.js +++ b/lib/server.js @@ -363,16 +363,18 @@ WalletService.prototype._getUtxos = function(cb) { self.getPendingTxs({}, function(err, txps) { if (err) return cb(err); + var utxoKey = function(utxo) { + return utxo.txid + '|' + utxo.vout + }; + var inputs = _.chain(txps) .pluck('inputs') .flatten() - .map(function(utxo) { - return utxo.txid + '|' + utxo.vout - }) + .map(utxoKey) .value(); var dictionary = _.reduce(utxos, function(memo, utxo) { - memo[utxo.txid + '|' + utxo.vout] = utxo; + memo[utxoKey(utxo)] = utxo; return memo; }, {}); diff --git a/test/integration/server.js b/test/integration/server.js index 5b2ae94..166c53c 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -91,27 +91,29 @@ helpers.toSatoshi = function(btc) { helpers.stubUtxos = function(server, wallet, amounts, cb) { var amounts = [].concat(amounts); - async.map(amounts, function(a, next) { - server.createAddress({}, function(err, address) { - next(err, address); - }); - }, - function(err, addresses) { - var i = 0; - var utxos = _.map(amounts, function(amount) { - return { - txid: helpers.randomTXID(), - vout: Math.floor((Math.random() * 10) + 1), - satoshis: helpers.toSatoshi(amount).toString(), - scriptPubKey: addresses[i].getScriptPubKey(wallet.m).toBuffer().toString('hex'), - address: addresses[i++].address, - }; - }); - - blockExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos); - - return cb(utxos); + async.map(_.range(Math.ceil(amounts.length / 2)), function(i, next) { + // async.map(_.range(amounts.length), function(i, next) { + // async.map(_.range(2), function(i, next) { + server.createAddress({}, function(err, address) { + next(err, address); + }); + }, function(err, addresses) { + if (err) throw new Error('Could not generate addresses'); + + var utxos = _.map(amounts, function(amount, i) { + var address = addresses[i % addresses.length]; + return { + txid: helpers.randomTXID(), + 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); + }); }; helpers.stubBroadcast = function(txid) { @@ -146,12 +148,12 @@ helpers.clientSign = function(tx, xprivHex) { .change(tx.changeAddress.address) .sign(privs); - var signatures = []; - _.each(privs, function(p) { - var s = t.getSignatures(p)[0].signature.toDER().toString('hex'); - signatures.push(s); + var signatures = _.map(privs, function(priv, i) { + return _.find(t.getSignatures(priv), { + inputIndex: i + }).signature.toDER().toString('hex'); }); - // + 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'); var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, TestData.copayers[0].privKey); server.createTx(txOpts, function(err, txp) {