Skip to content
Open
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,40 @@ which is the hash of the Genesis block (0 height)
```
The response contains the value in Satoshis.

### Multiple Addresss
GET method:
```
/insight-api/addrs/[:addrs]
/insight-api/addrs/2NF2baYuJAkCKo5onjUKEPdARQkZ6SYyKd5,2NAre8sX2povnjy4aeiHKeEh97Qhn97tB1f
```

POST method:
```
/insight-api/addrs/[:addrs]
```

POST params:
```
addrs: 2NF2baYuJAkCKo5onjUKEPdARQkZ6SYyKd5,2NAre8sX2povnjy4aeiHKeEh97Qhn97tB1f
```

### Address Properties for Multiple Addresses
GET method:
```
/insight-api/addrs/[:addrs]/balance
/insight-api/addrs/[:addrs]/totalReceived
/insight-api/addrs/[:addrs]/totalSent
/insight-api/addrs/[:addrs]/unconfirmedBalance
```

POST method:
```
/insight-api/addrs/balance
/insight-api/addrs/totalReceived
/insight-api/addrs/totalSent
/insight-api/addrs/unconfirmedBalance
```

### Unspent Outputs
```
/insight-api/addr/[:addr]/utxo[?noCache=1]
Expand Down
64 changes: 64 additions & 0 deletions lib/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,69 @@ AddressController.prototype.getAddressSummary = function(address, options, callb
});
};

AddressController.prototype.multishow = function(req, res) {
var self = this;

var options = {
noTxList: parseInt(req.query.noTxList)
};

if(req.body.addrs) {
req.addrs = req.body.addrs.split(',');
} else {
req.addrs = req.params.addrs.split(',');
}

async.map(req.addrs, function(address, callback) {
self.getAddressSummary(address, options, function(err, data) {
if (err) return callback(err);
callback(null, data);
});
}, function(err, results) {
if (err) return common.handleErrors(err, res);
res.jsonp(results);
});
};

AddressController.prototype.multiBalance = function(req, res) {
this.multiAddressSummarySubQuery(req, res, 'balanceSat');
};

AddressController.prototype.multiTotalReceived = function(req, res) {
this.multiAddressSummarySubQuery(req, res, 'totalReceivedSat');
};

AddressController.prototype.multiTotalSent = function(req, res) {
this.multiAddressSummarySubQuery(req, res, 'totalSentSat');
};

AddressController.prototype.multiUnconfirmedBalance = function(req, res) {
this.multiAddressSummarySubQuery(req, res, 'unconfirmedBalanceSat');
};

AddressController.prototype.multiAddressSummarySubQuery = function(req, res, param) {
var self = this;

if(req.body.addrs) {
req.addrs = req.body.addrs.split(',');
} else {
req.addrs = req.params.addrs.split(',');
}

async.map(req.addrs, function(address, callback) {
self.getAddressSummary(address, { noTxList: 1 }, function(err, data) {
if (err) return callback(err);

var ret = { addrStr: address }
ret[param] = data[param];
callback(null, ret);
});
}, function(err, results) {
if (err) return common.handleErrors(err, res);
res.jsonp(results);
});
};

AddressController.prototype.checkAddr = function(req, res, next) {
req.addr = req.params.addr;
this.check(req, res, next, [req.addr]);
Expand Down Expand Up @@ -150,6 +213,7 @@ AddressController.prototype.transformUtxo = function(utxo) {
ts: utxo.timestamp ? parseInt(utxo.timestamp) : Date.now(),
scriptPubKey: utxo.script,
amount: utxo.satoshis / 1e8,
satoshis: utxo.satoshis,
confirmations: utxo.confirmations
};
};
Expand Down
10 changes: 10 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ InsightAPI.prototype.setupRoutes = function(app) {
var addresses = new AddressController(this.node);
app.get('/addr/:addr', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.show.bind(addresses));
app.get('/addr/:addr/utxo', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.utxo.bind(addresses));
app.get('/addrs/:addrs', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multishow.bind(addresses));
app.post('/addrs', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multishow.bind(addresses));
app.get('/addrs/:addrs/utxo', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiutxo.bind(addresses));
app.post('/addrs/utxo', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiutxo.bind(addresses));
app.get('/addrs/:addrs/txs', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multitxs.bind(addresses));
Expand All @@ -132,6 +134,14 @@ InsightAPI.prototype.setupRoutes = function(app) {
app.get('/addr/:addr/totalReceived', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.totalReceived.bind(addresses));
app.get('/addr/:addr/totalSent', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.totalSent.bind(addresses));
app.get('/addr/:addr/unconfirmedBalance', this.cacheShort(), addresses.checkAddr.bind(addresses), addresses.unconfirmedBalance.bind(addresses));
app.get('/addrs/:addrs/balance', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiBalance.bind(addresses));
app.post('/addrs/balance', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiBalance.bind(addresses));
app.get('/addrs/:addrs/totalReceived', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiTotalReceived.bind(addresses));
app.post('/addrs/totalReceived', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiTotalReceived.bind(addresses));
app.get('/addrs/:addrs/totalSent', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiTotalSent.bind(addresses));
app.post('/addrs/totalSent', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiTotalSent.bind(addresses));
app.get('/addrs/:addrs/unconfirmedBalance', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiUnconfirmedBalance.bind(addresses));
app.post('/addrs/unconfirmedBalance', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multiUnconfirmedBalance.bind(addresses));

// Status route
var status = new StatusController(this.node);
Expand Down
3 changes: 3 additions & 0 deletions test/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ describe('Addresses', function() {
"ts": 1441116143,
"scriptPubKey": "76a914d2ec20bb8e5f25a52f730384b803d95683250e0b88ac",
"amount": 0.5332,
"satoshis": 53320000,
"confirmations": 50,
"confirmationsFromCache": true
}
Expand Down Expand Up @@ -327,6 +328,7 @@ describe('Addresses', function() {
"ts": 1441116143,
"scriptPubKey": "76a914d2ec20bb8e5f25a52f730384b803d95683250e0b88ac",
"amount": 0.5332,
"satoshis": 53320000,
"confirmations": 50,
"confirmationsFromCache": true
},
Expand All @@ -337,6 +339,7 @@ describe('Addresses', function() {
"ts": 1441116143,
"scriptPubKey": "76a914583df9fa56ad961051e00ca93e68dfaf1eab9ec588ac",
"amount": 0.00289829,
"satoshis": 289829,
"confirmations": 50,
"confirmationsFromCache": true
}
Expand Down