From f905bad9457b4d9f32d1d7a9d47699849e2fb811 Mon Sep 17 00:00:00 2001 From: Adam R <13562139+catenocrypt@users.noreply.github.com> Date: Mon, 10 May 2021 15:08:10 +0200 Subject: [PATCH] [Internal] Change all explorers to standard explorer (#7655) * In fix, overwrite Explorer to computed version. * Ignore case-only diff * Add VeChain explorer * Revert "Add VeChain explorer" This reverts commit 0a0b22c6beda4648c41cf307bbb9b4f421d7d773. * Add VeChain explorer template * Update thundertoken explorer * Lint fix * Lint fix Co-authored-by: Catenocrypt --- script/generic/asset-infos.ts | 55 ++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/script/generic/asset-infos.ts b/script/generic/asset-infos.ts index 603377d7f..48cf5d7fb 100644 --- a/script/generic/asset-infos.ts +++ b/script/generic/asset-infos.ts @@ -161,15 +161,19 @@ export function explorerUrl(chain: string, contract: string): string { return "https://explorer.ont.io"; case CoinType.name(CoinType.gochain).toLowerCase(): - return `https://explorer.gochain.io/addr/${contract}`; + return `https://explorer.gochain.io/addr/${contract}`; case CoinType.name(CoinType.thundertoken).toLowerCase(): case "thundertoken": - return `https://scan.thundercore.com/`; + return `https://viewblock.io/thundercore/address/${contract}`; case CoinType.name(CoinType.classic).toLowerCase(): case "classic": - return `https://blockscout.com/etc/mainnet/tokens/${contract}`; + return `https://blockscout.com/etc/mainnet/tokens/${contract}`; + + case CoinType.name(CoinType.vechain).toLowerCase(): + case "vechain": + return `https://explore.vechain.org/accounts/${contract}`; } } return ""; @@ -223,29 +227,38 @@ function isAssetInfoOK(chain: string, address: string, errors: string[], warning fixedInfo = fixedInfo2; } + const explorerExpected = explorerUrl(chain, address); const hasExplorer = Object.prototype.hasOwnProperty.call(info, 'explorer'); - if (!hasExplorer) { - errors.push(`Missing explorer key`); - } else { - const explorerActual = info['explorer']; - const explorerActualLower = explorerActual.toLowerCase(); - const explorerExpected = explorerUrl(chain, address); - if (explorerActualLower != explorerExpected.toLowerCase() && explorerExpected) { - // doesn't match, check for alternatives - const explorersAlt = explorerUrlAlternatives(chain, address, info['name']); - if (explorersAlt && explorersAlt.length > 0) { - let matchCount = 0; - explorersAlt.forEach(exp => { if (exp.toLowerCase() == explorerActualLower) { ++matchCount; }}); - if (matchCount == 0) { - // none matches, this is warning/error - if (chain.toLowerCase() == CoinType.name(CoinType.ethereum) || chain.toLowerCase() == CoinType.name(CoinType.smartchain)) { - errors.push(`Incorrect explorer, ${explorerActual} instead of ${explorerExpected} (${explorersAlt.join(', ')})`); - } else { - warnings.push(`Unexpected explorer, ${explorerActual} instead of ${explorerExpected} (${explorersAlt.join(', ')})`); + const explorerActual = info['explorer'] || ''; + const explorerActualLower = explorerActual.toLowerCase(); + const explorerExpectedLower = explorerExpected.toLowerCase(); + if (checkOnly) { + if (!hasExplorer) { + errors.push(`Missing explorer key`); + } else { + if (explorerActualLower !== explorerExpectedLower && explorerExpected) { + // doesn't match, check for alternatives + const explorersAlt = explorerUrlAlternatives(chain, address, info['name']); + if (explorersAlt && explorersAlt.length > 0) { + let matchCount = 0; + explorersAlt.forEach(exp => { if (exp.toLowerCase() == explorerActualLower) { ++matchCount; }}); + if (matchCount == 0) { + // none matches, this is warning/error + if (chain.toLowerCase() == CoinType.name(CoinType.ethereum) || chain.toLowerCase() == CoinType.name(CoinType.smartchain)) { + errors.push(`Incorrect explorer, ${explorerActual} instead of ${explorerExpected} (${explorersAlt.join(', ')})`); + } else { + warnings.push(`Unexpected explorer, ${explorerActual} instead of ${explorerExpected} (${explorersAlt.join(', ')})`); + } } } } } + } else { + // fix: simply replace with expected (case-only deviation is accepted) + if (explorerActualLower !== explorerExpectedLower) { + if (!fixedInfo) { fixedInfo = info; } + fixedInfo['explorer'] = explorerExpected; + } } if (fixedInfo && !checkOnly) {