UNPKG

@hashgraph/hedera-local

Version:

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

53 lines 2.02 kB
"use strict"; // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.ClientService = void 0; const sdk_1 = require("@hashgraph/sdk"); const LoggerService_1 = require("./LoggerService"); const ServiceLocator_1 = require("./ServiceLocator"); const CLIService_1 = require("./CLIService"); const LocalNodeErrors_1 = require("../Errors/LocalNodeErrors"); /** * Represents a service for managing the Hedera client. * @implements {IService} */ class ClientService { /** * Create a client service instance. */ constructor() { this.serviceName = ClientService.name; this.logger = ServiceLocator_1.ServiceLocator.Current.get(LoggerService_1.LoggerService.name); this.cliService = ServiceLocator_1.ServiceLocator.Current.get(CLIService_1.CLIService.name); this.logger.trace('Client Service Initialized!', this.serviceName); } /** * Sets up the client for communication with the network. * @throws {LocalNodeErrors} If the environment variables OPERATOR_ID and OPERATOR_KEY are not set. * @private */ setupClient() { if (process.env.RELAY_OPERATOR_ID_MAIN == null || process.env.RELAY_OPERATOR_KEY_MAIN == null) { throw LocalNodeErrors_1.Errors.CLEINT_ERROR("Environment variables OPERATOR_ID, and OPERATOR_KEY are required."); } const { host } = this.cliService.getCurrentArgv(); this.client = sdk_1.Client.forNetwork({ [`${host}:50211`]: '0.0.3' }) .setOperator(process.env.RELAY_OPERATOR_ID_MAIN, process.env.RELAY_OPERATOR_KEY_MAIN); } /** * Retrieves the client instance. * If the client instance does not exist, it will be set up. * @returns {Client} The client. * @public */ getClient() { if (!this.client) { this.setupClient(); } return this.client; } } exports.ClientService = ClientService; //# sourceMappingURL=ClientService.js.map