2020-07-29 13:42:51 +00:00
|
|
|
import { ethForkChains } from "../common/blockchains";
|
|
|
|
import {
|
|
|
|
getChainAssetsPath,
|
|
|
|
getChainAssetsList,
|
|
|
|
getChainAssetPath,
|
|
|
|
getChainAssetInfoPath,
|
|
|
|
getChainAssetFilesList,
|
|
|
|
isChainAssetInfoExistSync,
|
|
|
|
logoName,
|
|
|
|
logoExtension,
|
2020-08-06 19:17:38 +00:00
|
|
|
logoFullName,
|
|
|
|
getChainAssetLogoPath
|
2020-07-29 13:42:51 +00:00
|
|
|
} from "../common/repo-structure";
|
|
|
|
import { formatJsonFile } from "../common/json";
|
|
|
|
import {
|
|
|
|
getFileName,
|
|
|
|
getFileExt,
|
|
|
|
gitMove,
|
2020-08-06 19:17:38 +00:00
|
|
|
readDirSync,
|
|
|
|
isPathExistsSync,
|
2020-07-29 13:42:51 +00:00
|
|
|
} from "../common/filesystem";
|
2020-08-08 07:33:01 +00:00
|
|
|
import { toChecksum } from "../common/eth-web3";
|
2020-08-06 19:17:38 +00:00
|
|
|
import { ActionInterface, CheckStepInterface } from "./interface";
|
|
|
|
import { isAssetInfoOK } from "../common/asset-info";
|
|
|
|
import * as bluebird from "bluebird";
|
2020-07-29 13:42:51 +00:00
|
|
|
|
2020-08-07 14:39:46 +00:00
|
|
|
async function formatInfos() {
|
2020-07-29 13:42:51 +00:00
|
|
|
console.log(`Formatting info files...`);
|
2020-08-07 14:39:46 +00:00
|
|
|
await bluebird.each(ethForkChains, async (chain) => {
|
2020-07-29 13:42:51 +00:00
|
|
|
let count: number = 0;
|
|
|
|
const chainAssets = getChainAssetsList(chain);
|
2020-08-07 14:39:46 +00:00
|
|
|
await bluebird.each(chainAssets, async (address) => {
|
2020-07-29 13:42:51 +00:00
|
|
|
if (isChainAssetInfoExistSync(chain, address)) {
|
|
|
|
const chainAssetInfoPath = getChainAssetInfoPath(chain, address);
|
|
|
|
formatJsonFile(chainAssetInfoPath, true);
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
console.log(`Formatted ${count} info files for chain ${chain} (total ${chainAssets.length})`);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-08-10 14:56:02 +00:00
|
|
|
function checkAddressChecksum(assetsFolderPath: string, address: string, chain: string) {
|
|
|
|
const checksumAddress = toChecksum(address, chain);
|
2020-08-08 07:33:01 +00:00
|
|
|
if (checksumAddress !== address) {
|
2020-07-29 13:42:51 +00:00
|
|
|
gitMove(assetsFolderPath, address, checksumAddress);
|
|
|
|
console.log(`Renamed to checksum format ${checksumAddress}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 14:39:46 +00:00
|
|
|
async function checkAddressChecksums() {
|
2020-07-29 13:42:51 +00:00
|
|
|
console.log(`Checking for checksum formats ...`);
|
2020-08-07 14:39:46 +00:00
|
|
|
await bluebird.each(ethForkChains, async (chain) => {
|
2020-07-29 13:42:51 +00:00
|
|
|
const assetsPath = getChainAssetsPath(chain);
|
|
|
|
|
2020-08-07 14:39:46 +00:00
|
|
|
await bluebird.each(readDirSync(assetsPath), async (address) => {
|
|
|
|
await bluebird.each(getChainAssetFilesList(chain, address), async (file) => {
|
2020-07-29 13:42:51 +00:00
|
|
|
if (getFileName(file) == logoName && getFileExt(file) !== logoExtension) {
|
|
|
|
console.log(`Renaming incorrect asset logo extension ${file} ...`);
|
|
|
|
gitMove(getChainAssetPath(chain, address), file, logoFullName);
|
|
|
|
}
|
|
|
|
});
|
2020-08-10 14:56:02 +00:00
|
|
|
checkAddressChecksum(assetsPath, address, chain);
|
2020-07-29 13:42:51 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-06 19:17:38 +00:00
|
|
|
export class EthForks implements ActionInterface {
|
|
|
|
getName(): string { return "Ethereum forks"; }
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
getSanityChecks(): CheckStepInterface[] {
|
2020-08-06 19:17:38 +00:00
|
|
|
var steps: CheckStepInterface[] = [];
|
|
|
|
ethForkChains.forEach(chain => {
|
|
|
|
steps.push(
|
|
|
|
{
|
|
|
|
getName: () => { return `Folder structure for chain ${chain} (ethereum fork)`;},
|
|
|
|
check: async () => {
|
2020-09-16 12:52:10 +00:00
|
|
|
var errors: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
const assetsFolder = getChainAssetsPath(chain);
|
|
|
|
const assetsList = getChainAssetsList(chain);
|
|
|
|
console.log(` Found ${assetsList.length} assets for chain ${chain}`);
|
|
|
|
await bluebird.each(assetsList, async (address) => {
|
|
|
|
const assetPath = `${assetsFolder}/${address}`;
|
|
|
|
if (!isPathExistsSync(assetPath)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Expect directory at path: ${assetPath}`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
2020-08-10 14:56:02 +00:00
|
|
|
const inChecksum = toChecksum(address, chain);
|
2020-08-08 07:33:01 +00:00
|
|
|
if (address !== inChecksum) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Expect asset at path ${assetPath} in checksum: '${inChecksum}'`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
const assetLogoPath = getChainAssetLogoPath(chain, address);
|
|
|
|
if (!isPathExistsSync(assetLogoPath)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Missing file at path '${assetLogoPath}'`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
const [isInfoOK, infoMsg] = isAssetInfoOK(chain, address);
|
|
|
|
if (!isInfoOK) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(infoMsg);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
2020-09-16 12:52:10 +00:00
|
|
|
return [errors, []];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return steps;
|
|
|
|
}
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
getConsistencyChecks = null;
|
|
|
|
|
|
|
|
async sanityFix(): Promise<void> {
|
2020-08-07 14:39:46 +00:00
|
|
|
await formatInfos();
|
|
|
|
await checkAddressChecksums();
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
consistencyFix = null;
|
|
|
|
|
2020-08-06 19:17:38 +00:00
|
|
|
update = null;
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|