Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/insight.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var AddressInfo = require('./models/addressinfo');
* @param {Network=} network whether to use livenet or testnet
* @constructor
*/
function Insight(url, network) {
function Insight(url, network, api) {
if (!url && !network) {
return new Insight(Networks.defaultNetwork);
}
Expand All @@ -35,7 +35,8 @@ function Insight(url, network) {
}
JSUtil.defineImmutable(this, {
url: url,
network: Networks.get(network) || Networks.defaultNetwork
network: Networks.get(network) || Networks.defaultNetwork,
api: api || '/api'
});
this.request = request;
return this;
Expand All @@ -57,7 +58,7 @@ Insight.prototype.getTransaction = function(txid, callback) {
$.checkArgument(_.isString(txid));
$.checkArgument(txid.length === 64);

this.requestGet('/api/tx/' + txid, function(err, res, body) {
this.requestGet(`/tx/${txid}`, function(err, res, body) {
if (err || res.statusCode !== 200) {
return callback(err || res);
}
Expand Down Expand Up @@ -87,7 +88,7 @@ Insight.prototype.getUtxos = function(addresses, callback) {
return new Address(address);
});

this.requestPost('/api/addrs/utxo', {
this.requestPost('/addrs/utxo', {
addrs: _.map(addresses, function(address) {
return address.toString();
}).join(',')
Expand Down Expand Up @@ -125,7 +126,7 @@ Insight.prototype.broadcast = function(transaction, callback) {
transaction = transaction.serialize();
}

this.requestPost('/api/tx/send', {
this.requestPost('/tx/send', {
rawtx: transaction
}, function(err, res, body) {
if (err || res.statusCode !== 200) {
Expand All @@ -150,7 +151,7 @@ Insight.prototype.address = function(address, callback) {
$.checkArgument(_.isFunction(callback));
address = new Address(address);

this.requestGet('/api/addr/' + address.toString(), function(err, res, body) {
this.requestGet(`/addr/${address}`, function(err, res, body) {
if (err || res.statusCode !== 200) {
return callback(err || body);
}
Expand Down Expand Up @@ -179,7 +180,7 @@ Insight.prototype.requestPost = function(path, data, callback) {
$.checkArgument(_.isFunction(callback));
this.request({
method: 'POST',
url: this.url + path,
url: this.url + this.api + path,
json: data
}, callback);
};
Expand All @@ -195,8 +196,9 @@ Insight.prototype.requestGet = function(path, callback) {
$.checkArgument(_.isFunction(callback));
this.request({
method: 'GET',
url: this.url + path
url: this.url + this.api + path
}, callback);
};


module.exports = Insight;