From 13472e147a20759836f8d08010aad3a22558f5e8 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 13 Mar 2017 14:23:57 -0300 Subject: [PATCH] add method to get txids from a specified block --- lib/blockchainexplorers/insight.js | 19 +++++++++++++++++-- lib/blockchainmonitor.js | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/blockchainexplorers/insight.js b/lib/blockchainexplorers/insight.js index 6a319bb..5c79fb5 100644 --- a/lib/blockchainexplorers/insight.js +++ b/lib/blockchainexplorers/insight.js @@ -112,7 +112,7 @@ Insight.prototype.getTransactions = function(addresses, from, to, cb) { json: { addrs: [].concat(addresses).join(',') }, - timeout: 120000, + timeout: 120000, }; this._doRequest(args, function(err, res, txs) { @@ -122,7 +122,7 @@ Insight.prototype.getTransactions = function(addresses, from, to, cb) { if (txs.totalItems) total = txs.totalItems; - if (txs.items) + if (txs.items) txs = txs.items; } @@ -183,6 +183,21 @@ Insight.prototype.getBlockchainHeight = function(cb) { }); }; +Insight.prototype.getTxidsInBlock = function(blockHash, cb) { + var self = this; + + var args = { + method: 'GET', + path: this.apiPrefix + '/blocks/' + hash, + json: true, + }; + + this._doRequest(args, function(err, res, body) { + if (err || res.statusCode !== 200) return cb(_parseErr(err, res)); + return cb(null, body.tx); + }); +}; + Insight.prototype.initSocket = function() { // sockets always use the first server on the pull diff --git a/lib/blockchainmonitor.js b/lib/blockchainmonitor.js index 00c462d..caafc63 100644 --- a/lib/blockchainmonitor.js +++ b/lib/blockchainmonitor.js @@ -25,7 +25,7 @@ BlockchainMonitor.prototype.start = function(opts, cb) { async.parallel([ function(done) { - self.explorers = _.map(['livenet', 'testnet'], function(network) { + self.explorers = _.indexBy(_.map(['livenet', 'testnet'], function(network) { var explorer; if (opts.blockchainExplorers) { explorer = opts.blockchainExplorers[network]; @@ -44,7 +44,7 @@ BlockchainMonitor.prototype.start = function(opts, cb) { $.checkState(explorer); self._initExplorer(explorer); return explorer; - }); + }), 'network'); done(); }, function(done) {