sources-mainnet.js
1 /*! 2 * lib/remote-importer/sources.js 3 * Copyright © 2019 – Katana Cryptographic Ltd. All Rights Reserved. 4 */ 5 6 7 import network from '../bitcoin/network.js' 8 import Logger from '../logger.js' 9 import keysFile from '../../keys/index.js' 10 import Sources from './sources.js' 11 import BitcoindWrapper from './bitcoind-wrapper.js' 12 import LocalIndexerWrapper from './local-indexer-wrapper.js' 13 import LocalRestIndexerWrapper from './local-rest-indexer-wrapper.js' 14 import OxtWrapper from './oxt-wrapper.js' 15 16 const keys = keysFile[network.key] 17 18 /** 19 * Remote data sources for mainnet 20 */ 21 class SourcesMainnet extends Sources { 22 23 constructor() { 24 super() 25 this._initSource() 26 } 27 28 /** 29 * Initialize the external data source 30 */ 31 _initSource() { 32 switch (keys.indexer.active) { 33 case 'local_bitcoind': { 34 // If local bitcoind option is activated 35 // we'll use the local node as our unique source 36 this.source = new BitcoindWrapper() 37 Logger.info('Importer : Activated Bitcoind as the data source for imports') 38 39 break 40 } 41 case 'local_indexer': { 42 // If local indexer option is activated 43 // we'll use the local indexer as our unique source 44 this.source = new LocalIndexerWrapper() 45 Logger.info('Importer : Activated local indexer as the data source for imports') 46 47 break 48 } 49 case 'local_rest_indexer': { 50 // If local rest indexer option is activated 51 // we'll use the local indexer as our unique source 52 const uri = `http://${keys.indexer.localIndexer.host}:${keys.indexer.localIndexer.port}` 53 this.source = new LocalRestIndexerWrapper(uri) 54 Logger.info('Importer : Activated local indexer (REST API) as the data source for imports') 55 56 break 57 } 58 default: { 59 // Otherwise, we'll use the rest api provided by OXT 60 this.source = new OxtWrapper(keys.indexer.oxt) 61 Logger.info('Importer : Activated OXT API as the data source for imports') 62 } 63 } 64 } 65 66 } 67 68 export default SourcesMainnet