-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatABI.js
50 lines (40 loc) · 1.04 KB
/
formatABI.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
const fs = require("fs")
function getABI (path) {
const abi = require(path)
return abi
}
function capitalizeFirst (toCap) {
return toCap[0].toUpperCase() + toCap.slice(1)
}
function snakeToCap (snake) {
return snake.split('_')
.map(capitalizeFirst)
.join('')
}
function writeSingleABI (network, abiType, abis) {
const abiKey = `${abiType}_abi`
const addressKey = `${abiType}_address`
const abi = {
name: snakeToCap(abiType),
address: abis[addressKey],
abi: abis[abiKey]
}
fs.writeFile(
`abis/${network}/${snakeToCap(abiType)}.json`,
JSON.stringify(abi, null, 2),
err => {
// Checking for errors
if (err) throw err;
console.log(`Done writing ${snakeToCap(abiType)}`)
}
)
}
function index () {
const abi = getABI(process.argv[2])
const abiKeys = Object.keys(abi)
const abiTypes = abiKeys.filter(k => /_abi$/.test(k))
.map(k => k.replace('_abi', '') )
console.log(abiTypes)
abiTypes.forEach(abiType => writeSingleABI(process.argv[3], abiType, abi ))
}
index()