From 33827c5b183af493cbd200bc1ae5e6d6d7946f5f Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 28 May 2015 12:50:58 -0300 Subject: [PATCH] add getTransaction method --- lib/blockchainexplorer.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/blockchainexplorer.js b/lib/blockchainexplorer.js index 8da38f2..f2d4482 100644 --- a/lib/blockchainexplorer.js +++ b/lib/blockchainexplorer.js @@ -22,6 +22,7 @@ function BlockChainExplorer(opts) { switch (provider) { case 'insight': var explorer = new Explorers.Insight(url, network); + explorer.getTransaction = _.bind(getTransactionInsight, explorer, url); explorer.getTransactions = _.bind(getTransactionsInsight, explorer, url); explorer.getAddressActivity = _.bind(getAddressActivityInsight, explorer, url); explorer.initSocket = _.bind(initSocketInsight, explorer, url); @@ -31,6 +32,19 @@ function BlockChainExplorer(opts) { }; }; +function getTransactionInsight(url, txid, cb) { + var url = url + '/api/tx/' + txid; + var args = { + method: "GET", + url: url, + }; + + request(args, function(err, res, tx) { + if (err || res.statusCode != 200) return cb(err || res); + return cb(null, tx); + }); +}; + function getTransactionsInsight(url, addresses, from, to, cb) { var qs = []; if (_.isNumber(from)) qs.push('from=' + from);