2019-11-08 18:55:41 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
import { getOpenseaCollectionAddresses } from "./opesea_contrats"
|
|
|
|
|
|
|
|
import {
|
2020-01-17 08:31:42 +00:00
|
|
|
Ethereum, Terra, Tron,
|
2020-04-11 00:49:55 +00:00
|
|
|
getChainAssetInfoPath,
|
|
|
|
getChainAssetsList,
|
2020-01-17 08:31:42 +00:00
|
|
|
ethSidechains,
|
2019-11-08 18:55:41 +00:00
|
|
|
getChainBlacklistPath,
|
2020-04-04 05:22:45 +00:00
|
|
|
getChainValidatorsListPath,
|
2020-04-11 00:49:55 +00:00
|
|
|
getChainWhitelistPath,
|
2019-11-08 18:55:41 +00:00
|
|
|
getUnique,
|
2020-04-11 00:49:55 +00:00
|
|
|
isChainAssetInfoExistSync,
|
|
|
|
isChainBlacklistExistSync,
|
|
|
|
isChainWhitelistExistSync,
|
2020-04-04 05:22:45 +00:00
|
|
|
mapList,
|
2020-04-11 00:49:55 +00:00
|
|
|
readFileSync,
|
|
|
|
sortDesc,
|
|
|
|
stakingChains,
|
|
|
|
writeFileSync,
|
2019-11-08 18:55:41 +00:00
|
|
|
} from '../src/test/helpers'
|
|
|
|
|
2020-04-04 05:22:45 +00:00
|
|
|
formatWhiteBlackList()
|
|
|
|
formatValidators()
|
2020-04-11 00:49:55 +00:00
|
|
|
formatInfo()
|
2019-11-08 18:55:41 +00:00
|
|
|
|
2020-04-04 05:22:45 +00:00
|
|
|
function formatWhiteBlackList() {
|
2020-04-05 19:28:39 +00:00
|
|
|
ethSidechains.concat(Tron, Terra).forEach(async chain => {
|
2020-04-11 00:49:55 +00:00
|
|
|
const assets = getChainAssetsList(chain)
|
2020-04-04 05:22:45 +00:00
|
|
|
|
|
|
|
const whitelistPath = getChainWhitelistPath(chain)
|
|
|
|
const blacklistPath = getChainBlacklistPath(chain)
|
2020-04-07 00:08:19 +00:00
|
|
|
|
2020-04-04 05:22:45 +00:00
|
|
|
//Create inital lists if they do not exists
|
|
|
|
if (!isChainWhitelistExistSync(chain)) {
|
|
|
|
writeFileSync(whitelistPath, `[]`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isChainBlacklistExistSync(chain)) {
|
|
|
|
writeFileSync(blacklistPath, `[]`)
|
|
|
|
}
|
|
|
|
|
|
|
|
const currentWhitelist = JSON.parse(readFileSync(whitelistPath))
|
|
|
|
const currentBlacklist = JSON.parse(readFileSync(blacklistPath))
|
|
|
|
|
|
|
|
let newBlackList = []
|
|
|
|
// Some chains required pulling lists from other sources
|
2020-04-21 21:24:41 +00:00
|
|
|
// switch (chain) {
|
|
|
|
// case Ethereum:
|
|
|
|
// const nftList = await getOpenseaCollectionAddresses()
|
|
|
|
// newBlackList = currentBlacklist.concat(nftList)
|
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// newBlackList = newBlackList.concat(currentBlacklist)
|
|
|
|
// break;
|
|
|
|
// }
|
2020-04-04 05:22:45 +00:00
|
|
|
|
|
|
|
const removedAssets = getRemovedAddressesFromAssets(assets, currentWhitelist)
|
2020-04-21 21:24:41 +00:00
|
|
|
newBlackList = currentBlacklist.concat(removedAssets)
|
2020-04-04 05:22:45 +00:00
|
|
|
|
|
|
|
fs.writeFileSync(whitelistPath, JSON.stringify(sortDesc(assets), null, 4))
|
|
|
|
fs.writeFileSync(blacklistPath, JSON.stringify(getUnique(sortDesc(newBlackList)), null, 4))
|
|
|
|
})
|
|
|
|
}
|
2019-11-08 18:55:41 +00:00
|
|
|
|
2020-04-04 05:22:45 +00:00
|
|
|
function formatValidators() {
|
|
|
|
stakingChains.forEach(chain => {
|
|
|
|
const validatorsPath = getChainValidatorsListPath(chain)
|
|
|
|
const currentValidatorsList = JSON.parse(readFileSync(validatorsPath))
|
2019-11-08 18:55:41 +00:00
|
|
|
|
2020-04-04 05:22:45 +00:00
|
|
|
fs.writeFileSync(validatorsPath, JSON.stringify(currentValidatorsList, null, 4))
|
|
|
|
})
|
|
|
|
}
|
2019-11-08 18:55:41 +00:00
|
|
|
|
2020-04-11 00:49:55 +00:00
|
|
|
function formatInfo() {
|
|
|
|
ethSidechains.forEach(chain => {
|
|
|
|
const chainAssets = getChainAssetsList(chain)
|
|
|
|
chainAssets.forEach(address => {
|
|
|
|
if (isChainAssetInfoExistSync(chain, address)) {
|
|
|
|
const chainAssetInfoPath = getChainAssetInfoPath(chain, address)
|
|
|
|
const currentAssetInfo = JSON.parse(readFileSync(chainAssetInfoPath))
|
|
|
|
fs.writeFileSync(chainAssetInfoPath, JSON.stringify(currentAssetInfo, null, 4))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-01-04 23:20:43 +00:00
|
|
|
function getRemovedAddressesFromAssets(assets: string[], whiteList: string[]): string[] {
|
|
|
|
const mappedAssets = mapList(assets)
|
|
|
|
const removed = whiteList.filter(a => !mappedAssets.hasOwnProperty(a))
|
|
|
|
return removed
|
|
|
|
}
|