mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
[internal] Cleanup of script-old. (#3721)
Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
parent
6eadcb9074
commit
5c6f98f794
|
@ -12,16 +12,32 @@ import {
|
|||
getChainAssetsPath,
|
||||
getChainPath,
|
||||
getRootDirFilesList,
|
||||
isChecksum,
|
||||
isEthereumAddress,
|
||||
isPathDir,
|
||||
logo,
|
||||
logoExtension,
|
||||
makeDirIfDoestExist,
|
||||
readDirSync,
|
||||
toChecksum,
|
||||
isDirContainLogo
|
||||
} from "./helpers"
|
||||
import { isEthereumAddress, toChecksum, isChecksum } from "../script/common/eth-web3";
|
||||
|
||||
async function makeDirIfDoestExist(dirPath: string, dirName: string) {
|
||||
const path = `${dirPath}/${dirName}`
|
||||
await fs.mkdir(path, {recursive: true}, (err) => {
|
||||
if (err) {
|
||||
console.error(`Error creating dir at path ${path} with result ${err}`)
|
||||
} else {
|
||||
console.log(`Created direcotry at ${path}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function isPathDir(path: string): boolean {
|
||||
try {
|
||||
return fs.lstatSync(path).isDirectory()
|
||||
} catch (e) {
|
||||
console.log(`Path: ${path} is not a directory with error: ${e.message}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
ethForkChains.forEach(chain => {
|
||||
const chainAssetsPath = getChainAssetsPath(chain)
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd ../
|
||||
cd "blockchains/binance/assets"
|
||||
|
||||
for symbol in *
|
||||
do
|
||||
echo $symbol
|
||||
upper=$(echo "$symbol" | awk '{print toupper($0)}')
|
||||
git mv "$symbol" "$upper-test" && git mv "$upper-test" "$upper"
|
||||
done
|
|
@ -1,7 +1,5 @@
|
|||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
const Web3 = require('web3')
|
||||
const web3 = new Web3('ws://localhost:8546');
|
||||
|
||||
export const logoName = `logo`
|
||||
export const infoName = `info`
|
||||
|
@ -9,87 +7,20 @@ export const infoName = `info`
|
|||
export const logoExtension = "png"
|
||||
export const jsonExtension = "json"
|
||||
|
||||
const allowList = `allowlist.${jsonExtension}`
|
||||
const denyList = `denylist.${jsonExtension}`
|
||||
|
||||
export const logo = `${logoName}.${logoExtension}`
|
||||
export const info = `${infoName}.${jsonExtension}`
|
||||
|
||||
export const root = './'
|
||||
export const chainsFolderPath = path.join(process.cwd(), '/blockchains')
|
||||
export const getChainLogoPath = (chain: string): string => `${chainsFolderPath}/${chain}/info/${logo}`
|
||||
export const getChainInfoPath = (chain: string): string => `${chainsFolderPath}/${chain}/info/${info}`
|
||||
export const getChainAssetsPath = (chain: string): string => `${chainsFolderPath}/${chain}/assets`
|
||||
export const getChainPath = (chain: string): string => `${chainsFolderPath}/${chain}`
|
||||
|
||||
export const getChainAssetPath = (chain: string, address: string) => `${getChainAssetsPath(chain)}/${address}`
|
||||
export const getAllChainsList = (): string[] => readDirSync(chainsFolderPath)
|
||||
export const getChainAssetLogoPath = (chain: string, address: string) => `${getChainAssetsPath(chain)}/${address}/${logo}`
|
||||
export const getChainAllowlistPath = (chain: string): string => `${chainsFolderPath}/${chain}/${allowList}`
|
||||
export const getChainDenylistPath = (chain: string): string => `${chainsFolderPath}/${chain}/${denyList}`
|
||||
export const getChainAllowlist = (chain: string): string[] => {
|
||||
if (isChainAllowlistExistSync(chain)) {
|
||||
return JSON.parse(readFileSync(getChainAllowlistPath(chain)))
|
||||
}
|
||||
return []
|
||||
}
|
||||
export const getChainDenylist = (chain: string): string[] => {
|
||||
if (isChainDenylistExistSync(chain)) {
|
||||
return JSON.parse(readFileSync(getChainDenylistPath(chain)))
|
||||
}
|
||||
return []
|
||||
}
|
||||
export const getRootDirFilesList = (): string[] => readDirSync(root)
|
||||
|
||||
export const readDirSync = (path: string): string[] => fs.readdirSync(path)
|
||||
export const makeDirSync = (path: string) => fs.mkdirSync(path)
|
||||
export const isPathExistsSync = (path: string): boolean => fs.existsSync(path)
|
||||
export const isDirContainLogo = (path: string): boolean => fs.existsSync(`${path}/${logo}`)
|
||||
export const isChainAllowlistExistSync = (chain: string): boolean => isPathExistsSync(getChainAllowlistPath(chain))
|
||||
export const isChainDenylistExistSync = (chain: string): boolean => isPathExistsSync(getChainDenylistPath(chain))
|
||||
export const isChainInfoExistSync = (chain: string): boolean => isPathExistsSync(getChainInfoPath(chain))
|
||||
export const readFileSync = (path: string) => fs.readFileSync(path, 'utf8')
|
||||
|
||||
export const isChecksum = (address: string): boolean => web3.utils.checkAddressChecksum(address)
|
||||
export const toChecksum = (address: string): string => web3.utils.toChecksumAddress(address)
|
||||
|
||||
export const isEthereumAddress = (address: string): boolean => {
|
||||
return web3.utils.isAddress(address)
|
||||
}
|
||||
|
||||
export const isPathDir = (path: string): boolean => {
|
||||
try {
|
||||
return fs.lstatSync(path).isDirectory()
|
||||
} catch (e) {
|
||||
console.log(`Path: ${path} is not a directory with error: ${e.message}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export const isPathDirEmpty = (path: string): boolean => {
|
||||
try {
|
||||
if (isPathDir(path)) {
|
||||
return fs.readdirSync(path).length == 0
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`Error isPathDirEmpty`, error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
export const removeDir = (path: string) => {
|
||||
fs.rmdirSync(path, {recursive: true})
|
||||
}
|
||||
|
||||
export const makeDirIfDoestExist = async (dirPath: string, dirName: string) => {
|
||||
const path = `${dirPath}/${dirName}`
|
||||
await fs.mkdir(path, {recursive: true}, (err) => {
|
||||
if (err) {
|
||||
console.error(`Error creating dir at path ${path} with result ${err}`)
|
||||
} else {
|
||||
console.log(`Created direcotry at ${path}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
export interface CoinInfoList {
|
||||
name: string;
|
||||
website: string;
|
||||
source_code: string;
|
||||
whitepaper: string;
|
||||
short_description: string;
|
||||
explorer: string;
|
||||
socials: Social[];
|
||||
details: Detail[];
|
||||
}
|
||||
|
||||
interface Detail {
|
||||
language: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
interface Social {
|
||||
name: string;
|
||||
url: string;
|
||||
handle: string;
|
||||
}
|
||||
|
||||
// CoinmarketCap
|
||||
export interface mapTiker {
|
||||
coin: number
|
||||
type: mapType
|
||||
token_id?: string
|
||||
id: number
|
||||
}
|
||||
|
||||
type mapType = TickerType.Coin | TickerType.Token
|
||||
|
||||
export enum TickerType {
|
||||
Token = "token",
|
||||
Coin = "coin"
|
||||
}
|
||||
|
||||
export enum PlatformType {
|
||||
Ethereum = "Ethereum",
|
||||
Binance = "Binance Coin",
|
||||
TRON = "TRON",
|
||||
OMNI = "Omni",
|
||||
VeChain = "VeChain"
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
var axios = require("axios");
|
||||
import { toChecksum } from "./helpers"
|
||||
|
||||
// Returns array of ERC-721, ERC-1155 contract addresses in checksum
|
||||
export const getOpenseaCollectionAddresses = async () => {
|
||||
console.log(`Fetching assets from OpenSea`)
|
||||
const limit = 300 // max limit
|
||||
let offset = 0
|
||||
const erc20Addresses = []
|
||||
const nftList = []
|
||||
|
||||
while(true) {
|
||||
const url = `https://api.opensea.io/api/v1/collections?limit=${limit}&offset=${offset}`
|
||||
console.log({url})
|
||||
const collections = await axios.get(url)
|
||||
.then(res => res.data.collections)
|
||||
.catch(e => console.log(e.message))
|
||||
collections.forEach(c => {
|
||||
c.primary_asset_contracts.forEach(a => {
|
||||
const checksum = toChecksum(a.address)
|
||||
if (a.schema_name === "ERC20") {
|
||||
erc20Addresses.push(checksum)
|
||||
} else {
|
||||
nftList.push(checksum)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
if(collections.length < limit) {
|
||||
return nftList
|
||||
} else {
|
||||
offset += limit
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
import {
|
||||
getChainAssetPath,
|
||||
getChainAssetsPath,
|
||||
isPathDir,
|
||||
isPathDirEmpty,
|
||||
readDirSync,
|
||||
removeDir,
|
||||
getAllChainsList,
|
||||
} from "./helpers"
|
||||
|
||||
getAllChainsList().forEach(async chain => {
|
||||
const chainAssetsPath = getChainAssetsPath(chain)
|
||||
|
||||
if (isPathDir(chainAssetsPath)) {
|
||||
readDirSync(chainAssetsPath).forEach(async (asset) => {
|
||||
const assetPath = getChainAssetPath(chain, asset);
|
||||
const isDir = await isPathDir(assetPath);
|
||||
const isPathEmpty = await isPathDirEmpty(assetPath);
|
||||
|
||||
if (isDir && isPathEmpty) {
|
||||
removeDir(assetPath)
|
||||
console.log(`Removed empty folder at path ${assetPath}`);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
|
@ -1,19 +0,0 @@
|
|||
const { execSync } = require('child_process');
|
||||
const path = require('path')
|
||||
const axios = require('axios')
|
||||
import { readDirSync } from "./helpers";
|
||||
|
||||
const assetsPath = path.resolve(`${__dirname}/../blockchains/tron/assets`)
|
||||
const chainAddresses = readDirSync(assetsPath)
|
||||
|
||||
chainAddresses.forEach(async addr => {
|
||||
const trc20Info = await axios.get(`https://apilist.tronscan.org/api/token_trc20?contract=${addr}&showAll=1`).then(({ data }) => data)
|
||||
|
||||
if (!isChecksum) {
|
||||
console.log(`Address ${addr} not in checksum`)
|
||||
const checksum = web3.utils.toChecksumAddress(addr)
|
||||
const moveToChecksum = `git mv ${addr} ${checksum}-temp && git mv ${checksum}-temp ${checksum}`
|
||||
const renamed = execSync(`cd ${assetsPath} && ${moveToChecksum}`, {encoding: "utf-8"})
|
||||
console.log(`Result renaming ${addr} : ${renamed}`)
|
||||
}
|
||||
})
|
|
@ -29,3 +29,6 @@ export function isChecksum(address: string, chain: string = "ethereum"): boolean
|
|||
return isChecksumEthereum(address);
|
||||
}
|
||||
|
||||
export function isEthereumAddress(address: string): boolean {
|
||||
return web3.utils.isAddress(address)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ import {
|
|||
} from "../script/common/types";
|
||||
import {
|
||||
isChecksum,
|
||||
toChecksum
|
||||
toChecksum,
|
||||
isEthereumAddress
|
||||
} from "../script/common/eth-web3";
|
||||
import {
|
||||
isDimensionTooLarge,
|
||||
|
@ -37,6 +38,10 @@ describe("Test eth-web3 helpers", () => {
|
|||
expect(toChecksum("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee", "ethereum"), `from checksum`).toEqual("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee");
|
||||
expect(toChecksum("0x7bb09bc8ade747178e95b1d035ecbeebbb18cfee", "wanchain"), `wanchain, from lowercase`).toEqual("0x7bB09Bc8Ade747178E95b1d035ECbEebBb18CfEE");
|
||||
});
|
||||
test(`Test isEthereumAddress`, () => {
|
||||
expect(isEthereumAddress("0x7bb09bc8ade747178e95b1d035ecbeebbb18cfee")).toBe(true);
|
||||
expect(isEthereumAddress("b09bc8ade747178e95b1d035ecbeebbb18cfee")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Test image helpers", () => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user