-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathmake-blocks.js
67 lines (59 loc) · 2.1 KB
/
make-blocks.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
#!/usr/bin/env node
/* eslint @typescript-eslint/no-var-requires: "off" */
const fs = require('fs')
const http = require('http')
const https = require('https')
const url = require('url')
const networkUrl =
'https://raw.githubusercontent.com/hyperledger/indy-node-monitor/main/fetch-validator-status/networks.json'
const networksToAdd = [
{ id: 'bct', connectOnStartup: true, production: false },
{ id: 'cdn', connectOnStartup: true, production: false },
{ id: 'ctn', connectOnStartup: true, production: false },
{ id: 'cpn', connectOnStartup: true, production: true },
{ id: 'imn', connectOnStartup: true, production: true },
{ id: 'idn', connectOnStartup: true, production: false },
{ id: 'itn', connectOnStartup: true, production: false },
{ id: 'sbn', connectOnStartup: true, production: false },
{ id: 'ssn', connectOnStartup: true, production: false },
{ id: 'smn', connectOnStartup: true, production: true },
]
const networkNameRe = /\W+/im
const getUrlContents = async (aUrl) => {
const client = aUrl.protocol.slice(0, -1) === 'http' ? http : https
return new Promise((resolve) => {
let data = ''
client.get(aUrl, (res) => {
res.on('data', (chunk) => {
data += chunk
})
res.on('end', () => {
resolve(data)
})
})
})
}
const main = async () => {
const networksAsString = await getUrlContents(url.parse(networkUrl))
const networks = JSON.parse(networksAsString)
const myNetworks = networksToAdd.map((n) => Object({ ...n, ...networks[n.id] }))
let ledgers = []
for (let n of myNetworks) {
const aUrl = url.parse(n['genesisUrl'])
const name = n['name']
.split(' ')
.filter((w) => !networkNameRe.test(w))
.join('')
const transaction = await getUrlContents(aUrl)
// const data = `export default \`${block.trim()}\`\n`
ledgers.push({
id: name,
indyNamespace: n['indyNamespace'],
isProduction: n['production'],
connectOnStartup: n['connectOnStartup'],
genesisTransactions: transaction.trim(),
})
}
fs.writeFileSync(`ledgers.json`, JSON.stringify(ledgers, null, 2), 'utf8')
}
main()