2020-08-06 19:17:38 +00:00
|
|
|
import { ActionInterface, CheckStepInterface } from "./interface";
|
|
|
|
import { getChainAssetsPath } from "../common/repo-structure";
|
|
|
|
import { Tron } from "../common/blockchains";
|
|
|
|
import { readDirSync, isPathExistsSync } from "../common/filesystem";
|
|
|
|
import { getChainAssetLogoPath, getChainValidatorsAssets } from "../common/repo-structure";
|
|
|
|
import { isLowerCase, isUpperCase } from "../common/types";
|
|
|
|
import * as bluebird from "bluebird";
|
|
|
|
|
|
|
|
export function isTRC10(str: string): boolean {
|
|
|
|
return (/^\d+$/.test(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isTRC20(address: string): boolean {
|
|
|
|
return address.length == 34 &&
|
|
|
|
address.startsWith("T") &&
|
|
|
|
isLowerCase(address) == false &&
|
|
|
|
isUpperCase(address) == false;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class TronAction implements ActionInterface {
|
|
|
|
getName(): string { return "Tron chain"; }
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
getSanityChecks(): CheckStepInterface[] {
|
2020-08-06 19:17:38 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
getName: () => { return "Tron assets should be TRC10 or TRC20, logo of correct size"; },
|
|
|
|
check: async () => {
|
2020-09-16 12:52:10 +00:00
|
|
|
var errors: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
const path = getChainAssetsPath(Tron);
|
|
|
|
const assets = readDirSync(path);
|
|
|
|
await bluebird.each(assets, async (asset) => {
|
|
|
|
if (!isTRC10(asset) && !isTRC20(asset)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Asset ${asset} at path '${path}' is not TRC10 nor TRC20`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
const assetsLogoPath = getChainAssetLogoPath(Tron, asset);
|
|
|
|
if (!isPathExistsSync(assetsLogoPath)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Missing file at path '${assetsLogoPath}'`);
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
getName: () => { return "Tron validator assets must have correct format"},
|
|
|
|
check: async () => {
|
2020-09-16 12:52:10 +00:00
|
|
|
var errors: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
const assets = getChainValidatorsAssets(Tron);
|
|
|
|
assets.forEach(addr => {
|
|
|
|
if (!(isTRC20(addr))) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`Address ${addr} should be TRC20 address'`);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
getConsistencyChecks = null;
|
|
|
|
|
|
|
|
sanityFix = null;
|
|
|
|
|
|
|
|
consistencyFix = null;
|
2020-08-06 19:17:38 +00:00
|
|
|
|
|
|
|
update = null;
|
|
|
|
}
|