-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.js
83 lines (73 loc) · 2.13 KB
/
compile.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
71
72
73
74
75
76
77
78
79
80
81
82
83
const path = require('path');
const solc = require('solc');
const fs = require('fs-extra');
const buildPath = path.resolve(__dirname, 'build');
fs.removeSync(buildPath);
const contractPath = path.resolve(__dirname,'contracts');
var sources = new Array();
fs.readdir(contractPath, (err, files) => {
if (err) {
console.error("Could not list the directory.", err);
process.exit(1);
} else {
files.forEach( (file,_) => {
sources.push(fs.readFileSync(contractPath + '/' + file,'UTF-8'));
});
};
});
var output;
fs.ensureDirSync(buildPath);
//Timeout is used, since JS fires off a callback upon fs.readdir, which takes some time to complete.
setTimeout(() => {
const input = {
language: "Solidity",
sources: {
"PKI.sol": {
content: sources[0]
},
"Verify_deployRenter.sol": {
content: sources[1]
},
"Verify_renterBooking.sol": {
content: sources[2]
},
"Verify_renterPayment.sol": {
content: sources[3]
},
"dPACE.sol": {
content: sources[4]
},
},settings: {
outputSelection: {
"*": {
"*": ["abi", "evm.bytecode.object"]
}
}
}
};
output = JSON.parse(solc.compile(JSON.stringify(input),
{ import: findImports })).contracts;
for (let contract in output){
//If library, they have to be kept separately
if (contract === 'verify_libs.sol'){
for (let lib in output[contract]){
fs.outputJsonSync(
path.resolve(buildPath, lib + '.json'),
output[contract]);
}
}
else {
fs.outputJsonSync(
path.resolve(buildPath, contract.slice(0,-4) + '.json'),
output[contract]
);
}}
},
100
);
function findImports(path) {
return {
contents:
fs.readFileSync(contractPath + '/' + path,'utf8')
};
}