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,
|
2019-11-08 18:55:41 +00:00
|
|
|
getChainAssetsPath,
|
2020-01-17 08:31:42 +00:00
|
|
|
ethSidechains,
|
2019-11-08 18:55:41 +00:00
|
|
|
readDirSync,
|
|
|
|
readFileSync,
|
|
|
|
isChainWhitelistExistSync,
|
|
|
|
isChainBlacklistExistSync,
|
|
|
|
getChainWhitelistPath,
|
|
|
|
getChainBlacklistPath,
|
2020-04-04 05:22:45 +00:00
|
|
|
getChainValidatorsListPath,
|
2019-11-08 18:55:41 +00:00
|
|
|
writeFileSync,
|
|
|
|
sortDesc,
|
|
|
|
getUnique,
|
2020-04-04 05:22:45 +00:00
|
|
|
mapList,
|
|
|
|
stakingChains
|
2019-11-08 18:55:41 +00:00
|
|
|
} from '../src/test/helpers'
|
|
|
|
|
2020-04-04 05:22:45 +00:00
|
|
|
formatWhiteBlackList()
|
|
|
|
formatValidators()
|
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-04 05:22:45 +00:00
|
|
|
const assets = readDirSync(getChainAssetsPath(chain))
|
|
|
|
|
|
|
|
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
|
|
|
|
switch (chain) {
|
|
|
|
case Ethereum:
|
|
|
|
const nftList = await getOpenseaCollectionAddresses()
|
|
|
|
newBlackList = currentBlacklist.concat(nftList)
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newBlackList = newBlackList.concat(currentBlacklist)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const removedAssets = getRemovedAddressesFromAssets(assets, currentWhitelist)
|
|
|
|
newBlackList = newBlackList.concat(removedAssets)
|
|
|
|
|
|
|
|
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-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
|
|
|
|
}
|