|
|
@ -16,6 +16,15 @@ function Insight(opts) { |
|
|
|
this.url = opts.url; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var _parseErr = function(err, res) { |
|
|
|
if (err) { |
|
|
|
return "Insight Error"; |
|
|
|
} |
|
|
|
log.warn("Insight " + res.request.href + " Returned Status: " + res.statusCode); |
|
|
|
return "Error querying the blockchain"; |
|
|
|
}; |
|
|
|
|
|
|
|
Insight.prototype.getConnectionInfo = function() { |
|
|
|
return 'Insight (' + this.network + ') @ ' + this.url; |
|
|
|
}; |
|
|
@ -34,7 +43,7 @@ Insight.prototype.getUnspentUtxos = function(addresses, cb) { |
|
|
|
}; |
|
|
|
|
|
|
|
request(args, function(err, res, unspent) { |
|
|
|
if (err || res.statusCode !== 200) return cb(err || res); |
|
|
|
if (err || res.statusCode !== 200) return cb(_parseErr(err,res)); |
|
|
|
return cb(null, unspent); |
|
|
|
}); |
|
|
|
}; |
|
|
@ -53,7 +62,7 @@ Insight.prototype.broadcast = function(rawTx, cb) { |
|
|
|
}; |
|
|
|
|
|
|
|
request(args, function(err, res, body) { |
|
|
|
if (err || res.statusCode !== 200) return cb(err || res); |
|
|
|
if (err || res.statusCode !== 200) return cb(_parseErr(err,res)); |
|
|
|
return cb(null, body ? body.txid : null); |
|
|
|
}); |
|
|
|
}; |
|
|
@ -66,7 +75,7 @@ Insight.prototype.getTransaction = function(txid, cb) { |
|
|
|
}; |
|
|
|
|
|
|
|
request(args, function(err, res, tx) { |
|
|
|
if (err || res.statusCode != 200) return cb(err || res); |
|
|
|
if (err || res.statusCode !== 200) return cb(_parseErr(err,res)); |
|
|
|
return cb(null, tx); |
|
|
|
}); |
|
|
|
}; |
|
|
@ -86,7 +95,7 @@ Insight.prototype.getTransactions = function(addresses, from, to, cb) { |
|
|
|
}; |
|
|
|
|
|
|
|
request(args, function(err, res, txs) { |
|
|
|
if (err || res.statusCode != 200) return cb(err || res); |
|
|
|
if (err || res.statusCode !== 200) return cb(_parseErr(err,res)); |
|
|
|
|
|
|
|
if (_.isObject(txs) && txs.items) |
|
|
|
txs = txs.items; |
|
|
@ -117,7 +126,7 @@ Insight.prototype.estimateFee = function(nbBlocks, cb) { |
|
|
|
json: true, |
|
|
|
}; |
|
|
|
request(args, function(err, res, body) { |
|
|
|
if (err || res.statusCode !== 200) return cb(err || res); |
|
|
|
if (err || res.statusCode !== 200) return cb(_parseErr(err,res)); |
|
|
|
return cb(null, body); |
|
|
|
}); |
|
|
|
}; |
|
|
|