-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
67 lines (59 loc) · 1.75 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { assets, chains } from 'chain-registry'
import fetch from 'node-fetch'
import fs from 'fs'
var finalData = []
async function getLcd(chain) {
let finder = chains.find(
({chain_name}) => chain_name === chain
)
let finalLcd = ''
if (typeof finder !== 'undefined' && typeof finder.apis !== 'undefined') {
for (const lcds of finder.apis.rest) {
try {
const response = await fetch(lcds.address + '/node_info')
if (response.status == 200) {
finalLcd = lcds.address
break
}
} catch (err) {
console.error(err)
}
}
}
return finalLcd
}
async function getRpc(chain) {
let finder = chains.find(
({chain_name}) => chain_name === chain
)
let finalRpc = ''
if (typeof finder !== 'undefined' && typeof finder.apis !== 'undefined') {
for (const rpcs of finder.apis.rpc) {
try {
const response = await fetch(rpcs.address)
if (response.status == 200) {
finalRpc = rpcs.address
break
}
} catch (err) {
console.error(err)
}
}
}
return finalRpc
}
async function start() {
let getChains = fs.readFileSync('cosmos.config.json')
let getChainsJson = JSON.parse(getChains)
let datetime = new Date()
for (const chain of getChainsJson) {
chain.apiURL = await getLcd(chain.name.toLowerCase())
chain.rpcURL = await getRpc(chain.name.toLowerCase())
chain.lastUpdate = datetime
}
fs.writeFile("cosmos.config.json", JSON.stringify(getChainsJson, null, 2), (err) => {
if (err) { console.log(err); }
console.log("Task done!");
});
}
start()