mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
[internal] Allowlist: auto-allow only assets with both logo and info (#4877)
* Allowlist: auto-allow only assets with both logo and info. * Rmove unsed imports. * Lint fix * Lint Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
parent
0aa5690704
commit
e785fae5cb
|
@ -1,12 +1,20 @@
|
||||||
import { chainsWithDenylist } from "./blockchains";
|
import { chainsWithDenylist } from "./blockchains";
|
||||||
import {
|
import {
|
||||||
getChainAssetsList,
|
getChainAssetInfoPath,
|
||||||
|
getChainAssetLogoPath,
|
||||||
|
//getChainAssetsList,
|
||||||
|
getChainAssetsPath,
|
||||||
getChainAllowlistPath,
|
getChainAllowlistPath,
|
||||||
getChainDenylistPath
|
getChainDenylistPath
|
||||||
} from "./repo-structure";
|
} from "./repo-structure";
|
||||||
import { readFileSync, writeFileSync } from "./filesystem";
|
|
||||||
import {
|
import {
|
||||||
arrayDiff,
|
isPathExistsSync,
|
||||||
|
readDirSync,
|
||||||
|
readFileSync,
|
||||||
|
writeFileSync
|
||||||
|
} from "./filesystem";
|
||||||
|
import {
|
||||||
|
//arrayDiff,
|
||||||
arrayDiffNocase,
|
arrayDiffNocase,
|
||||||
findCommonElementsOrDuplicates,
|
findCommonElementsOrDuplicates,
|
||||||
makeUnique
|
makeUnique
|
||||||
|
@ -15,10 +23,35 @@ import { ActionInterface, CheckStepInterface } from "./interface";
|
||||||
import { formatSortJson } from "./json";
|
import { formatSortJson } from "./json";
|
||||||
import * as bluebird from "bluebird";
|
import * as bluebird from "bluebird";
|
||||||
|
|
||||||
|
// Find assets for which full info is available -- logo+info -- and is not in the allowlist
|
||||||
|
async function findFullAssetsWithNoAllow(chain: string, allowlist: string[]): Promise<string[]> {
|
||||||
|
const list: string[] = [];
|
||||||
|
const assetsPath = getChainAssetsPath(chain);
|
||||||
|
if (!isPathExistsSync(assetsPath)) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
await bluebird.mapSeries(readDirSync(assetsPath), async asset => {
|
||||||
|
if (allowlist.includes(asset)) {
|
||||||
|
// present in allowlist, skip
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const logoPath = getChainAssetLogoPath(chain, asset);
|
||||||
|
if (!isPathExistsSync(logoPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const infoPath = getChainAssetInfoPath(chain, asset);
|
||||||
|
if (!isPathExistsSync(infoPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// both files exist, not in allowlist
|
||||||
|
list.push(asset);
|
||||||
|
});
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
async function checkUpdateAllowDenyList(chain: string, checkOnly: boolean ): Promise<[boolean, string[], string[]]> {
|
async function checkUpdateAllowDenyList(chain: string, checkOnly: boolean ): Promise<[boolean, string[], string[]]> {
|
||||||
const errorMsgs: string[] = [];
|
const errorMsgs: string[] = [];
|
||||||
const warningMsgs: string[] = [];
|
const warningMsgs: string[] = [];
|
||||||
const assets = getChainAssetsList(chain);
|
|
||||||
|
|
||||||
const allowlistPath = getChainAllowlistPath(chain);
|
const allowlistPath = getChainAllowlistPath(chain);
|
||||||
const denylistPath = getChainDenylistPath(chain);
|
const denylistPath = getChainDenylistPath(chain);
|
||||||
|
@ -32,16 +65,18 @@ async function checkUpdateAllowDenyList(chain: string, checkOnly: boolean ): Pro
|
||||||
if (commonElementsOrDuplicates && commonElementsOrDuplicates.length > 0) {
|
if (commonElementsOrDuplicates && commonElementsOrDuplicates.length > 0) {
|
||||||
errorMsgs.push(`Denylist and allowlist for chain ${chain} should have no common elements or duplicates, found ${commonElementsOrDuplicates.length} ${commonElementsOrDuplicates[0]}`);
|
errorMsgs.push(`Denylist and allowlist for chain ${chain} should have no common elements or duplicates, found ${commonElementsOrDuplicates.length} ${commonElementsOrDuplicates[0]}`);
|
||||||
}
|
}
|
||||||
|
//const assetsWithLogo = getChainAssetsList(chain);
|
||||||
|
const assetsWithInfoNotInAllow = await findFullAssetsWithNoAllow(chain, currentAllowlist);
|
||||||
/*
|
/*
|
||||||
const allowlistOrphan = arrayDiff(currentAllowlist, assets);
|
const allowlistOrphan = arrayDiff(currentAllowlist, assetsWithLogo);
|
||||||
if (allowlistOrphan && allowlistOrphan.length > 0) {
|
if (allowlistOrphan && allowlistOrphan.length > 0) {
|
||||||
// warning only
|
// warning only
|
||||||
warningMsgs.push(`Allowlist for chain ${chain} contains non-exitent assets, found ${allowlistOrphan.length}, ${allowlistOrphan[0]}`);
|
warningMsgs.push(`Allowlist for chain ${chain} contains non-exitent assetsWithLogo, found ${allowlistOrphan.length}, ${allowlistOrphan[0]}`);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//const newDeny = makeUnique(currentDenylist.concat(allowlistOrphan));
|
//const newDeny = makeUnique(currentDenylist.concat(allowlistOrphan));
|
||||||
const tempAssetsOrAllow = makeUnique(currentAllowlist.concat(assets));
|
const tempAssetsOrAllow = makeUnique(currentAllowlist.concat(assetsWithInfoNotInAllow));
|
||||||
const newAllow = makeUnique(arrayDiffNocase(tempAssetsOrAllow, currentDenylist));
|
const newAllow = makeUnique(arrayDiffNocase(tempAssetsOrAllow, currentDenylist));
|
||||||
//console.log(currentAllowlist.length, "vs.", newAllow.length);
|
//console.log(currentAllowlist.length, "vs.", newAllow.length);
|
||||||
//console.log(currentDenylist.length, "vs.", newDeny.length);
|
//console.log(currentDenylist.length, "vs.", newDeny.length);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user