This repository was archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (66 loc) · 2.06 KB
/
index.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
69
70
#!/usr/bin/env node
// @format
const program = require('commander');
const util = require('util');
const fs = require('fs');
const exec = util.promisify(require('child_process').exec);
const readFile = util.promisify(fs.readFile);
const resolve = require('path').resolve;
const basename = require('path').basename;
const axios = require('axios');
const verifier = require('sol-verifier');
const rimraf = require('rimraf');
const version = require('./package.json').version;
program
.version(version)
.option('-f --file <path>', 'Contract file to flatten')
.option('-k --api-key <path>', 'Etherscan API key')
.option('-a --address <path>', 'Contract address')
.option('-n --name <path>', 'Contract name')
.option('-e --network <path>', 'Network to upload contract')
.option(
'-c --constructor-parameters [args...]',
'Comma separated list of constructor names',
val => val.split(','),
[],
)
.option(
'-v --constructor-values [args...]',
'Comma separated list of constructor params',
val => val.split(','),
[],
)
.option('-o --optimize', 'Optimizes the contract in 200 cycles')
.parse(process.argv);
(async function flatten() {
const modulesDir = (await exec('npm root -g')).stdout.trim();
const path = `${modulesDir}/etherscan-uploader/node_modules/.bin/poa-solidity-flattener`;
const file = resolve(program.file);
const fileName = basename(file).split('.')[0];
const args = `${path} ${file}`;
const {stdout, stderr} = await exec(args);
if (stderr) {
console.log(stderr);
process.exit();
}
const data = {
key: program.apiKey,
path: `./out/${fileName}_flat.sol`,
contractAddress: program.address,
network: program.network,
contractName: fileName,
cparams: program.constructorParameters,
cvalues: program.constructorValues,
optimizationFlag: program.optimize,
};
let res;
try {
res = await verifier.verifyContract(data);
} catch (err) {
console.log(err);
process.exit();
}
rimraf.sync('./out');
console.log('Response from Etherscan API');
console.log(res);
})();