-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.js
More file actions
39 lines (32 loc) · 1.07 KB
/
Copy pathparser.js
File metadata and controls
39 lines (32 loc) · 1.07 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
const localpath = "./build/contracts";
const { Console } = require("console");
const fs = require("fs");
const path = require("path");
console.log("Into the parser");
module.exports = async (network) => {
console.log("Starting the Parser");
fs.readdir(localpath, (err, files) => {
const artifactsDir = __dirname + "/artifacts/" + `${network}`;
if (!fs.existsSync(artifactsDir)) {
fs.mkdirSync(artifactsDir);
}
files.forEach((file) => {
const filePath = path.resolve(__dirname, `${localpath}/${file}`);
const fileContent = JSON.parse(fs.readFileSync(filePath));
try {
const contractName = fileContent.contractName;
const abi = fileContent.abi;
const bytecode = fileContent.bytecode;
fs.writeFile(
`${artifactsDir}/${contractName}.json`,
`{ "bytecode" : "${bytecode}","abi" : ${JSON.stringify(abi)}}
`,
(err) => err ? Console.warn("Error", err) : -1
);
} catch (error) {
Console.warn("Invalid");
}
});
});
console.log("Done Parsing");
};