UNPKG

bitcore-node

Version:

A blockchain indexing node with extended capabilities using bitcore

157 lines 5.74 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const _ = __importStar(require("lodash")); const os_1 = require("os"); const parseArgv_1 = __importDefault(require("./utils/parseArgv")); let program = (0, parseArgv_1.default)([], ['config']); function findConfig() { let foundConfig; const envConfigPath = process.env.BITCORE_CONFIG_PATH; const argConfigPath = program.config; const configFileName = 'bitcore.config.json'; let bitcoreConfigPaths = [ `${(0, os_1.homedir)()}/${configFileName}`, `../../../../${configFileName}`, `../../${configFileName}` ]; const overrideConfig = argConfigPath || envConfigPath; if (overrideConfig) { bitcoreConfigPaths.unshift(overrideConfig); } // No config specified. Search home, bitcore and cur directory for (let path of bitcoreConfigPaths) { if (!foundConfig) { try { const expanded = path[0] === '~' ? path.replace('~', (0, os_1.homedir)()) : path; const bitcoreConfig = require(expanded); foundConfig = bitcoreConfig.bitcoreNode; } catch (e) { foundConfig = undefined; } } } return foundConfig; } function setTrustedPeers(config) { for (let [chain, chainObj] of Object.entries(config)) { for (let network of Object.keys(chainObj)) { let env = process.env; const envString = `TRUSTED_${chain.toUpperCase()}_${network.toUpperCase()}_PEER`; if (env[envString]) { let peers = config.chains[chain][network].trustedPeers || []; peers.push({ host: env[envString], port: env[`${envString}_PORT`] }); config.chains[chain][network].trustedPeers = peers; } } } return config; } const Config = function () { let config = { maxPoolSize: 50, port: 3000, dbUrl: process.env.DB_URL || '', dbHost: process.env.DB_HOST || '127.0.0.1', dbName: process.env.DB_NAME || 'bitcore', dbPort: process.env.DB_PORT || '27017', dbUser: process.env.DB_USER || '', dbPass: process.env.DB_PASS || '', numWorkers: (0, os_1.cpus)().length, chains: {}, aliasMapping: { chains: {}, networks: {} }, services: { api: { rateLimiter: { disabled: false, whitelist: ['::ffff:127.0.0.1', '::1'] }, wallets: { allowCreationBeforeCompleteSync: false, allowUnauthenticatedCalls: false } }, event: { onlyWalletEvents: false }, p2p: {}, socket: { bwsKeys: [] }, storage: {} }, externalProviders: { moralis: { apiKey: 'string' } } }; let foundConfig = findConfig(); const mergeCopyArray = (objVal, srcVal) => (objVal instanceof Array ? srcVal : undefined); config = _.mergeWith(config, foundConfig, mergeCopyArray); if (!Object.keys(config.chains).length) { Object.assign(config.chains, { BTC: { mainnet: { chainSource: 'p2p', trustedPeers: [{ host: '127.0.0.1', port: 8333 }], rpc: { host: '127.0.0.1', port: 8332, username: 'bitcoin', password: 'bitcoin' } } } }); } if (config.modules) { throw new Error('The config modules has moved! You can remove the `modules` array from your config to use the defaults, or if you need to use custom modules then you can specify the paths in the specific chain-network config objects with `modulePath`'); } config = setTrustedPeers(config); return config; }; exports.default = Config(); //# sourceMappingURL=config.js.map