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 = {
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',

View File

@ -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) {

View File

@ -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');