UNPKG

@hashgraph/hedera-local

Version:

Developer tooling for running Local Hedera Network (Consensus + Mirror Nodes).

87 lines 4.22 kB
"use strict"; // SPDX-License-Identifier: Apache-2.0 var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 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) : adopt(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 }); exports.StartState = void 0; const shelljs_1 = __importDefault(require("shelljs")); const LocalNodeErrors_1 = require("../Errors/LocalNodeErrors"); const constants_1 = require("../constants"); const CLIService_1 = require("../services/CLIService"); const ConnectionService_1 = require("../services/ConnectionService"); const DockerService_1 = require("../services/DockerService"); const LoggerService_1 = require("../services/LoggerService"); const ServiceLocator_1 = require("../services/ServiceLocator"); const EventType_1 = require("../types/EventType"); class StartState { /** * Creates an instance of StartState. * * @constructor */ constructor() { this.stateName = StartState.name; this.logger = ServiceLocator_1.ServiceLocator.Current.get(LoggerService_1.LoggerService.name); this.cliOptions = ServiceLocator_1.ServiceLocator.Current.get(CLIService_1.CLIService.name).getCurrentArgv(); this.dockerService = ServiceLocator_1.ServiceLocator.Current.get(DockerService_1.DockerService.name); this.connectionService = ServiceLocator_1.ServiceLocator.Current.get(ConnectionService_1.ConnectionService.name); this.logger.trace(constants_1.START_STATE_INIT_MESSAGE, this.stateName); } /** * Subscribes an observer to the state. * * @public * @param {IOBserver} observer - The observer to subscribe. */ subscribe(observer) { this.observer = observer; } /** * Starts the Hedera Local Node. * * @public * @returns {Promise<void>} A Promise that resolves when the Hedera Local Node is successfully started. */ onStart() { return __awaiter(this, void 0, void 0, function* () { var _a, _b; this.logger.info(constants_1.START_STATE_STARTING_MESSAGE, this.stateName); const rootPath = process.cwd(); shelljs_1.default.cd(__dirname); shelljs_1.default.cd('../../'); this.dockerService.checkDockerImages(); const output = yield this.dockerService.dockerComposeUp(this.cliOptions); if (output.code === 1) { (_a = this.observer) === null || _a === void 0 ? void 0 : _a.update(EventType_1.EventType.DockerError); yield this.dockerService.dockerComposeUp(this.cliOptions); } shelljs_1.default.cd(rootPath); this.logger.info(constants_1.START_STATE_STARTED_DETECTING, this.stateName); try { yield this.connectionService.waitForFiringUp(5600, 'Mirror Node GRPC'); yield this.connectionService.waitForFiringUp(50211, 'Network Node'); } catch (e) { if (e instanceof LocalNodeErrors_1.LocalNodeErrors) { this.logger.error(e.message, this.stateName); } this.observer.update(EventType_1.EventType.UnknownError); return; } this.logger.info(constants_1.START_STATE_STARTED_MESSAGE, this.stateName); (_b = this.observer) === null || _b === void 0 ? void 0 : _b.update(EventType_1.EventType.Finish); }); } } exports.StartState = StartState; //# sourceMappingURL=StartState.js.map