-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.js
executable file
·62 lines (47 loc) · 1.98 KB
/
fetch.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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const c = require('chalk');
async function download(version) {
const path = `./.solc/${version}.js`;
if (!fs.existsSync(path)) {
const resp = await fetch(`https://binaries.soliditylang.org/bin/soljson-${version}.js`);
if (resp.ok) {
fs.writeFileSync(path, await resp.text());
process.stdout.write(c.yellow('fetch'));
} else {
console.info(c.red(`${resp.status} ${resp.statusText}`));
return;
}
} else {
process.stdout.write(c.yellow('cached'));
}
console.info(c.green(' \u2713'));
}
async function main() {
const config = require('./.config.js');
fs.mkdirSync('.solc', { recursive: true });
const versions = new Map();
console.info('Collecting solc version info...');
console.info('Prefixes');
for (const prefix of fs.readdirSync(config.contracts)) {
process.stdout.write(`${prefix} ${parseInt(prefix, 16) % 8 === 7 ? '\n' : c.dim(' | ')}`);
for (const hash of fs.readdirSync(`${config.contracts}/${prefix}`)) {
const base = `${config.contracts}/${prefix}/${hash}`;
const metadata = JSON.parse(fs.readFileSync(path.join(base, 'metadata.json'), 'utf8'));
const version = metadata.CompilerVersion;
if (!versions.has(version)) {
versions.set(version, []);
}
versions.get(version).push(`${prefix}/${hash}`);
}
}
console.info('Total', c.bold('solc'), 'Versions:', c.blue(versions.size));
console.info('Fetching versions...');
for (const [version, hashes] of versions.entries()) {
process.stdout.write(`Fetching solc ${c.cyan(version)} (used by ${c.magenta(hashes.length + ' contracts')})... `);
await download(version);
fs.writeFileSync(`.solc/${version}.hashes.json`, JSON.stringify(hashes, null, 2));
}
}
main().catch(err => console.error(err));