From 99c04b405f5c7091be0cf011568e45cc19d92a77 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 13 Apr 2018 15:48:19 -0400 Subject: [PATCH] fix clas name and bytecode --- lib/contracts/deploy.js | 3 ++- lib/modules/vyper/index.js | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index d6f6636e..d1b87ade 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -305,7 +305,8 @@ class Deploy { let contractObject = new self.web3.eth.Contract(contract.abiDefinition); try { - deployObject = contractObject.deploy({arguments: contractParams, data: "0x" + contractCode}); + const dataCode = contractCode.startsWith('0x') ? contractCode : "0x" + contractCode; + deployObject = contractObject.deploy({arguments: contractParams, data: dataCode}); } catch(e) { if (e.message.indexOf('Invalid number of parameters for "undefined"') >= 0) { return next(new Error("attempted to deploy " + contract.className + " without specifying parameters")); diff --git a/lib/modules/vyper/index.js b/lib/modules/vyper/index.js index d75fbe8c..df805a21 100644 --- a/lib/modules/vyper/index.js +++ b/lib/modules/vyper/index.js @@ -20,31 +20,34 @@ class Vyper { const compiled_object = {}; async.each(contractFiles, function (file, fileCb) { - const fileNameOnly = path.basename(file.filename); - compiled_object[fileNameOnly] = {}; + const className = path.basename(file.filename).split('.')[0]; + compiled_object[className] = {}; async.parallel([ function getByteCode(paraCb) { - shelljs.exec(`vyper ${file.filename}`, { silent: true }, (code, stdout, stderr) => { + shelljs.exec(`vyper ${file.filename}`, {silent: true}, (code, stdout, stderr) => { if (stderr) { return paraCb(stderr); } if (code !== 0) { - return paraCb(`Vyper exited with error code ${code}`) + return paraCb(`Vyper exited with error code ${code}`); } if (!stdout) { return paraCb('Execution returned no bytecode'); } - compiled_object[fileNameOnly].code = stdout.replace(/\n/g, ''); + const byteCode = stdout.replace(/\n/g, ''); + compiled_object[className].runtimeBytecode = byteCode; + compiled_object[className].realRuntimeBytecode = byteCode; + compiled_object[className].code = byteCode; paraCb(); }); }, function getABI(paraCb) { - shelljs.exec(`vyper -f json ${file.filename}`, { silent: true }, (code, stdout, stderr) => { + shelljs.exec(`vyper -f json ${file.filename}`, {silent: true}, (code, stdout, stderr) => { if (stderr) { return paraCb(stderr); } if (code !== 0) { - return paraCb(`Vyper exited with error code ${code}`) + return paraCb(`Vyper exited with error code ${code}`); } if (!stdout) { return paraCb('Execution returned no ABI'); @@ -55,7 +58,7 @@ class Vyper { } catch (e) { return paraCb('ABI is not valid JSON'); } - compiled_object[fileNameOnly].abiDefinition = ABI; + compiled_object[className].abiDefinition = ABI; paraCb(); }); }