You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.0 KiB
41 lines
1.0 KiB
'use strict';
|
|
|
|
var _ = require('lodash');
|
|
var $ = require('preconditions').singleton();
|
|
var log = require('npmlog');
|
|
log.debug = log.verbose;
|
|
|
|
var Insight = require('./blockchainexplorers/insight');
|
|
|
|
var PROVIDERS = {
|
|
'insight': {
|
|
'livenet': 'https://insight.bitpay.com:443',
|
|
'testnet': 'https://test-insight.bitpay.com:443',
|
|
},
|
|
};
|
|
|
|
function BlockChainExplorer(opts) {
|
|
$.checkArgument(opts);
|
|
|
|
var provider = opts.provider || 'insight';
|
|
var network = opts.network || 'livenet';
|
|
|
|
$.checkState(PROVIDERS[provider], 'Provider ' + provider + ' not supported');
|
|
$.checkState(_.contains(_.keys(PROVIDERS[provider]), network), 'Network ' + network + ' not supported by this provider');
|
|
|
|
var url = opts.url || PROVIDERS[provider][network];
|
|
|
|
switch (provider) {
|
|
case 'insight':
|
|
return new Insight({
|
|
network: network,
|
|
url: url,
|
|
apiPrefix: opts.apiPrefix,
|
|
userAgent: opts.userAgent,
|
|
});
|
|
default:
|
|
throw new Error('Provider ' + provider + ' not supported.');
|
|
};
|
|
};
|
|
|
|
module.exports = BlockChainExplorer;
|
|
|