-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse-abi-files.js
68 lines (47 loc) · 1.93 KB
/
parse-abi-files.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
68
import * as fs from 'fs';
import {parseEventAbiWithLabels} from './parse-abi.js';
import {fromDir, writeCsvFiles, writeSqlViewFilesFromAbis} from './util.js';
import JSONStream from 'JSONStream';
function parseAbiFilesForEvents() {
const promises = []
const project = 'beamswap'
const labels = new Set()
const contracts = new Map()
const events = new Set()
const abis = new Map()
const contractEvents = new Map()
fromDir(`./input/${project}`, /.json$/, filename => {
console.log(filename)
const contractAddress = filename.substr(filename.lastIndexOf('/')+1, 42)
const contractName = filename.substring(filename.lastIndexOf('/')+1+42, filename.indexOf('.json'))
const name = contractName.replace(/\s|\./g, '')
let countRecords = 0;
const jsonStream = JSONStream.parse('result')
const p = new Promise((resolve, reject) => {
jsonStream.on('data', datum => {
const abi = JSON.parse(datum)
const d = {abi: abi, address: contractAddress, namespace: project, name: name}
parseEventAbiWithLabels(d, labels, contracts, abis, events, contractEvents)
countRecords++
}).on('end', () => {
const m = `read ${countRecords} records from ${filename}`
console.log(m)
resolve(m)
}).on('error', e => {
const m = `cannot parse json in ${filename}`
console.error(m, e)
reject(m)
})
})
promises.push(p)
fs.createReadStream(filename).pipe(jsonStream)
})
Promise.all(promises).then(results => {
console.log(`resolved results ${JSON.stringify(results)}`)
console.log(`read ${labels.size} labels ${contracts.size} contracts ${events.size} events ${contractEvents.size} contractEvents ${abis.size} abis`)
const name = `parse-abi`
writeCsvFiles(labels, contracts, events, abis, name)
writeSqlViewFilesFromAbis(labels, contracts, events, abis, contractEvents, name)
})
}
parseAbiFilesForEvents()