diff --git a/blockchains/tron/assets/TJvqNiWUN2v2NBG12UhfV7WSvReJkRP3VC/info.json b/blockchains/tron/assets/TJvqNiWUN2v2NBG12UhfV7WSvReJkRP3VC/info.json index c4f2cf2f9..5c7051fb7 100644 --- a/blockchains/tron/assets/TJvqNiWUN2v2NBG12UhfV7WSvReJkRP3VC/info.json +++ b/blockchains/tron/assets/TJvqNiWUN2v2NBG12UhfV7WSvReJkRP3VC/info.json @@ -7,6 +7,7 @@ "white_paper": "https://bridge.link/Bridge_White_Paper.pdf", "short_description": "First Ever Public Oracle System on TRON Network", "description": "First Ever Public Oracle System on TRON Network", + "explorer": "https://tronscan.io/#/token20/TJvqNiWUN2v2NBG12UhfV7WSvReJkRP3VC", "socials": [ { "name": "Twitter", @@ -19,4 +20,4 @@ "handle": "Bridge Oracle" } ] -} \ No newline at end of file +} diff --git a/script/generic/asset-info.ts b/script/generic/asset-info.ts deleted file mode 100644 index a36910079..000000000 --- a/script/generic/asset-info.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { getChainAssetInfoPath } from "./repo-structure"; -import { readFileSync, isPathExistsSync } from "./filesystem"; -import { arrayDiff } from "./types"; -import { isValidJSON } from "../generic/json"; - -const requiredKeys = ["explorer", "name", "website", "short_description"]; - -function isAssetInfoHasAllKeys(path: string): [boolean, string] { - const info = JSON.parse(readFileSync(path)); - const infoKeys = Object.keys(info); - - const hasAllKeys = requiredKeys.every(k => Object.prototype.hasOwnProperty.call(info, k)); - - if (!hasAllKeys) { - return [false, `Info at path '${path}' missing next key(s): ${arrayDiff(requiredKeys, infoKeys)}`]; - } - - const isKeysCorrentType = - typeof info.explorer === "string" && info.explorer != "" - && typeof info.name === "string" && info.name != "" - && typeof info.website === "string" - && typeof info.short_description === "string"; - - return [isKeysCorrentType, `Check keys '${requiredKeys}' vs. '${infoKeys}'`]; -} - -export function isAssetInfoOK(chain: string, address: string): [boolean, string] { - const assetInfoPath = getChainAssetInfoPath(chain, address); - if (!isPathExistsSync(assetInfoPath)) { - return [true, `Info file doesn't exist, no need to check`] - } - - if (!isValidJSON(assetInfoPath)) { - console.log(`JSON at path: '${assetInfoPath}' is invalid`); - return [false, `JSON at path: '${assetInfoPath}' is invalid`]; - } - - const [hasAllKeys, msg] = isAssetInfoHasAllKeys(assetInfoPath); - if (!hasAllKeys) { - console.log(msg); - return [false, msg]; - } - - return [true, '']; -} diff --git a/script/generic/asset-infos.ts b/script/generic/asset-infos.ts new file mode 100644 index 000000000..563430fbd --- /dev/null +++ b/script/generic/asset-infos.ts @@ -0,0 +1,86 @@ +import { + allChains, + getChainAssetsList, + getChainAssetsPath, + getChainAssetInfoPath +} from "./repo-structure"; +import { + readFileSync, + isPathExistsSync +} from "./filesystem"; +import { arrayDiff } from "./types"; +import { isValidJSON } from "../generic/json"; +import { ActionInterface, CheckStepInterface } from "../generic/interface"; +import * as bluebird from "bluebird"; + +const requiredKeys = ["explorer", "name", "website", "short_description"]; + +function isAssetInfoHasAllKeys(path: string): [boolean, string] { + const info = JSON.parse(readFileSync(path)); + const infoKeys = Object.keys(info); + + const hasAllKeys = requiredKeys.every(k => Object.prototype.hasOwnProperty.call(info, k)); + + if (!hasAllKeys) { + return [false, `Info at path '${path}' missing next key(s): ${arrayDiff(requiredKeys, infoKeys)}`]; + } + + const isKeysCorrentType = + typeof info.explorer === "string" && info.explorer != "" + && typeof info.name === "string" && info.name != "" + && typeof info.website === "string" + && typeof info.short_description === "string"; + + return [isKeysCorrentType, `Check keys '${requiredKeys}' vs. '${infoKeys}'`]; +} + +function isAssetInfoOK(chain: string, address: string): [boolean, string] { + const assetInfoPath = getChainAssetInfoPath(chain, address); + if (!isPathExistsSync(assetInfoPath)) { + return [true, `Info file doesn't exist, no need to check`] + } + + if (!isValidJSON(assetInfoPath)) { + console.log(`JSON at path: '${assetInfoPath}' is invalid`); + return [false, `JSON at path: '${assetInfoPath}' is invalid`]; + } + + const [hasAllKeys, msg] = isAssetInfoHasAllKeys(assetInfoPath); + if (!hasAllKeys) { + console.log(msg); + return [false, msg]; + } + + return [true, '']; +} + +export class AssetInfos implements ActionInterface { + getName(): string { return "Asset Infos"; } + + getSanityChecks(): CheckStepInterface[] { + const steps: CheckStepInterface[] = []; + allChains.forEach(chain => { + // only if there is no assets subfolder + if (isPathExistsSync(getChainAssetsPath(chain))) { + steps.push( + { + getName: () => { return `Info.json's for chain ${chain}`;}, + check: async () => { + const errors: string[] = []; + const assetsList = getChainAssetsList(chain); + //console.log(` Found ${assetsList.length} assets for chain ${chain}`); + await bluebird.each(assetsList, async (address) => { + const [isInfoOK, infoMsg] = isAssetInfoOK(chain, address); + if (!isInfoOK) { + errors.push(infoMsg); + } + }); + return [errors, []]; + } + } + ); + } + }); + return steps; + } +} diff --git a/script/generic/eth-forks.ts b/script/generic/eth-forks.ts index 0a33789a0..22c16017d 100644 --- a/script/generic/eth-forks.ts +++ b/script/generic/eth-forks.ts @@ -21,7 +21,6 @@ import { } from "../generic/filesystem"; import { toChecksum } from "../generic/eth-address"; import { ActionInterface, CheckStepInterface } from "../generic/interface"; -import { isAssetInfoOK } from "../generic/asset-info"; import * as bluebird from "bluebird"; async function formatInfos() { @@ -92,10 +91,6 @@ export class EthForks implements ActionInterface { if (!isPathExistsSync(assetLogoPath)) { errors.push(`Missing file at path '${assetLogoPath}'`); } - const [isInfoOK, infoMsg] = isAssetInfoOK(chain, address); - if (!isInfoOK) { - errors.push(infoMsg); - } }); return [errors, []]; } diff --git a/script/generic/folders-and-files.ts b/script/generic/folders-and-files.ts index b894f6408..808bbd5b8 100644 --- a/script/generic/folders-and-files.ts +++ b/script/generic/folders-and-files.ts @@ -4,7 +4,7 @@ import { } from "../generic/filesystem"; import { CheckStepInterface, ActionInterface } from "../generic/interface"; import { - chainsPath, + allChains, getChainLogoPath, getChainAssetsPath, getChainAssetPath, @@ -18,8 +18,6 @@ import { isLogoOK } from "../generic/image"; import { isLowerCase } from "../generic/types"; import * as bluebird from "bluebird"; -const foundChains = readDirSync(chainsPath) - export class FoldersFiles implements ActionInterface { getName(): string { return "Folders and Files"; } @@ -42,7 +40,7 @@ export class FoldersFiles implements ActionInterface { getName: () => { return "Chain folders are lowercase, contain only predefined list of files"}, check: async () => { const errors: string[] = []; - foundChains.forEach(chain => { + allChains.forEach(chain => { if (!isLowerCase(chain)) { errors.push(`Chain folder must be in lowercase "${chain}"`); } @@ -59,7 +57,7 @@ export class FoldersFiles implements ActionInterface { getName: () => { return "Chain folders have logo, and correct size"}, check: async () => { const errors: string[] = []; - await bluebird.each(foundChains, async (chain) => { + await bluebird.each(allChains, async (chain) => { const chainLogoPath = getChainLogoPath(chain); if (!isPathExistsSync(chainLogoPath)) { errors.push(`File missing at path "${chainLogoPath}"`); @@ -76,7 +74,7 @@ export class FoldersFiles implements ActionInterface { getName: () => { return "Asset folders contain logo"}, check: async () => { const errors: string[] = []; - foundChains.forEach(chain => { + allChains.forEach(chain => { const assetsPath = getChainAssetsPath(chain); if (isPathExistsSync(assetsPath)) { readDirSync(assetsPath).forEach(address => { @@ -95,7 +93,7 @@ export class FoldersFiles implements ActionInterface { getName: () => { return "Asset folders contain info.json"}, check: async () => { const warnings: string[] = []; - foundChains.forEach(chain => { + allChains.forEach(chain => { const assetsPath = getChainAssetsPath(chain); if (isPathExistsSync(assetsPath)) { readDirSync(assetsPath).forEach(address => { @@ -114,7 +112,7 @@ export class FoldersFiles implements ActionInterface { getName: () => { return "Asset folders contain only predefined set of files"}, check: async () => { const errors: string[] = []; - foundChains.forEach(chain => { + allChains.forEach(chain => { const assetsPath = getChainAssetsPath(chain); if (isPathExistsSync(assetsPath)) { readDirSync(assetsPath).forEach(address => { diff --git a/script/generic/logo-size.ts b/script/generic/logo-size.ts index 87e8bcb1d..3985029f3 100644 --- a/script/generic/logo-size.ts +++ b/script/generic/logo-size.ts @@ -1,6 +1,6 @@ import * as bluebird from "bluebird"; import { - chainsPath, + allChains, getChainLogoPath, getChainAssetsPath, getChainAssetLogoPath, @@ -80,8 +80,7 @@ export class LogoSize implements ActionInterface { { getName: () => { return "Check that logos are not too large"}, check: async () => { - const foundChains = readDirSync(chainsPath); - const largePaths = await checkDownsize(foundChains, true); + const largePaths = await checkDownsize(allChains, true); const errors: string[] = largePaths.map(p => `Logo too large: ${p}`); return [errors, []]; } @@ -90,7 +89,6 @@ export class LogoSize implements ActionInterface { } async sanityFix(): Promise { - const foundChains = readDirSync(chainsPath); - await checkDownsize(foundChains, false); + await checkDownsize(allChains, false); } } diff --git a/script/generic/repo-structure.ts b/script/generic/repo-structure.ts index da79f68d0..7481fc31f 100644 --- a/script/generic/repo-structure.ts +++ b/script/generic/repo-structure.ts @@ -28,6 +28,7 @@ export const chainFolderAllowedFiles = [ ] export const chainsPath: string = path.join(process.cwd(), '/blockchains'); export const getChainPath = (chain: string): string => `${chainsPath}/${chain}`; +export const allChains = readDirSync(chainsPath); export const getChainLogoPath = (chain: string): string => `${getChainPath(chain)}/info/${logoFullName}`; export const getChainAssetsPath = (chain: string): string => `${getChainPath(chain)}/assets`; export const getChainAssetPath = (chain: string, asset: string): string => `${getChainAssetsPath(chain)}/${asset}`; diff --git a/script/generic/update-all.ts b/script/generic/update-all.ts index 8a14fdd98..1329e9877 100644 --- a/script/generic/update-all.ts +++ b/script/generic/update-all.ts @@ -1,5 +1,6 @@ import { BinanceAction } from "../blockchain/binance"; import { CosmosAction } from "../blockchain/cosmos"; +import { AssetInfos } from "../generic/asset-infos"; import { EthForks } from "../generic/eth-forks"; import { FoldersFiles } from "../generic/folders-and-files"; import { JsonAction } from "../generic/json-format"; @@ -18,6 +19,7 @@ import * as bluebird from "bluebird"; const actionList: ActionInterface[] = [ new FoldersFiles(), + new AssetInfos(), new EthForks(), new LogoSize(), new Allowlists(),