2020-09-23 13:47:24 +00:00
|
|
|
import { ethForkChains } from "../generic/blockchains";
|
2020-07-29 13:42:51 +00:00
|
|
|
import {
|
|
|
|
getChainAssetsPath,
|
|
|
|
getChainAssetsList,
|
|
|
|
getChainAssetPath,
|
|
|
|
getChainAssetFilesList,
|
|
|
|
logoName,
|
|
|
|
logoExtension,
|
2020-08-06 19:17:38 +00:00
|
|
|
logoFullName,
|
2020-09-23 13:47:24 +00:00
|
|
|
} from "../generic/repo-structure";
|
2020-07-29 13:42:51 +00:00
|
|
|
import {
|
|
|
|
getFileName,
|
|
|
|
getFileExt,
|
|
|
|
gitMove,
|
2020-08-06 19:17:38 +00:00
|
|
|
readDirSync,
|
|
|
|
isPathExistsSync,
|
2020-09-23 13:47:24 +00:00
|
|
|
} from "../generic/filesystem";
|
2020-09-29 13:01:34 +00:00
|
|
|
import { toChecksum } from "../generic/eth-address";
|
2020-09-23 13:47:24 +00:00
|
|
|
import { ActionInterface, CheckStepInterface } from "../generic/interface";
|
2020-08-06 19:17:38 +00:00
|
|
|
import * as bluebird from "bluebird";
|
2020-07-29 13:42:51 +00:00
|
|
|
|
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-09-18 14:39:31 +00:00
|
|
|
const steps: CheckStepInterface[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
ethForkChains.forEach(chain => {
|
|
|
|
steps.push(
|
|
|
|
{
|
|
|
|
getName: () => { return `Folder structure for chain ${chain} (ethereum fork)`;},
|
|
|
|
check: async () => {
|
2020-09-18 14:39:31 +00:00
|
|
|
const errors: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
const assetsFolder = getChainAssetsPath(chain);
|
2021-09-02 05:42:58 +00:00
|
|
|
if (!isPathExistsSync(assetsFolder)) {
|
|
|
|
console.log(` Found 0 assets for chain ${chain}`);
|
|
|
|
return [errors, []];
|
|
|
|
}
|
2020-08-06 19:17:38 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
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
|
|
|
async sanityFix(): Promise<void> {
|
2020-08-07 14:39:46 +00:00
|
|
|
await checkAddressChecksums();
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|