diff --git a/bit-wallet/bit-status b/bit-wallet/bit-status index 2bb188a..c904d0b 100755 --- a/bit-wallet/bit-status +++ b/bit-wallet/bit-status @@ -34,9 +34,6 @@ client.getStatus(function(err, res) { return a.copayerName + ': ' + a.type + '' }).join('. ')); } - - if (program.verbose) - console.log('* Raw Server Response:\n', res); //TODO }); } }); diff --git a/lib/client/api.js b/lib/client/api.js index 1e65eb0..2783609 100644 --- a/lib/client/api.js +++ b/lib/client/api.js @@ -152,7 +152,7 @@ API.prototype._initData = function(network, walletPrivKey, m, n) { var xPrivKey = new Bitcore.HDPrivateKey(network); var signingPrivKey = (new Bitcore.HDPrivateKey(xPrivKey)).derive('m/1/0').privateKey.toWIF(); var xPubKey = (new Bitcore.HDPublicKey(xPrivKey)).toString(); - var copayerId = WalletUtils.xpubToCopayerId(xPubKey); + var copayerId = WalletUtils.xPubToCopayerId(xPubKey); var data = { copayerId: copayerId, @@ -279,6 +279,10 @@ API.prototype.getStatus = function(cb) { var url = '/v1/wallets/'; self._doGetRequest(url, data, function(err, body) { + _.each(body.pendingTxps, function(txp) { + txp.message = _decryptProposalMessage(txp.message, data.signingPrivKey); + }); + return cb(err, body, data.copayerId); }); }); @@ -413,7 +417,7 @@ API.prototype.getTxProposals = function(opts, cb) { if (err) return cb(err); _.each(txps, function(txp) { - txp.message = self._decryptProposalMessage(txp.message, data.signingPrivKey); + txp.message = _decryptProposalMessage(txp.message, data.signingPrivKey); }); return cb(null, txps); }); diff --git a/lib/model/txproposal.js b/lib/model/txproposal.js index fb04a9b..174479d 100644 --- a/lib/model/txproposal.js +++ b/lib/model/txproposal.js @@ -90,6 +90,7 @@ TxProposal.prototype._getBitcoreTx = function() { var self = this; var t = new Bitcore.Transaction(); + _.each(this.inputs, function(i) { t.from(i, i.publicKeys, self.requiredSignatures) }); @@ -99,7 +100,6 @@ TxProposal.prototype._getBitcoreTx = function() { t._updateChangeOutput(); - var sigs = this._getCurrentSignatures(); _.each(sigs, function(x) { self._addSignaturesToBitcoreTx(t, x.signatures, x.xpub); diff --git a/lib/server.js b/lib/server.js index 8ee149c..89d6b48 100644 --- a/lib/server.js +++ b/lib/server.js @@ -378,6 +378,8 @@ CopayServer.prototype._getUtxos = function(cb) { // Needed for the clients to sign UTXOs _.each(utxos, function(utxo) { + utxo.satoshis = utxo.satoshis ? +utxo.satoshis : Utils.strip(utxo.amount * 1e8); + delete utxo.amount; utxo.path = addressToPath[utxo.address].path; utxo.publicKeys = addressToPath[utxo.address].publicKeys; }); @@ -402,13 +404,13 @@ CopayServer.prototype.getBalance = function(opts, cb) { var balance = {}; balance.totalAmount = Utils.strip(_.reduce(utxos, function(sum, utxo) { - return sum + self._inputSatoshis(utxo); + return sum + utxo.satoshis; }, 0)); balance.lockedAmount = Utils.strip(_.reduce(_.filter(utxos, { locked: true }), function(sum, utxo) { - return sum + self._inputSatoshis(utxo); + return sum + utxo.satoshis; }, 0)); return cb(null, balance); @@ -416,11 +418,6 @@ CopayServer.prototype.getBalance = function(opts, cb) { }; -// TODO: should be in Utils -CopayServer.prototype._inputSatoshis = function(i) { - return i.amount ? Utils.strip(i.amount * 1e8) : i.satoshis; -}; - CopayServer.prototype._selectUtxos = function(txp, utxos) { var i = 0; var total = 0; @@ -429,7 +426,7 @@ CopayServer.prototype._selectUtxos = function(txp, utxos) { while (i < inputs.length) { selected.push(inputs[i]); - total += this._inputSatoshis(inputs[i]); + total += inputs[i].satoshis; if (total >= txp.amount + Bitcore.Transaction.FEE_PER_KB) { try { diff --git a/test/integration/clientApi.js b/test/integration/clientApi.js index 526e557..d820989 100644 --- a/test/integration/clientApi.js +++ b/test/integration/clientApi.js @@ -169,6 +169,25 @@ describe('client API ', function() { }); }); + + describe('#getTxProposals', function() { + it('should return tx proposals and decrypt message', function(done) { + client.storage.fs.readFile = sinon.stub().yields(null, JSON.stringify(TestData.storage.complete11)); + var request = sinon.mock().yields(null, { + statusCode: 200 + }, TestData.serverResponse.pendingTxs); + client.request = request; + + client.getTxProposals({}, function(err, x) { + should.not.exist(err); + x.length.should.equal(1); + x[0].id.should.equal(TestData.serverResponse.pendingTxs[0].id); + x[0].message.should.equal('hola'); + done(); + }); + }); + }); + describe('#recreate', function() { it.skip('Should recreate a wallet acording stored data', function(done) {}); }); diff --git a/test/integration/clienttestdata.js b/test/integration/clienttestdata.js index 440a455..c390ae0 100644 --- a/test/integration/clienttestdata.js +++ b/test/integration/clienttestdata.js @@ -30,6 +30,16 @@ var storage = { "signingPrivKey": "KyhU3befBaePqHuPQNNyY1XFUgnArR3GUKZpZwV5vS7u1pcR3uzB", "network": "livenet" }, + complete11: { + "copayerId": "02da4d1bd797b41a5565fe54f22583051bd3c29dbbc86eedadb6af6e9200af1048", + "xPrivKey": "tprv8ZgxMBicQKsPeCyWCzmvnAkJUBEKpqggFmEmaR6CeyHeJj8oB8uFRWZonK7qLD1ih35tiRr1xnXg9a2rGLiYGQWVgvjhubzuUvVyanPXNuU", + "publicKeyRing": ["tpubD6NzVbkrYhZ4Xg1J6eSXBaQR3CkFzAsaq4qYrw8W5F639DPZoXiqc1BfxSR2J1muzEE2qq7rZEDUgwyuwv1nYQgA9uorLghrT76FE5CjAuz"], + "network": "testnet", + "m": 1, + "n": 1, + "signingPrivKey": "Kzs8tquNTCsxwbEB9RiSNmcti4QXaW1i9UyLBV329VM5zU7o5nGB", + "walletPrivKey": "L259i9W123MrrEjBUTzPVvo3ZMoJV26WB7Abr9LcVsiuWpj6sEL1" + }, }; var serverResponse = { @@ -124,6 +134,32 @@ var serverResponse = { }, ], } }, + pendingTxs: [{ + version: '1.0.0', + createdOn: 1424287779, + id: '01424287779165d80a7123-f5c4-4144-ac1b-663220c01c55', + creatorId: '02da4d1bd797b41a5565fe54f22583051bd3c29dbbc86eedadb6af6e9200af1048', + toAddress: 'n2TBMPzPECGUfcT2EByiTJ12TPZkhN2mN5', + amount: 10000, + message: '{"iv":"Ij6LjNp6Cjlrpx1MklQk9A==","v":1,"iter":1,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","ct":"uyxcL8bBgRS0W2KA"}', + changeAddress: '2Mu4nmHhBWFk766M4yXJi2oyi59HZLKHWqn', + inputs: [{ + address: '2MvBhgsQX6EusXvNGdcjM5dschDkaos1uuk', + txid: '006a2915d8f1811620f8b83357869a94c53714f90ce4be4a5ca0d5305a21400d', + vout: 0, + scriptPubKey: 'a914203dd60a7659995a6e3bba7caac3c2d684c836ce87', + amount: 0.1, + path: 'm/2147483647/0/0', + publicKeys: ['0371629fe3547002723ef57ad4dae0d97653cf89b0a570637cffca2f23982f0f92'] + }], + requiredSignatures: 1, + requiredRejections: 1, + status: 'pending', + inputPaths: ['m/2147483647/0/0'], + actions: {}, + creatorName: 'ematiu' + }], + }; module.exports.serverResponse = serverResponse; diff --git a/test/integration/server.js b/test/integration/server.js index ad48009..88235ca 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -106,7 +106,7 @@ helpers.createUtxos = function(server, wallet, amounts, cb) { return { txid: helpers.randomTXID(), vout: Math.floor((Math.random() * 10) + 1), - satoshis: helpers.toSatoshi(amount), + satoshis: helpers.toSatoshi(amount).toString(), scriptPubKey: addresses[i].getScriptPubKey(wallet.m).toBuffer().toString('hex'), address: addresses[i++].address, };