UNPKG

@sangaman/xud

Version:
105 lines 3.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const os_1 = __importDefault(require("os")); const path_1 = __importDefault(require("path")); const toml_1 = __importDefault(require("toml")); const utils_1 = require("./utils/utils"); class Config { constructor() { this.instanceId = 0; const platform = os_1.default.platform(); let lndDefaultDatadir; switch (platform) { case 'win32': { // windows const homeDir = process.env.LOCALAPPDATA; this.xudir = `${homeDir}/Xud/`; lndDefaultDatadir = `${homeDir}/Lnd/`; break; } case 'darwin': { // mac const homeDir = process.env.HOME; this.xudir = `${homeDir}/.xud/`; lndDefaultDatadir = `${homeDir}/Library/Application Support/Lnd/`; break; } default: { // linux const homeDir = process.env.HOME; this.xudir = `${homeDir}/.xud/`; lndDefaultDatadir = `${homeDir}/.lnd/`; break; } } // default configuration this.initDb = true; this.p2p = { listen: true, port: 8885, addresses: [], }; this.db = { host: 'localhost', port: 3306, username: 'xud', database: 'xud', }; this.testDb = Object.assign({}, this.db, { database: 'xud_test' }); this.rpc = { disable: false, host: 'localhost', port: 8886, }; this.webproxy = { disable: true, port: 8080, }; this.lndbtc = { disable: false, certpath: path_1.default.join(lndDefaultDatadir, 'tls.cert'), macaroonpath: path_1.default.join(lndDefaultDatadir, 'admin.macaroon'), host: 'localhost', port: 10009, }; this.lndltc = { disable: false, certpath: path_1.default.join(lndDefaultDatadir, 'tls.cert'), macaroonpath: path_1.default.join(lndDefaultDatadir, 'admin.macaroon'), host: 'localhost', port: 10010, }; this.raiden = { disable: false, host: 'localhost', port: 5001, }; } load(args) { if (args && args['xudir']) { this.xudir = args['xudir']; } const configPath = path_1.default.join(this.xudir, 'xud.conf'); if (!fs_1.default.existsSync(this.xudir)) { fs_1.default.mkdirSync(this.xudir); } else if (fs_1.default.existsSync(configPath)) { const configText = fs_1.default.readFileSync(configPath, 'utf8'); try { const props = toml_1.default.parse(configText); // merge parsed json properties from config file to the default config utils_1.deepMerge(this, props); } catch (e) { throw new Error(`Parsing error on line ${e.line}, column ${e.column}: ${e.message}`); } } if (args) { // override our config file with command line arguments utils_1.deepMerge(this, args); } } } exports.default = Config; //# sourceMappingURL=Config.js.map