diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index ceb408b8d..d4d731436 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -96,6 +96,13 @@ class CodeGenerator { } + generateContext() { + let result = ""; + result += Templates.main_context(); + result += Templates.load_manager(); + return result; + } + generateProvider(isDeployment) { let self = this; let result = ""; diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index c6f31dfbd..9d98b6a02 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -77,10 +77,16 @@ class Deploy { if (contract.onDeploy !== undefined) { self.logger.info('executing onDeploy commands'); let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); + let context = codeGenerator.generateContext(); let code = codeGenerator.generateContracts(false, true, true); let cmds = contract.onDeploy.join(';\n'); - RunCode.doEval(code + "\n" + cmds, self.web3); + let _cmds = "" + _cmds += "__mainContext.__loadManagerInstance.execWhenReady(function() {" + _cmds += cmds; + _cmds += "});" + + RunCode.doEval(context + "\n" + code + "\n" + _cmds, self.web3); } callback();