List of transactions by address associated to wallet
This commit is contained in:
parent
37c20b47ac
commit
df9b26fdde
4 changed files with 120 additions and 32 deletions
|
|
@ -29,6 +29,52 @@ function _asyncForEach(array, fn, callback) {
|
|||
}
|
||||
};
|
||||
|
||||
Insight.prototype.getTransactions = function(addresses, cb) {
|
||||
var self = this;
|
||||
|
||||
if (!addresses || !addresses.length) return cb([]);
|
||||
|
||||
var txids = [];
|
||||
var txs = [];
|
||||
|
||||
_asyncForEach(addresses, function(addr, callback) {
|
||||
var options = {
|
||||
host: self.host,
|
||||
port: self.port,
|
||||
scheme: self.scheme,
|
||||
method: 'GET',
|
||||
path: '/api/addr/' + addr,
|
||||
|
||||
headers: { 'Access-Control-Request-Headers' : '' }
|
||||
};
|
||||
|
||||
self._request(options, function(err, res) {
|
||||
var txids_tmp = res.transactions;
|
||||
for(var i=0; i<txids_tmp.length; i++) {
|
||||
txids.push(txids_tmp[i]);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}, function() {
|
||||
_asyncForEach(txids, function(txid, callback2) {
|
||||
var options = {
|
||||
host: self.host,
|
||||
port: self.port,
|
||||
scheme: self.scheme,
|
||||
method: 'GET',
|
||||
path: '/api/tx/' + txid,
|
||||
headers: { 'Access-Control-Request-Headers' : '' }
|
||||
};
|
||||
self._request(options, function(err, res) {
|
||||
txs.push(res);
|
||||
callback2();
|
||||
});
|
||||
}, function() {
|
||||
return cb(txs);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Insight.prototype.getUnspent = function(addresses, cb) {
|
||||
var self = this;
|
||||
|
||||
|
|
@ -98,7 +144,6 @@ Insight.prototype._request = function(options, callback) {
|
|||
request.open(options.method, url, true);
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState === 4) {
|
||||
console.log('[Insight.js.102]', request); //TODO
|
||||
if (request.status === 200) {
|
||||
return callback(null, JSON.parse(request.responseText));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue