From 32ac41a9cbef357d7b435319da14a1c12525a25c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 1 Oct 2015 23:04:15 -0400 Subject: [PATCH] compile using js solc --- lib/compiler.js | 34 ++++++++-------------------------- package.json | 1 + 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index 2006fd57..7593f0e1 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -1,6 +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; @@ -21,44 +23,24 @@ Compiler.prototype.init = function(env) { }; Compiler.prototype.compile_solidity = function(contractFile) { - var cmd, result, output, version, json, compiled_object; + var source = fs.readFileSync(contractFile).toString(); + var output = solc.compile(source, 1); - cmd = "solc --version"; + var json = output.contracts; - result = exec(cmd, {silent: true}); - output = result.output; - version = output.split('\n')[1].split(' ')[1].slice(0,5); - - if (version == '0.1.1') { - cmd = "solc --input-file " + contractFile + " --combined-json binary,json-abi"; - } - else { - cmd = "solc --input-file " + contractFile + " --combined-json bin,abi"; - } - - result = exec(cmd, {silent: true}); - output = result.output; - - if (result.code === 1) { - if (version == '0.1.1' || version == '0.1.0'){ - throw new Error(result.output); - } - } - - json = JSON.parse(output).contracts; 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].code = contract.bytecode; compiled_object[className].info = {}; - compiled_object[className].info.abiDefinition = JSON.parse(contract["abi"] || contract["json-abi"]); + compiled_object[className].info.abiDefinition = JSON.parse(contract.interface); } return compiled_object; -} +}; Compiler.prototype.compile_serpent = function(contractFile) { var cmd, result, output, json, compiled_object; diff --git a/package.json b/package.json index 0987a62a..3d693ce6 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "python": "^0.0.4", "read-yaml": "^1.0.0", "shelljs": "^0.5.0", + "solc": "^0.1.3-2", "sync-me": "^0.1.1", "toposort": "^0.2.10", "web3": "^0.8.1",