mirror of
https://github.com/Instadapp/chains.git
synced 2024-07-29 22:37:19 +00:00
Remove javascript stuff
This commit is contained in:
parent
0f96a6eb8d
commit
4ec909fe7b
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"extends": "standard"
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
const {
|
|
||||||
CHAINS_DIRECTORY,
|
|
||||||
startSpinner,
|
|
||||||
stopSpinner,
|
|
||||||
stat,
|
|
||||||
tableLog,
|
|
||||||
toNumber
|
|
||||||
} = require('./shared')
|
|
||||||
|
|
||||||
fs.readdir(CHAINS_DIRECTORY, async function (err, files) {
|
|
||||||
if (err) {
|
|
||||||
console.error('Could not list the directory.', err)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
let matches = []
|
|
||||||
|
|
||||||
startSpinner(`Counting ${CHAINS_DIRECTORY}`)
|
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
files.map(async function (file, index) {
|
|
||||||
const filePath = path.join(CHAINS_DIRECTORY, file)
|
|
||||||
const fileStat = await stat(filePath)
|
|
||||||
const ext = path.extname(file)
|
|
||||||
if (fileStat.isFile() && ext === '.json') {
|
|
||||||
let json = require(filePath)
|
|
||||||
if (toNumber(json.chainId) !== toNumber(json.networkId)) {
|
|
||||||
matches.push(json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fileStat
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
stopSpinner()
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`There are ${files.length} known EVM chains from which ${
|
|
||||||
matches.length
|
|
||||||
} have unmatched ids, here are the list of those chains: `
|
|
||||||
)
|
|
||||||
tableLog(matches)
|
|
||||||
})
|
|
1547
scripts/package-lock.json
generated
1547
scripts/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -1,27 +0,0 @@
|
||||||
{
|
|
||||||
"name": "script",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"axios": "^0.19.0",
|
|
||||||
"bignumber.js": "^9.0.0",
|
|
||||||
"dotenv": "^8.0.0",
|
|
||||||
"lodash.sortby": "^4.7.0",
|
|
||||||
"ora": "^3.4.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"eslint": "^5.16.0",
|
|
||||||
"eslint-config-standard": "^12.0.0",
|
|
||||||
"eslint-plugin-import": "^2.17.3",
|
|
||||||
"eslint-plugin-node": "^9.1.0",
|
|
||||||
"eslint-plugin-promise": "^4.1.1",
|
|
||||||
"eslint-plugin-standard": "^4.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,195 +0,0 @@
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
const axios = require('axios')
|
|
||||||
const BigNumber = require('bignumber.js')
|
|
||||||
const sortBy = require('lodash.sortby')
|
|
||||||
const ora = require('ora')
|
|
||||||
|
|
||||||
require('dotenv').config()
|
|
||||||
|
|
||||||
const ROOT_DIRECTORY = path.join(__dirname, '../../')
|
|
||||||
|
|
||||||
const CHAINS_DIRECTORY = path.join(ROOT_DIRECTORY, './_data/chains')
|
|
||||||
|
|
||||||
const NET_VERSION_REQ = {
|
|
||||||
id: 1,
|
|
||||||
jsonrpc: '2.0',
|
|
||||||
method: 'net_version',
|
|
||||||
params: []
|
|
||||||
}
|
|
||||||
|
|
||||||
const CHAIN_ID_REQ = {
|
|
||||||
id: 1,
|
|
||||||
jsonrpc: '2.0',
|
|
||||||
method: 'eth_chainId',
|
|
||||||
params: []
|
|
||||||
}
|
|
||||||
|
|
||||||
let spinner = null
|
|
||||||
|
|
||||||
function startSpinner (message) {
|
|
||||||
spinner = ora(message).start()
|
|
||||||
}
|
|
||||||
|
|
||||||
function stopSpinner () {
|
|
||||||
if (spinner) {
|
|
||||||
spinner.stop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function padRight (n, width, z) {
|
|
||||||
z = z || '0'
|
|
||||||
n = n + ''
|
|
||||||
return n.length >= width ? n : n + new Array(width - n.length + 1).join(z)
|
|
||||||
}
|
|
||||||
|
|
||||||
function paddedLog (...args) {
|
|
||||||
let output = ''
|
|
||||||
args.forEach(arg => {
|
|
||||||
output += padRight(`${arg}`, 32, ' ')
|
|
||||||
})
|
|
||||||
console.log(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
function tableLog (chains) {
|
|
||||||
chains = sortBy(chains, ['chainId'])
|
|
||||||
console.log('\n')
|
|
||||||
paddedLog('Name', 'Chain', 'ChainId', 'NetworkId')
|
|
||||||
console.log('\n')
|
|
||||||
chains.map(json =>
|
|
||||||
paddedLog(json.name, json.chain, json.chainId, json.networkId)
|
|
||||||
)
|
|
||||||
console.log('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
function stat (filePath) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
fs.stat(filePath, function (error, stat) {
|
|
||||||
if (error) {
|
|
||||||
return reject(error)
|
|
||||||
}
|
|
||||||
resolve(stat)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatRpcUrl (rpcUrl) {
|
|
||||||
return rpcUrl.replace(
|
|
||||||
'${INFURA_API_KEY}', // eslint-disable-line
|
|
||||||
process.env.INFURA_PROJECT_ID
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function writeJson (filePath, json) {
|
|
||||||
// console.log('Overwriting', filePath)
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const data = JSON.stringify(json, null, 2)
|
|
||||||
fs.writeFile(filePath, data, (err, res) => {
|
|
||||||
if (err) {
|
|
||||||
reject(err)
|
|
||||||
}
|
|
||||||
resolve(res)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function rpcRequest (rpcUrl, body) {
|
|
||||||
const response = await axios.post(rpcUrl, body, {
|
|
||||||
timeout: 20000, // 20 secs
|
|
||||||
headers: {
|
|
||||||
Accept: 'application/json',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if (!response && !response.data) {
|
|
||||||
throw new Error('No Response Body')
|
|
||||||
}
|
|
||||||
if (response.data.error && response.data.error.message) {
|
|
||||||
throw new Error(response.data.error.message)
|
|
||||||
}
|
|
||||||
return response.data.result
|
|
||||||
}
|
|
||||||
|
|
||||||
function toNumber (value) {
|
|
||||||
const BN = new BigNumber(value)
|
|
||||||
let result = null
|
|
||||||
if (!BN.isNaN()) {
|
|
||||||
result = BN.toNumber()
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getNetworkId (rpcUrl) {
|
|
||||||
try {
|
|
||||||
rpcUrl = formatRpcUrl(rpcUrl)
|
|
||||||
const result = await rpcRequest(rpcUrl, NET_VERSION_REQ)
|
|
||||||
const networkId = toNumber(result)
|
|
||||||
return networkId
|
|
||||||
} catch (error) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getChainId (rpcUrl) {
|
|
||||||
try {
|
|
||||||
rpcUrl = formatRpcUrl(rpcUrl)
|
|
||||||
const result = await rpcRequest(rpcUrl, CHAIN_ID_REQ)
|
|
||||||
const chainId = toNumber(result)
|
|
||||||
return chainId
|
|
||||||
} catch (error) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function queryMulti (urls, apiCall) {
|
|
||||||
let result = null
|
|
||||||
let results = await Promise.all(
|
|
||||||
urls.map(async url => {
|
|
||||||
try {
|
|
||||||
return await apiCall(url)
|
|
||||||
} catch (error) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
if (results && results.length) {
|
|
||||||
results = results.filter(x => !!x)
|
|
||||||
result = results[0] || null
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
async function verifyJson (json) {
|
|
||||||
if (json.rpc && json.rpc.length) {
|
|
||||||
const chainId = await queryMulti(json.rpc, getChainId)
|
|
||||||
if (chainId) {
|
|
||||||
json.chainId = chainId
|
|
||||||
}
|
|
||||||
const networkId = await queryMulti(json.rpc, getNetworkId)
|
|
||||||
if (networkId) {
|
|
||||||
json.networkId = networkId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return json
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
ROOT_DIRECTORY,
|
|
||||||
CHAINS_DIRECTORY,
|
|
||||||
NET_VERSION_REQ,
|
|
||||||
CHAIN_ID_REQ,
|
|
||||||
startSpinner,
|
|
||||||
stopSpinner,
|
|
||||||
padRight,
|
|
||||||
paddedLog,
|
|
||||||
tableLog,
|
|
||||||
stat,
|
|
||||||
formatRpcUrl,
|
|
||||||
writeJson,
|
|
||||||
rpcRequest,
|
|
||||||
toNumber,
|
|
||||||
getNetworkId,
|
|
||||||
getChainId,
|
|
||||||
queryMulti,
|
|
||||||
verifyJson
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
const {
|
|
||||||
CHAINS_DIRECTORY,
|
|
||||||
startSpinner,
|
|
||||||
stopSpinner,
|
|
||||||
tableLog,
|
|
||||||
stat,
|
|
||||||
writeJson,
|
|
||||||
toNumber,
|
|
||||||
verifyJson
|
|
||||||
} = require('./shared')
|
|
||||||
|
|
||||||
fs.readdir(CHAINS_DIRECTORY, async function (err, files) {
|
|
||||||
if (err) {
|
|
||||||
console.error('Could not list the directory.', err)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
startSpinner(`Verifying ${CHAINS_DIRECTORY} files`)
|
|
||||||
|
|
||||||
let result = []
|
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
files.map(async function (file, index) {
|
|
||||||
const filePath = path.join(CHAINS_DIRECTORY, file)
|
|
||||||
const fileStat = await stat(filePath)
|
|
||||||
const ext = path.extname(file)
|
|
||||||
if (fileStat.isFile() && ext === '.json') {
|
|
||||||
let json = require(filePath)
|
|
||||||
const fileName = file.replace(ext, '')
|
|
||||||
if (toNumber(fileName)) {
|
|
||||||
json.chainId = toNumber(fileName)
|
|
||||||
}
|
|
||||||
json = await verifyJson(json)
|
|
||||||
await writeJson(filePath, json)
|
|
||||||
result.push(json)
|
|
||||||
}
|
|
||||||
return fileStat
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
stopSpinner()
|
|
||||||
|
|
||||||
tableLog(result)
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Successfully verified and wrote ${files.length} file${
|
|
||||||
files.length > 1 ? 's' : ''
|
|
||||||
}`
|
|
||||||
)
|
|
||||||
})
|
|
Loading…
Reference in New Issue
Block a user