trustwallet-assets/script/blockchain/tron.ts
Adam R 41037d09f0
[Internal] Allow assets to exist with no logo, info only (typically spam) (#11530)
* Allow assets to exist with no logo, info only (typically spam)

* Allow missing logo only for spam assets

* Lint fix

* Remove logo for a few spam tokens

* Revert "Remove logo for a few spam tokens"

This reverts commit 95e93cd7b2e9c3c03f4e8369f59a5c56c593e13d.

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
2021-07-08 17:40:16 +02:00

55 lines
2.1 KiB
TypeScript

import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { getChainAssetsPath } from "../generic/repo-structure";
import { Tron } from "../generic/blockchains";
import { readDirSync } from "../generic/filesystem";
import { getChainValidatorsAssets } from "../generic/repo-structure";
import { isLowerCase, isUpperCase } from "../generic/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"; }
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Tron assets should be TRC10 or TRC20, logo of correct size"; },
check: async () => {
const errors: string[] = [];
const path = getChainAssetsPath(Tron);
const assets = readDirSync(path);
await bluebird.each(assets, async (asset) => {
if (!isTRC10(asset) && !isTRC20(asset)) {
errors.push(`Asset ${asset} at path '${path}' is not TRC10 nor TRC20`);
}
});
return [errors, []];
}
},
{
getName: () => { return "Tron validator assets must have correct format"},
check: async () => {
const errors: string[] = [];
const assets = getChainValidatorsAssets(Tron);
assets.forEach(addr => {
if (!(isTRC20(addr))) {
errors.push(`Address ${addr} should be TRC20 address'`);
}
});
return [errors, []];
}
}
];
}
}