rm BLOCKCHAINERROR error code

This commit is contained in:
Ivan Socolsky 2015-08-02 19:48:18 -03:00
parent e474c71a1e
commit 602bc9a9a3
3 changed files with 16 additions and 35 deletions

View File

@ -6,7 +6,6 @@ var ClientError = require('./clienterror');
var errors = { var errors = {
BADSIGNATURES: 'Bad signatures', BADSIGNATURES: 'Bad signatures',
BLOCKCHAINERROR: 'An error ocurred while trying to interact with the blockchain explorer',
CDATAMISMATCH: 'Copayer data mismatch', CDATAMISMATCH: 'Copayer data mismatch',
CINWALLET: 'Copayer already in wallet', CINWALLET: 'Copayer already in wallet',
CREGISTERED: 'Copayer ID already registered on server', CREGISTERED: 'Copayer ID already registered on server',

View File

@ -640,10 +640,8 @@ WalletService.prototype.getUtxos = function(cb) {
var bc = self._getBlockchainExplorer(networkName); var bc = self._getBlockchainExplorer(networkName);
bc.getUnspentUtxos(addressStrs, function(err, inutxos) { bc.getUnspentUtxos(addressStrs, function(err, inutxos) {
if (err) { if (err) return cb(err);
log.error('Could not fetch unspent outputs', err);
return cb(new ClientError(Errors.codes.BLOCKCHAINERROR, 'Could not fetch unspent outputs'));
}
var utxos = _.map(inutxos, function(utxo) { var utxos = _.map(inutxos, function(utxo) {
var u = _.pick(utxo, ['txid', 'vout', 'address', 'scriptPubKey', 'amount', 'satoshis', 'confirmations']); var u = _.pick(utxo, ['txid', 'vout', 'address', 'scriptPubKey', 'amount', 'satoshis', 'confirmations']);
u.confirmations = u.confirmations || 0; u.confirmations = u.confirmations || 0;
@ -1172,10 +1170,7 @@ WalletService.prototype._broadcastTx = function(txp, cb) {
} }
var bc = this._getBlockchainExplorer(txp.getNetworkName()); var bc = this._getBlockchainExplorer(txp.getNetworkName());
bc.broadcast(raw, function(err, txid) { bc.broadcast(raw, function(err, txid) {
if (err) { if (err) return cb(err);
log.error('Could not broadcast transaction', err);
return cb(new ClientError(Errors.codes.BLOCKCHAINERROR, 'Could not broadcast transaction'));
}
return cb(null, txid); return cb(null, txid);
}) })
}; };
@ -1184,10 +1179,7 @@ WalletService.prototype._checkTxInBlockchain = function(txp, cb) {
var tx = txp.getBitcoreTx(); var tx = txp.getBitcoreTx();
var bc = this._getBlockchainExplorer(txp.getNetworkName()); var bc = this._getBlockchainExplorer(txp.getNetworkName());
bc.getTransaction(tx.id, function(err, tx) { bc.getTransaction(tx.id, function(err, tx) {
if (err) { if (err) return cb(err);
log.error('Could not get transaction info', err);
return cb(new ClientError(Errors.codes.BLOCKCHAINERROR, 'Could not get transaction info'));
}
return cb(null, tx); return cb(null, tx);
}) })
}; };
@ -1600,10 +1592,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
var from = opts.skip || 0; var from = opts.skip || 0;
var to = from + (_.isUndefined(opts.limit) ? 100 : opts.limit); var to = from + (_.isUndefined(opts.limit) ? 100 : opts.limit);
bc.getTransactions(addressStrs, from, to, function(err, txs) { bc.getTransactions(addressStrs, from, to, function(err, txs) {
if (err) { if (err) return cb(err);
log.error('Could not fetch transactions', err);
return next(new ClientError(Errors.codes.BLOCKCHAINERROR, 'Could not fetch transactions'));
}
next(null, self._normalizeTxHistory(txs)); next(null, self._normalizeTxHistory(txs));
}); });
}, },
@ -1656,10 +1645,7 @@ WalletService.prototype.scan = function(opts, cb) {
if (err) return next(err); if (err) return next(err);
networkName = networkName || Bitcore.Address(addresses[0].address).toObject().network; networkName = networkName || Bitcore.Address(addresses[0].address).toObject().network;
checkActivity(_.pluck(addresses, 'address'), networkName, function(err, thereIsActivity) { checkActivity(_.pluck(addresses, 'address'), networkName, function(err, thereIsActivity) {
if (err) { if (err) return cb(err);
log.error('Could not check address activity', err);
return next(new ClientError(Errors.codes.BLOCKCHAINERROR, 'Could not check address activity'));
}
activity = thereIsActivity; activity = thereIsActivity;
if (thereIsActivity) { if (thereIsActivity) {

View File

@ -169,10 +169,6 @@ helpers.stubBroadcast = function(txid) {
blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, null, txid); blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, null, txid);
}; };
helpers.stubBroadcastFail = function() {
blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, 'broadcast error');
};
helpers.stubHistory = function(txs) { helpers.stubHistory = function(txs) {
blockchainExplorer.getTransactions = function(addresses, from, to, cb) { blockchainExplorer.getTransactions = function(addresses, from, to, cb) {
var MAX_BATCH_SIZE = 100; var MAX_BATCH_SIZE = 100;
@ -1452,7 +1448,7 @@ describe('Wallet service', function() {
should.not.exist(err); should.not.exist(err);
server.getBalance({}, function(err, balance) { server.getBalance({}, function(err, balance) {
should.exist(err); should.exist(err);
err.code.should.equal('BLOCKCHAINERROR'); err.toString().should.equal('dummy error');
done(); done();
}); });
}); });
@ -1731,7 +1727,7 @@ describe('Wallet service', function() {
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, 'some message', TestData.copayers[0].privKey_1H_0); var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, 'some message', TestData.copayers[0].privKey_1H_0);
server.createTx(txOpts, function(err, tx) { server.createTx(txOpts, function(err, tx) {
should.exist(err); should.exist(err);
err.code.should.equal('BLOCKCHAINERROR'); err.toString().should.equal('dummy error');
done(); done();
}); });
}); });
@ -2602,13 +2598,13 @@ describe('Wallet service', function() {
}); });
it('should keep tx as accepted if unable to broadcast it', function(done) { 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); blockchainExplorer.getTransaction = sinon.stub().callsArgWith(1, null, null);
server.broadcastTx({ server.broadcastTx({
txProposalId: txpid txProposalId: txpid
}, function(err) { }, function(err) {
should.exist(err); should.exist(err);
err.code.should.equal('BLOCKCHAINERROR'); err.toString().should.equal('broadcast error');
server.getTx({ server.getTx({
txProposalId: txpid txProposalId: txpid
}, function(err, txp) { }, 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) { 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, { blockchainExplorer.getTransaction = sinon.stub().callsArgWith(1, null, {
txid: '999' 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) { 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'); blockchainExplorer.getTransaction = sinon.stub().callsArgWith(1, 'bc check error');
server.broadcastTx({ server.broadcastTx({
txProposalId: txpid txProposalId: txpid
}, function(err) { }, function(err) {
should.exist(err); should.exist(err);
err.code.should.equal('BLOCKCHAINERROR'); err.toString().should.equal('bc check error');
server.getTx({ server.getTx({
txProposalId: txpid txProposalId: txpid
}, function(err, txp) { }, function(err, txp) {
@ -3085,7 +3081,7 @@ describe('Wallet service', function() {
it('should notify sign and acceptance', function(done) { it('should notify sign and acceptance', function(done) {
server.getPendingTxs({}, function(err, txs) { server.getPendingTxs({}, function(err, txs) {
helpers.stubBroadcastFail(); blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, 'broadcast error');
var tx = txs[0]; var tx = txs[0];
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey); var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
server.signTx({ server.signTx({
@ -3770,7 +3766,7 @@ describe('Wallet service', function() {
blockchainExplorer.getTransactions = sinon.stub().callsArgWith(3, 'dummy error'); blockchainExplorer.getTransactions = sinon.stub().callsArgWith(3, 'dummy error');
server.getTxHistory({}, function(err, txs) { server.getTxHistory({}, function(err, txs) {
should.exist(err); should.exist(err);
err.code.should.equal('BLOCKCHAINERROR'); err.toString().should.equal('dummy error');
done(); done();
}); });
}); });
@ -3920,7 +3916,7 @@ describe('Wallet service', function() {
blockchainExplorer.getAddressActivity = sinon.stub().callsArgWith(1, 'dummy error'); blockchainExplorer.getAddressActivity = sinon.stub().callsArgWith(1, 'dummy error');
server.scan({}, function(err) { server.scan({}, function(err) {
should.exist(err); should.exist(err);
err.code.should.equal('BLOCKCHAINERROR'); err.toString().should.equal('dummy error');
server.getWallet({}, function(err, wallet) { server.getWallet({}, function(err, wallet) {
should.not.exist(err); should.not.exist(err);
wallet.scanStatus.should.equal('error'); wallet.scanStatus.should.equal('error');