UNPKG

web3-error-helper

Version:

> 🛠️ Turn confusing Web3 errors into clear, human-friendly messages for developers and users alike.

121 lines (120 loc) 4.26 kB
"use strict"; /** * Built-in chain management * * This module provides comprehensive management for all built-in blockchain networks * supported by the library. It handles chain validation, metadata retrieval, discovery * operations, and statistics. Acts as the primary interface for interacting with * predefined blockchain configurations and their associated error mappings. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.validateChain = exports.getAllChainConfigs = exports.searchChainsByName = exports.findChainsByProperty = exports.findChainsBySymbol = exports.findChainByChainId = void 0; exports.getBuiltInChains = getBuiltInChains; exports.isBuiltInChain = isBuiltInChain; exports.getBuiltInChainInfo = getBuiltInChainInfo; exports.getChainMetadata = getChainMetadata; exports.getBuiltInChainStats = getBuiltInChainStats; const types_1 = require("./types"); const chain_registry_1 = require("./data/chain-registry"); /** * Fast chain lookup using Set */ const BUILT_IN_CHAIN_SET = new Set(Object.values(types_1.SupportedChain)); /** * Get all built-in supported chains * * @returns Array of built-in chain identifiers * * @example * ```typescript * const builtInChains = getBuiltInChains(); * console.log(builtInChains); // ['ethereum', 'polygon', 'arbitrum', ...] * ``` */ function getBuiltInChains() { return (0, chain_registry_1.getSupportedChainIds)(); } /** * Check if a chain is built-in * * @param chain - The chain identifier to check * @returns true if the chain is a built-in supported chain * * @example * ```typescript * if (isBuiltInChain('ethereum')) { * console.log('Ethereum is a built-in chain'); * } * ``` */ function isBuiltInChain(chain) { return BUILT_IN_CHAIN_SET.has(chain); } /** * Get built-in chain information * * @param chain - The chain identifier * @returns Chain information object or null if not a built-in chain * * @example * ```typescript * const info = getBuiltInChainInfo('ethereum'); * console.log(info); // { type: 'built-in', name: 'Ethereum' } * ``` */ function getBuiltInChainInfo(chain) { if (!isBuiltInChain(chain)) { return null; } const config = (0, chain_registry_1.getChainConfig)(chain); return { type: 'built-in', name: config?.metadata.name || chain }; } /** * Get enhanced chain metadata * * @param chain - The chain identifier * @returns Full chain metadata or null if not a built-in chain * * @example * ```typescript * const metadata = getChainMetadata('ethereum'); * console.log(metadata?.chainId); // 1 * console.log(metadata?.symbol); // 'ETH' * ``` */ function getChainMetadata(chain) { if (!isBuiltInChain(chain)) { return null; } return (0, chain_registry_1.getChainConfig)(chain)?.metadata || null; } /** * Get built-in chain statistics * * @returns Object with built-in chain statistics * * @example * ```typescript * const stats = getBuiltInChainStats(); * console.log(stats); // { count: 8, chains: ['ethereum', 'polygon', ...] } * ``` */ function getBuiltInChainStats() { const chains = getBuiltInChains(); return { count: chains.length, chains }; } var chain_discovery_1 = require("./services/chain-discovery"); Object.defineProperty(exports, "findChainByChainId", { enumerable: true, get: function () { return chain_discovery_1.findChainByChainId; } }); Object.defineProperty(exports, "findChainsBySymbol", { enumerable: true, get: function () { return chain_discovery_1.findChainsBySymbol; } }); Object.defineProperty(exports, "findChainsByProperty", { enumerable: true, get: function () { return chain_discovery_1.findChainsByProperty; } }); Object.defineProperty(exports, "searchChainsByName", { enumerable: true, get: function () { return chain_discovery_1.searchChainsByName; } }); var chain_registry_2 = require("./data/chain-registry"); Object.defineProperty(exports, "getAllChainConfigs", { enumerable: true, get: function () { return chain_registry_2.getAllChainConfigs; } }); var chain_validation_1 = require("./services/chain-validation"); Object.defineProperty(exports, "validateChain", { enumerable: true, get: function () { return chain_validation_1.validateBuiltInChain; } });