"use strict"; /** * Blockchain network safety guards. * Blocks accidental mainnet usage in non-production when testnet mode is expected. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.validateTestnetSafetyOrThrow = validateTestnetSafetyOrThrow; const config_1 = require("../config"); /** * Throws when a safety assertion fails. * @param condition Truthy when the check passes * @param message Error message when condition is false */ function assert(condition, message) { if (!condition) throw new Error(message); } /** * Returns true when the URL appears to target TRON Shasta testnet. * @param url TRON node URL */ function looksLikeShasta(url) { return /shasta/i.test(url); } /** * Validates that non-production runs use testnet endpoints and contracts. * * For the expected testnet setup: * - TRON: Shasta (TRON_NODE_URL should include "shasta") * - Asset: USDT TRC20 on Shasta * * Skipped in production or when NETWORK_MODE=mainnet. * @throws When a configured URL or contract points at mainnet while testnet is required */ function validateTestnetSafetyOrThrow() { const mode = (process.env.NETWORK_MODE || '').toLowerCase(); // "testnet" | "mainnet" | "" const isProd = config_1.config.env === 'production'; // Default to strict safety in non-production unless explicitly running mainnet mode. const requireTestnet = !isProd && mode !== 'mainnet'; if (!requireTestnet) return; assert(looksLikeShasta(config_1.config.blockchain.tron.nodeUrl), `Safety check failed: TRON_NODE_URL must point to Shasta (expected "shasta" in URL). Got: ${config_1.config.blockchain.tron.nodeUrl}`); assert(!!config_1.config.blockchain.tron.usdtTrc20Contract && config_1.config.blockchain.tron.usdtTrc20Contract.trim().length > 0, 'Safety check failed: USDT_TRC20_CONTRACT must be set for Shasta (testnet) so we do not use the mainnet default from DB.'); } //# sourceMappingURL=networkGuard.js.map