Merge pull request #847 from matiu/bug/handleInsightErrors
handle empty Insight responses
This commit is contained in:
commit
6e442cd902
2 changed files with 35 additions and 4 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
var imports = require('soop').imports();
|
var imports = require('soop').imports();
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
|
var preconditions = require('preconditions').singleton();
|
||||||
|
|
||||||
var http;
|
var http;
|
||||||
if (process.version) {
|
if (process.version) {
|
||||||
|
|
@ -78,8 +79,10 @@ Insight.prototype._getOptions = function(method, path, data) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Insight.prototype.getTransactions = function(addresses, cb) {
|
Insight.prototype.getTransactions = function(addresses, cb) {
|
||||||
var self = this;
|
preconditions.shouldBeArray(addresses);
|
||||||
|
preconditions.shouldBeFunction(cb);
|
||||||
|
|
||||||
|
var self = this;
|
||||||
if (!addresses || !addresses.length) return cb([]);
|
if (!addresses || !addresses.length) return cb([]);
|
||||||
|
|
||||||
var txids = [];
|
var txids = [];
|
||||||
|
|
@ -87,10 +90,13 @@ Insight.prototype.getTransactions = function(addresses, cb) {
|
||||||
|
|
||||||
_asyncForEach(addresses, function(addr, callback) {
|
_asyncForEach(addresses, function(addr, callback) {
|
||||||
var options = self._getOptions('GET', '/api/addr/' + addr);
|
var options = self._getOptions('GET', '/api/addr/' + addr);
|
||||||
|
|
||||||
self._request(options, function(err, res) {
|
self._request(options, function(err, res) {
|
||||||
var txids_tmp = res.transactions;
|
if (res && res.transactions) {
|
||||||
for (var i = 0; i < txids_tmp.length; i++) {
|
var txids_tmp = res.transactions;
|
||||||
txids.push(txids_tmp[i]);
|
for (var i = 0; i < txids_tmp.length; i++) {
|
||||||
|
txids.push(txids_tmp[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,8 @@ describe('Insight model', function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('#checkActivity for innactive addreses', function(done) {
|
it('#checkActivity for innactive addreses', function(done) {
|
||||||
var w = new Insight();
|
var w = new Insight();
|
||||||
w.getTransactions = function(addresses, cb) {
|
w.getTransactions = function(addresses, cb) {
|
||||||
|
|
@ -176,4 +178,27 @@ describe('Insight model', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should handle getTransaction null response', function(done) {
|
||||||
|
var w = new Insight();
|
||||||
|
w._request = sinon.stub().yields();
|
||||||
|
w.getTransactions(['asdasd'], function(ret) {
|
||||||
|
ret.length.should.equal(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
it('should handle getTransaction empty response', function(done) {
|
||||||
|
var w = new Insight();
|
||||||
|
w._request = sinon.stub().yields([]);
|
||||||
|
w.getTransactions(['asdasd'], function(ret) {
|
||||||
|
ret.length.should.equal(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue