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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ Example response:
/insight-api/addr/[:addr]/totalReceived
/insight-api/addr/[:addr]/totalSent
/insight-api/addr/[:addr]/unconfirmedBalance

/insight-api/addrs/[:addrs]/summary
```
The response contains the value in Satoshis.

Expand Down
58 changes: 58 additions & 0 deletions lib/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,64 @@ AddressController.prototype.multitxs = function(req, res) {
});
};

// this call could take a while to run depending on what addresses are used
// considering memory constraints, we will streaming out the results for addresses
// not necessarily in the order we received them


AddressController.prototype.multisummary = function(req, res) {

var self = this;

var addresses;

if (_.isArray(req.addrs)) {
addresses = _.uniq(req.addrs);
} else {
addresses = _.compact(req.addrs.split(','));
}

var addressesLeft = addresses.length;
var startedWriting = false;
var cache = [];

res.write('[');

var sep = ',';

async.eachLimit(addresses, 4, function(addr, next) {

self._address.getAddressSummary(addr, {}, function(err, summary) {

if (err) {
return next(err);
}

if (addressesLeft-- > 0 && startedWriting) {
res.write(sep);
}
startedWriting = true;
sep = '';
cache.push(summary);
res.write(JSON.stringify(summary) + sep);
sep = ',';
next();
});

}, function(err) {

if (err) {
return self.common.handleErrors(err, res);
}

res.write(']');
res.end();
});

};



AddressController.prototype.transformAddressHistoryForMultiTxs = function(txs, options, callback) {
var self = this;

Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ InsightAPI.prototype.setupRoutes = function(app) {
app.get('/addr/:addr/totalReceived', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.totalReceived.bind(addresses));
app.get('/addr/:addr/totalSent', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.totalSent.bind(addresses));
app.get('/addr/:addr/unconfirmedBalance', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.unconfirmedBalance.bind(addresses));

app.get('/addrs/:addrs/summary', this.cacheShort(), addresses.checkAddrs.bind(addresses), addresses.multisummary.bind(addresses));

// Status route
var status = new StatusController(this.node);
Expand Down