From 602bc9a9a390e5730041739cfb1a89a7635d9852 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Sun, 2 Aug 2015 19:48:18 -0300 Subject: [PATCH] rm BLOCKCHAINERROR error code --- lib/errors/errordefinitions.js | 1 - lib/server.js | 26 ++++++-------------------- test/integration/server.js | 24 ++++++++++-------------- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/lib/errors/errordefinitions.js b/lib/errors/errordefinitions.js index d88d701..aa33e98 100644 --- a/lib/errors/errordefinitions.js +++ b/lib/errors/errordefinitions.js @@ -6,7 +6,6 @@ var ClientError = require('./clienterror'); var errors = { BADSIGNATURES: 'Bad signatures', - BLOCKCHAINERROR: 'An error ocurred while trying to interact with the blockchain explorer', CDATAMISMATCH: 'Copayer data mismatch', CINWALLET: 'Copayer already in wallet', CREGISTERED: 'Copayer ID already registered on server', diff --git a/lib/server.js b/lib/server.js index d60b146..11144b9 100644 --- a/lib/server.js +++ b/lib/server.js @@ -640,10 +640,8 @@ WalletService.prototype.getUtxos = function(cb) { var bc = self._getBlockchainExplorer(networkName); bc.getUnspentUtxos(addressStrs, function(err, inutxos) { - if (err) { - log.error('Could not fetch unspent outputs', err); - return cb(new ClientError(Errors.codes.BLOCKCHAINERROR, 'Could not fetch unspent outputs')); - } + if (err) return cb(err); + var utxos = _.map(inutxos, function(utxo) { var u = _.pick(utxo, ['txid', 'vout', 'address', 'scriptPubKey', 'amount', 'satoshis', 'confirmations']); u.confirmations = u.confirmations || 0; @@ -1172,10 +1170,7 @@ WalletService.prototype._broadcastTx = function(txp, cb) { } var bc = this._getBlockchainExplorer(txp.getNetworkName()); bc.broadcast(raw, function(err, txid) { - if (err) { - log.error('Could not broadcast transaction', err); - return cb(new ClientError(Errors.codes.BLOCKCHAINERROR, 'Could not broadcast transaction')); - } + if (err) return cb(err); return cb(null, txid); }) }; @@ -1184,10 +1179,7 @@ WalletService.prototype._checkTxInBlockchain = function(txp, cb) { var tx = txp.getBitcoreTx(); var bc = this._getBlockchainExplorer(txp.getNetworkName()); bc.getTransaction(tx.id, function(err, tx) { - if (err) { - log.error('Could not get transaction info', err); - return cb(new ClientError(Errors.codes.BLOCKCHAINERROR, 'Could not get transaction info')); - } + if (err) return cb(err); return cb(null, tx); }) }; @@ -1600,10 +1592,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) { var from = opts.skip || 0; var to = from + (_.isUndefined(opts.limit) ? 100 : opts.limit); bc.getTransactions(addressStrs, from, to, function(err, txs) { - if (err) { - log.error('Could not fetch transactions', err); - return next(new ClientError(Errors.codes.BLOCKCHAINERROR, 'Could not fetch transactions')); - } + if (err) return cb(err); next(null, self._normalizeTxHistory(txs)); }); }, @@ -1656,10 +1645,7 @@ WalletService.prototype.scan = function(opts, cb) { if (err) return next(err); networkName = networkName || Bitcore.Address(addresses[0].address).toObject().network; checkActivity(_.pluck(addresses, 'address'), networkName, function(err, thereIsActivity) { - if (err) { - log.error('Could not check address activity', err); - return next(new ClientError(Errors.codes.BLOCKCHAINERROR, 'Could not check address activity')); - } + if (err) return cb(err); activity = thereIsActivity; if (thereIsActivity) { diff --git a/test/integration/server.js b/test/integration/server.js index 70e89eb..ed796d9 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -169,10 +169,6 @@ helpers.stubBroadcast = function(txid) { blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, null, txid); }; -helpers.stubBroadcastFail = function() { - blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, 'broadcast error'); -}; - helpers.stubHistory = function(txs) { blockchainExplorer.getTransactions = function(addresses, from, to, cb) { var MAX_BATCH_SIZE = 100; @@ -1452,7 +1448,7 @@ describe('Wallet service', function() { should.not.exist(err); server.getBalance({}, function(err, balance) { should.exist(err); - err.code.should.equal('BLOCKCHAINERROR'); + err.toString().should.equal('dummy error'); done(); }); }); @@ -1731,7 +1727,7 @@ describe('Wallet service', function() { var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, 'some message', TestData.copayers[0].privKey_1H_0); server.createTx(txOpts, function(err, tx) { should.exist(err); - err.code.should.equal('BLOCKCHAINERROR'); + err.toString().should.equal('dummy error'); done(); }); }); @@ -2602,13 +2598,13 @@ describe('Wallet service', function() { }); it('should keep tx as accepted if unable to broadcast it', function(done) { - helpers.stubBroadcastFail(); + blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, 'broadcast error'); blockchainExplorer.getTransaction = sinon.stub().callsArgWith(1, null, null); server.broadcastTx({ txProposalId: txpid }, function(err) { should.exist(err); - err.code.should.equal('BLOCKCHAINERROR'); + err.toString().should.equal('broadcast error'); server.getTx({ txProposalId: txpid }, function(err, txp) { @@ -2623,7 +2619,7 @@ describe('Wallet service', function() { }); it('should mark tx as broadcasted if accepted but already in blockchain', function(done) { - helpers.stubBroadcastFail(); + blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, 'broadcast error'); blockchainExplorer.getTransaction = sinon.stub().callsArgWith(1, null, { txid: '999' }); @@ -2645,13 +2641,13 @@ describe('Wallet service', function() { }); it('should keep tx as accepted if broadcast fails and cannot check tx in blockchain', function(done) { - helpers.stubBroadcastFail(); + blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, 'broadcast error'); blockchainExplorer.getTransaction = sinon.stub().callsArgWith(1, 'bc check error'); server.broadcastTx({ txProposalId: txpid }, function(err) { should.exist(err); - err.code.should.equal('BLOCKCHAINERROR'); + err.toString().should.equal('bc check error'); server.getTx({ txProposalId: txpid }, function(err, txp) { @@ -3085,7 +3081,7 @@ describe('Wallet service', function() { it('should notify sign and acceptance', function(done) { server.getPendingTxs({}, function(err, txs) { - helpers.stubBroadcastFail(); + blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, 'broadcast error'); var tx = txs[0]; var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey); server.signTx({ @@ -3770,7 +3766,7 @@ describe('Wallet service', function() { blockchainExplorer.getTransactions = sinon.stub().callsArgWith(3, 'dummy error'); server.getTxHistory({}, function(err, txs) { should.exist(err); - err.code.should.equal('BLOCKCHAINERROR'); + err.toString().should.equal('dummy error'); done(); }); }); @@ -3920,7 +3916,7 @@ describe('Wallet service', function() { blockchainExplorer.getAddressActivity = sinon.stub().callsArgWith(1, 'dummy error'); server.scan({}, function(err) { should.exist(err); - err.code.should.equal('BLOCKCHAINERROR'); + err.toString().should.equal('dummy error'); server.getWallet({}, function(err, wallet) { should.not.exist(err); wallet.scanStatus.should.equal('error');