-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsighashes.js
executable file
·46 lines (37 loc) · 1.35 KB
/
sighashes.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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const c = require('chalk');
const { FunctionFragment } = require('ethers');
function sighash(base, sighashes) {
let output = fs.readFileSync(path.join(base, 'output.jsonc'), 'utf8');
output = output.replace(/^\/\/(sol|json)\n/, '');
const { contracts } = JSON.parse(output);
for (const file in contracts) {
for (const contract in contracts[file]) {
const { abi } = contracts[file][contract];
const fns = abi.filter(m => m.type === 'function').map(m => FunctionFragment.from(m).format('sighash'));
for (const fn of fns) {
sighashes.add(fn);
}
}
}
}
function main() {
const config = require('./.config.js');
const sighashes = new Set();
for (const prefix of fs.readdirSync(config.contracts)) {
process.stdout.write(`${prefix}`);
process.stdout.write(parseInt(prefix, 16) % 16 === 15 ? '\n' : c.dim(' | '));
for (const hash of fs.readdirSync(`${config.contracts}/${prefix}`)) {
try {
sighash(`${config.contracts}/${prefix}/${hash}`, sighashes);
} catch (err) {
}
}
}
const arr = Array.from(sighashes);
arr.sort();
fs.writeFileSync('sighashes.json', JSON.stringify(arr, null, 2));
}
main();