From 6923b9bed970f93866a2a383ac100626d6b60900 Mon Sep 17 00:00:00 2001 From: Esteban Ordano Date: Wed, 14 Jan 2015 11:43:57 -0300 Subject: [PATCH] Drop explorers --- docs/guide/insight.md | 36 --------- lib/transport/explorers/index.js | 3 - lib/transport/explorers/insight.js | 115 ----------------------------- lib/transport/index.js | 6 -- 4 files changed, 160 deletions(-) delete mode 100644 docs/guide/insight.md delete mode 100644 lib/transport/explorers/index.js delete mode 100644 lib/transport/explorers/insight.js delete mode 100644 lib/transport/index.js diff --git a/docs/guide/insight.md b/docs/guide/insight.md deleted file mode 100644 index 9892846..0000000 --- a/docs/guide/insight.md +++ /dev/null @@ -1,36 +0,0 @@ -title: Insight Explorer -description: Provides an interface to fetch information about the state of the blockchain from a trusted Insight server. ---- -# Insight - -## Description - -`bitcore.transport.explorers.Insight` is a simple agent to perform queries to an Insight blockchain explorer. The default servers are `https://insight.bitpay.com` and `https://test-insight.bitpay.com`, hosted by BitPay Inc. You can (and we strongly suggest you do) run your own insight server. For more information, head to https://github.com/bitpay/insight-api - -There are currently two methods implemented (the API will grow as features are requested): `getUnspentUtxos` and `broadcast`. - -### Retrieving Unspent UTXOs for an Address (or set of) - -```javascript -var insight = new Insight(); -insight.getUnspentUtxos('1Bitcoin...', function(err, utxos) { - if (err) { - // Handle errors... - } else { - // Maybe use the UTXOs to create a transaction - } -}); -``` - -### Broadcasting a Transaction - -```javascript -var insight = new Insight(); -insight.broadcast(tx, function(err, returnedTxId) { - if (err) { - // Handle errors... - } else { - // Mark the transaction as broadcasted - } -}); -``` diff --git a/lib/transport/explorers/index.js b/lib/transport/explorers/index.js deleted file mode 100644 index 2483955..0000000 --- a/lib/transport/explorers/index.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - Insight: require('./insight') -}; diff --git a/lib/transport/explorers/insight.js b/lib/transport/explorers/insight.js deleted file mode 100644 index 71a41c5..0000000 --- a/lib/transport/explorers/insight.js +++ /dev/null @@ -1,115 +0,0 @@ -'use strict'; - -var $ = require('../../util/preconditions'); -var _ = require('lodash'); - -var Address = require('../../address'); -var JSUtil = require('../../util/js'); -var Networks = require('../../networks'); -var Transaction = require('../../transaction'); -var UnspentOutput = Transaction.UnspentOutput; - -var request = require('request'); - -/** - * Allows the retrieval of information regarding the state of the blockchain - * (and broadcasting of transactions) from/to a trusted Insight server. - * @param {string=} url the url of the Insight server - * @param {Network=} network whether to use livenet or testnet - * @constructor - */ -function Insight(url, network) { - if (!url && !network) { - return new Insight(Networks.defaultNetwork); - } - if (Networks.get(url)) { - network = Networks.get(url); - if (network === Networks.livenet) { - url = 'https://insight.bitpay.com'; - } else { - url = 'https://test-insight.bitpay.com'; - } - } - JSUtil.defineImmutable(this, { - url: url, - network: Networks.get(network) || Networks.defaultNetwork - }); - return this; -} - -/** - * @callback Insight.GetUnspentUtxosCallback - * @param {Error} err - * @param {Array.UnspentOutput} utxos - */ - -/** - * Retrieve a list of unspent outputs associated with an address or set of addresses - * @param {Address|string|Array.Address|Array.string} addresses - * @param {GetUnspentUtxosCallback} callback - */ -Insight.prototype.getUnspentUtxos = function(addresses, callback) { - $.checkArgument(_.isFunction(callback)); - if (!_.isArray(addresses)) { - addresses = [addresses]; - } - addresses = _.map(addresses, function(address) { return new Address(address); }); - - this.requestPost('/api/addrs/utxo', { - addrs: _.map(addresses, function(address) { return address.toString(); }).join(',') - }, function(err, res, unspent) { - if (err || res.statusCode !== 200) { - return callback(err || res); - } - unspent = _.map(unspent, UnspentOutput); - - return callback(null, unspent); - }); -}; - -/** - * @callback Insight.BroadcastCallback - * @param {Error} err - * @param {string} txid - */ - -/** - * Broadcast a transaction to the bitcoin network - * @param {transaction|string} transaction - * @param {BroadcastCallback} callback - */ -Insight.prototype.broadcast = function(transaction, callback) { - $.checkArgument(JSUtil.isHexa(transaction) || transaction instanceof Transaction); - $.checkArgument(_.isFunction(callback)); - if (transaction instanceof Transaction) { - transaction = transaction.serialize(); - } - - this.requestPost('/api/tx/send', { - rawtx: transaction - }, function(err, res, body) { - if (err || res.statusCode !== 200) { - return callback(err || body); - } - return callback(null, body ? body.txid : null); - }); -}; - -/** - * Internal function to make a post request to the server - * @param {string} path - * @param {?} data - * @param {function} callback - * @private - */ -Insight.prototype.requestPost = function(path, data, callback) { - $.checkArgument(_.isString(path)); - $.checkArgument(_.isFunction(callback)); - request({ - method: 'POST', - url: this.url + path, - json: data - }, callback); -}; - -module.exports = Insight; diff --git a/lib/transport/index.js b/lib/transport/index.js deleted file mode 100644 index 6e49efa..0000000 --- a/lib/transport/index.js +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @namespace Transport - */ -module.exports = { - explorers: require('./explorers') -};