bitcore-wallet-service/lib/blockchainexplorer.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2015-03-30 11:34:05 -07:00
'use strict';
var _ = require('lodash');
var $ = require('preconditions').singleton();
var log = require('npmlog');
log.debug = log.verbose;
var Insight = require('./blockchainexplorers/insight');
2015-03-30 11:34:05 -07:00
2015-06-10 07:49:52 -07:00
var PROVIDERS = {
'insight': {
'livenet': 'https://insight.bitpay.com:443',
'testnet': 'https://test-insight.bitpay.com:443',
},
};
2015-03-30 11:34:05 -07:00
2015-03-30 16:16:51 -07:00
function BlockChainExplorer(opts) {
2015-03-30 11:34:05 -07:00
$.checkArgument(opts);
2015-06-10 07:49:52 -07:00
var provider = opts.provider || 'insight';
var network = opts.network || 'livenet';
2015-06-10 07:49:52 -07:00
$.checkState(PROVIDERS[provider], 'Provider ' + provider + ' not supported');
$.checkState(_.contains(_.keys(PROVIDERS[provider]), network), 'Network ' + network + ' not supported by this provider');
2015-06-10 07:49:52 -07:00
var url = opts.url || PROVIDERS[provider][network];
2015-06-10 07:49:52 -07:00
switch (provider) {
2015-03-30 11:34:05 -07:00
case 'insight':
return new Insight({
network: network,
url: url,
2016-04-07 10:52:23 -07:00
apiPrefix: opts.apiPrefix,
userAgent: opts.userAgent,
});
default:
2015-09-07 20:57:59 -07:00
throw new Error('Provider ' + provider + ' not supported.');
2015-04-18 02:55:24 -07:00
};
};
2015-03-30 16:16:51 -07:00
module.exports = BlockChainExplorer;