forked from olivdb/truffle-source-verify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.js
More file actions
47 lines (41 loc) · 1.25 KB
/
lib.js
File metadata and controls
47 lines (41 loc) · 1.25 KB
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
const { spawn } = require("child_process");
async function verify(contractNames, network, options = {}) {
const commandOptions = [
'--network', network,
];
if (options.license) {
commandOptions.push('--license', options.license)
}
if (options.debug) {
commandOptions.push('--debug')
}
if (options.forceConstructorArgs) {
commandOptions.push('--forceConstructorArgs', options.forceConstructorArgs)
}
let explorer;
if (["mainnet", "rinkeby", "kovan", "ropsten", "goerli"].includes(network)) {
explorer = "etherscan";
} else if (["xdai", "sokol", "elastos", "esc-testnet", "elatest"].includes(network)) {
explorer = "blockscout";
} else {
console.error(
`truffle-source-verify does not support network "${network}"`
);
return;
}
return new Promise((resolve, reject) => {
console.log(
`Verifying ${contractNames.length} contracts on ${explorer}...`
);
const cmd = `truffle run ${explorer} ${contractNames.join(
" "
)} ${commandOptions.join(" ")}`;
const p = spawn("npx", cmd.split(" "), {
stdio: "inherit",
});
console.log(`npx ${cmd}`);
p.on("exit", (code) => resolve(code));
p.on("error", (code) => reject(code));
});
}
module.exports = { verify };