UNPKG

@authereum/zos

Version:

Command-line interface for the ZeppelinOS smart contract platform

91 lines 4.57 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const zos_lib_1 = require("zos-lib"); const TruffleConfig_1 = __importDefault(require("./TruffleConfig")); const Session_1 = __importDefault(require("../network/Session")); const ZosConfig_1 = __importDefault(require("./ZosConfig")); const ConfigManager = { initialize(root = process.cwd()) { if (!TruffleConfig_1.default.exists() && !ZosConfig_1.default.exists()) { ZosConfig_1.default.initialize(root); } }, initStaticConfiguration(root = process.cwd()) { this.setBaseConfig(root); const buildDir = this.config.getBuildDir(); zos_lib_1.Contracts.setLocalBuildDir(buildDir); }, initNetworkConfiguration(options = {}, silent, root = process.cwd()) { return __awaiter(this, void 0, void 0, function* () { this.initStaticConfiguration(root); const { network: networkName, from, timeout } = Session_1.default.getOptions(options, silent); Session_1.default.setDefaultNetworkIfNeeded(options.network); if (!networkName) throw Error('A network name must be provided to execute the requested action.'); const { provider, artifactDefaults, network, } = yield this.config.loadNetworkConfig(networkName, root); const networkId = network.networkId || network.network_id; zos_lib_1.Contracts.setSyncTimeout(timeout * 1000); zos_lib_1.Contracts.setArtifactsDefaults(artifactDefaults); try { zos_lib_1.ZWeb3.initialize(provider); yield zos_lib_1.ZWeb3.checkNetworkId(networkId); const txParams = { from: zos_lib_1.ZWeb3.toChecksumAddress(from || artifactDefaults.from || (yield zos_lib_1.ZWeb3.defaultAccount())), }; return { network: yield zos_lib_1.ZWeb3.getNetworkName(), txParams }; } catch (error) { if (this.config && this.config.name === 'ZosConfig') { const providerInfo = typeof provider === 'string' ? ` on ${provider}` : ''; const message = `Could not connect to the ${networkName} Ethereum network${providerInfo}. Please check your networks.js configuration file.`; error.message = `${message} Error: ${error.message}.`; throw error; } else throw error; } }); }, getBuildDir(root = process.cwd()) { this.setBaseConfig(root); return this.config.getBuildDir(); }, getCompilerInfo(root = process.cwd()) { this.setBaseConfig(root); const { compilers: { solc: { version, settings }, }, } = this.config.getConfig(); const { enabled: optimizer, runs: optimizerRuns } = settings.optimizer; return { version, optimizer, optimizerRuns }; }, getNetworkNamesFromConfig(root = process.cwd()) { this.setBaseConfig(root); const config = this.config.getConfig(); return config && config.networks ? Object.keys(config.networks) : undefined; }, setBaseConfig(root = process.cwd()) { if (this.config) return; // these lines could be expanded to support different libraries like embark, ethjs, buidler, etc if (ZosConfig_1.default.exists(root)) { this.config = ZosConfig_1.default; } else if (TruffleConfig_1.default.exists(root)) { this.config = TruffleConfig_1.default; } else { throw Error('Could not find networks.js file, please remember to initialize your project.'); } }, }; exports.default = ConfigManager; //# sourceMappingURL=ConfigManager.js.map