Skip to content

Commit a872a6d

Browse files
committed
Use standard json internally in solcjs in every case
1 parent 41d674b commit a872a6d

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

solcjs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,36 @@ var sources = {};
7474

7575
for (var i = 0; i < files.length; i++) {
7676
try {
77-
sources[ files[i] ] = fs.readFileSync(files[i]).toString();
77+
sources[ files[i] ] = { content: fs.readFileSync(files[i]).toString() };
7878
} catch (e) {
7979
abort('Error reading ' + files[i] + ': ' + e);
8080
}
8181
}
8282

83-
var output = solc.compile({ sources: sources }, argv.optimize ? 1 : 0);
83+
var output = JSON.parse(solc.compileStandardWrapper(JSON.stringify({
84+
language: 'Solidity',
85+
settings: {
86+
optimizer: {
87+
enabled: argv.optimize
88+
},
89+
outputSelection: {
90+
'*': {
91+
'*': [ 'abi', 'evm.bytecode' ]
92+
}
93+
}
94+
},
95+
sources: sources
96+
})));
97+
8498
if (!output) {
8599
abort('No output from compiler');
86100
} else if (output['errors']) {
87-
function isWarning (message) {
88-
return message.match(/^(.*:[0-9]*:[0-9]* )?Warning: /)
89-
}
90-
91101
for (var error in output['errors']) {
92102
var message = output['errors'][error]
93-
if (isWarning(message)) {
94-
console.log(message)
103+
if (message.severity === 'warning') {
104+
console.log(message.formattedMessage)
95105
} else {
96-
console.error(message)
106+
console.error(message.formattedMessage)
97107
}
98108
}
99109
}
@@ -109,15 +119,18 @@ function writeFile (file, content) {
109119
});
110120
}
111121

112-
for (var contractName in output.contracts) {
113-
var contractFileName = contractName.replace(/[:./]/g, '_');
122+
for (var fileName in output.contracts) {
123+
for (var contractName in output.contracts[fileName]) {
124+
var contractFileName = fileName + ':' + contractName;
125+
contractFileName = contractFileName.replace(/[:./]/g, '_');
114126

115-
if (argv.bin) {
116-
writeFile(contractFileName + '.bin', output.contracts[contractName].bytecode);
117-
}
127+
if (argv.bin) {
128+
writeFile(contractFileName + '.bin', output.contracts[fileName][contractName].evm.bytecode.object);
129+
}
118130

119-
if (argv.abi) {
120-
writeFile(contractFileName + '.abi', output.contracts[contractName].interface);
131+
if (argv.abi) {
132+
writeFile(contractFileName + '.abi', JSON.stringify(output.contracts[fileName][contractName].abi));
133+
}
121134
}
122135
}
123136

0 commit comments

Comments
 (0)