mirror of https://github.com/embarklabs/embark.git
fix issue where contract was being deployed everytime when gas config was set; catch errors on individual onDeploy cmds
This commit is contained in:
parent
36d7890cfc
commit
ab5d3722b9
|
@ -44,10 +44,9 @@ class Deploy {
|
|||
return callback();
|
||||
}
|
||||
|
||||
if (contract.address !== undefined) {
|
||||
|
||||
realArgs = self.determineArguments(params || contract.args);
|
||||
|
||||
if (contract.address !== undefined) {
|
||||
contract.deployedAddress = contract.address;
|
||||
self.deployTracker.trackContract(contract.className, contract.realRuntimeBytecode, realArgs, contract.address);
|
||||
self.deployTracker.save();
|
||||
|
@ -55,7 +54,7 @@ class Deploy {
|
|||
return callback();
|
||||
}
|
||||
|
||||
let trackedContract = self.deployTracker.getContract(contract.className, contract.realRuntimeBytecode, contract.args);
|
||||
let trackedContract = self.deployTracker.getContract(contract.className, contract.realRuntimeBytecode, realArgs);
|
||||
|
||||
if (trackedContract && this.web3.eth.getCode(trackedContract.address) !== "0x") {
|
||||
self.logger.info(contract.className.bold.cyan + " already deployed at ".green + trackedContract.address.bold.cyan);
|
||||
|
@ -88,8 +87,8 @@ class Deploy {
|
|||
if (contract.onDeploy !== undefined) {
|
||||
self.logger.info('executing onDeploy commands');
|
||||
|
||||
let cmds = "";
|
||||
cmds += codeGenerator.generateContractCode(contract);
|
||||
let contractCode = codeGenerator.generateContractCode(contract);
|
||||
RunCode.doEval(contractCode, self.web3);
|
||||
|
||||
let withErrors = false;
|
||||
let regex = /\$\w+/g;
|
||||
|
@ -128,9 +127,18 @@ class Deploy {
|
|||
return callback(new Error("error running onDeploy"));
|
||||
}
|
||||
|
||||
cmds += onDeployCode.join(';\n');
|
||||
|
||||
RunCode.doEval(cmds, self.web3);
|
||||
// TODO: convert to for to avoid repeated callback
|
||||
for(let cmd of onDeployCode) {
|
||||
self.logger.info("executing: " + cmd);
|
||||
try {
|
||||
RunCode.doEval(cmd, self.web3);
|
||||
} catch(e) {
|
||||
if (e.message.indexOf("invalid opcode") >= 0) {
|
||||
self.logger.error('the transaction was rejected; this usually happens due to a throw or a require, it can also happen due to an invalid operation');
|
||||
}
|
||||
return callback(new Error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callback();
|
||||
|
|
|
@ -59,4 +59,3 @@ class DeployTracker {
|
|||
}
|
||||
|
||||
module.exports = DeployTracker;
|
||||
|
||||
|
|
Loading…
Reference in New Issue