fix clas name and bytecode

This commit is contained in:
Jonathan Rainville 2018-04-13 15:48:19 -04:00
parent 17e1c71506
commit 99c04b405f
2 changed files with 13 additions and 9 deletions

View File

@ -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"));

View File

@ -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();
});
}