forked from trustwallet/assets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtron.ts
More file actions
58 lines (54 loc) · 2.37 KB
/
tron.ts
File metadata and controls
58 lines (54 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { getChainAssetsPath } from "../generic/repo-structure";
import { Tron } from "../generic/blockchains";
import { readDirSync, isPathExistsSync } from "../generic/filesystem";
import { getChainAssetLogoPath, 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`);
}
const assetsLogoPath = getChainAssetLogoPath(Tron, asset);
if (!isPathExistsSync(assetsLogoPath)) {
errors.push(`Missing file at path '${assetsLogoPath}'`);
}
});
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, []];
}
}
];
}
}