always define contract code so ondeploy cmds work

This commit is contained in:
Iuri Matias 2017-12-27 11:40:21 -05:00
parent 33adaf360b
commit 750eace6ce
3 changed files with 16 additions and 2 deletions

View File

@ -61,6 +61,12 @@ class Deploy {
self.logger.info(contract.className.bold.cyan + " already deployed at ".green + trackedContract.address.bold.cyan);
contract.deployedAddress = trackedContract.address;
self.logger.contractsState(self.contractsManager.contractsState());
// always run contractCode so other functionality like 'afterDeploy' can also work
let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager});
let contractCode = codeGenerator.generateContractCode(contract);
RunCode.doEval(contractCode, self.web3);
return callback();
} else {
@ -74,9 +80,13 @@ class Deploy {
self.deployTracker.save();
self.logger.contractsState(self.contractsManager.contractsState());
// always run contractCode so other functionality like 'afterDeploy' can also work
let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager});
let contractCode = codeGenerator.generateContractCode(contract);
RunCode.doEval(contractCode, self.web3);
if (contract.onDeploy !== undefined) {
self.logger.info('executing onDeploy commands');
let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager});
let cmds = "";
cmds += codeGenerator.generateContractCode(contract);

View File

@ -117,7 +117,10 @@ class DeployManager {
return callback(new Error("error running afterDeploy"));
}
RunCode.doEval(onDeployCode.join(';\n'), web3);
onDeployCode.forEach((cmd) => {
self.logger.info("executing: " + cmd);
RunCode.doEval(cmd, web3);
});
callback(null, contractsManager);
}

View File

@ -14,6 +14,7 @@ function doEval(code, _web3) {
}
try {
// TODO: add trace log here
return eval(code); // jshint ignore:line
} catch(e) {
throw new Error(e + "\n" + code);