UNPKG

@kyve/core-beta

Version:

🚀 The base KYVE node implementation.

50 lines (49 loc) • 1.65 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.syncPoolConfig = void 0; const axios_1 = __importDefault(require("axios")); const utils_1 = require("../../utils"); /** * syncPoolConfig fetches the pool config from the provided link * and parses it into a json config * * @method syncPoolConfig * @param {Node} this * @return {Promise<void>} */ async function syncPoolConfig() { try { this.logger.debug(this.pool.data.config); try { this.poolConfig = JSON.parse(this.pool.data.config); return; } catch { } let url; // allow ipfs:// or ar:// as external config urls if (this.pool.data.config.startsWith("ipfs://")) { url = this.pool.data.config.replace("ipfs://", "https://ipfs.io/"); } else if (this.pool.data.config.startsWith("ar://")) { url = this.pool.data.config.replace("ar://", "https://arweave.net/"); } else { throw Error("Unsupported config link protocol"); } this.logger.debug(url); const { data } = await axios_1.default.get(url); this.logger.debug(JSON.stringify(data)); this.poolConfig = data; } catch (err) { this.logger.error(`Failed to sync pool config`); this.logger.error((0, utils_1.standardizeJSON)(err)); if (!this.poolConfig) { this.poolConfig = {}; } } } exports.syncPoolConfig = syncPoolConfig;