Update compiler.js
This commit is contained in:
parent
0ec7c88cd9
commit
9e8ebe9cb3
|
@ -1,7 +1,8 @@
|
|||
var shelljs = require('shelljs');
|
||||
var shelljs_global = require('shelljs/global');
|
||||
var web3 = require('web3');
|
||||
|
||||
var fs = require('fs');
|
||||
var solc = require('solc');
|
||||
|
||||
Compiler = function(blockchainConfig) {
|
||||
this.blockchainConfig = blockchainConfig;
|
||||
|
@ -11,26 +12,31 @@ Compiler.prototype.init = function(env) {
|
|||
var config = this.blockchainConfig.config(env);
|
||||
};
|
||||
|
||||
Compiler.prototype.compile_solidity = function(contractFile) {
|
||||
var cmd, result, output, version, json, compiled_object;
|
||||
Compiler.prototype.compile_solidity = function(contractFiles) {
|
||||
console.log("I HAVE REACHED HERE THROUGH GRUNT-EMBARK")
|
||||
var source = '{ ';
|
||||
for (var contractFile in contractFiles){
|
||||
source += '\'' + contractFile + '\': \''
|
||||
var file = fs.readFileSync(contractFile).toString() + '\'';
|
||||
|
||||
cmd = "solc " + contractFile + " --combined-json bin,abi";
|
||||
if (!contractFiles.length) source += ', '
|
||||
}
|
||||
source += '}';
|
||||
|
||||
var output = solc.compile(source, 1);
|
||||
|
||||
result = exec(cmd, {silent: true});
|
||||
output = result.output;
|
||||
var json = output.contracts;
|
||||
|
||||
json = JSON.parse(output).contracts;
|
||||
compiled_object = {}
|
||||
|
||||
compiled_object = {}
|
||||
|
||||
for (var className in json) {
|
||||
var contract = json[className];
|
||||
|
||||
compiled_object[className] = {};
|
||||
compiled_object[className].code = contract.binary || contract.bin;
|
||||
compiled_object[className].info = {};
|
||||
compiled_object[className].info.abiDefinition = JSON.parse(contract["abi"] || contract["json-abi"]);
|
||||
}
|
||||
for (var className in json) {
|
||||
var contract = json[className];
|
||||
|
||||
compiled_object[className] = {};
|
||||
compiled_object[className].code = contract.bytecode;
|
||||
compiled_object[className].info = {};
|
||||
compiled_object[className].info.abiDefinition = JSON.parse(contract.interface);
|
||||
}
|
||||
|
||||
return compiled_object;
|
||||
};
|
||||
|
@ -75,18 +81,24 @@ Compiler.prototype.compile_serpent = function(contractFile) {
|
|||
}
|
||||
|
||||
|
||||
Compiler.prototype.compile = function(contractFile) {
|
||||
var extension = contractFile.split('.')[1];
|
||||
Compiler.prototype.compile = function(contractFiles) {
|
||||
var solidity = [], serpent = [];
|
||||
|
||||
for (contract in contractFiles) {
|
||||
var extension = contractFile.split('.')[1];
|
||||
if (extension === 'sol') {
|
||||
solidity.push(contractFile);
|
||||
}
|
||||
else if (extension === 'se') {
|
||||
serpent.push(contractFile);
|
||||
}
|
||||
else {
|
||||
throw new Error("extension not known");
|
||||
}
|
||||
}
|
||||
|
||||
if (extension === 'sol') {
|
||||
return this.compile_solidity(contractFile);
|
||||
}
|
||||
else if (extension === 'se') {
|
||||
return this.compile_serpent(contractFile);
|
||||
}
|
||||
else {
|
||||
throw new Error("extension not known");
|
||||
}
|
||||
if (solidity.length > 0) return compile_solidity(solidity);
|
||||
if (serpent.length > 0) return compile_serpent(serpent);
|
||||
};
|
||||
|
||||
module.exports = Compiler;
|
||||
|
|
Loading…
Reference in New Issue