From 592b4ed4fdda3cbe8d0f16ca99240f84497bbff8 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 23 May 2018 11:16:13 -0400 Subject: [PATCH] conflict in code_generator --- lib/contracts/code_generator.js | 5 +++++ lib/contracts/deploy.js | 36 ++++++++++++++++----------------- lib/core/engine.js | 25 ++++++++++++----------- lib/core/events.js | 2 +- lib/index.js | 8 ++++---- lib/tests/test.js | 2 +- 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index b905fc0b2..e7e8064d5 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -26,6 +26,7 @@ class CodeGenerator { this.contractsConfig = options.contractsConfig || {}; this.storageConfig = options.storageConfig || {}; this.communicationConfig = options.communicationConfig || {}; + // TODO: this should also be removed and use events instead this.contractsManager = options.contractsManager; this.plugins = options.plugins; this.events = options.events; @@ -107,6 +108,10 @@ class CodeGenerator { self.buildContractJS(contractName, self.generateContractJSON(contractName, contract), cb); }); + self.events.setCommandHandler('code-generator:contract:vanilla', (contract, gasLimit, cb) => { + cb(self.generateContractCode(contract, gasLimit)); + }); + this.events.setCommandHandler('embark-building-placeholder', (cb) => { this.buildPlaceholderPage(cb); }); diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index 0f3c50b16..490522d53 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -4,13 +4,10 @@ let utils = require('../utils/utils.js'); let RunCode = require('../core/runCode.js'); -let CodeGenerator = require('./code_generator.js'); - class Deploy { constructor(options) { this.blockchain = options.blockchain; this.web3 = this.blockchain.web3; - this.contractsManager = options.contractsManager; this.logger = options.logger; this.events = options.events; this.plugins = options.plugins; @@ -129,12 +126,12 @@ class Deploy { contract.deployedAddress = trackedContract.address; self.events.emit("deploy:contract:deployed", contract); - // always run contractCode so other functionality like 'afterDeploy' can also work - let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); - let contractCode = codeGenerator.generateContractCode(contract, self.gasLimit); - RunCode.doEval(contractCode, {web3: self.web3}); - - return callback(); + // TODO: can be moved into a afterDeploy event + // just need to figure out the gasLimit coupling issue + self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { + RunCode.doEval(contractCode, {web3: self.web3}); + return callback(); + }); } contractToDeploy(contract, params, callback) { @@ -152,18 +149,21 @@ class Deploy { contract.address = address; self.events.emit("deploy:contract:deployed", contract); - // always run contractCode so other functionality like 'afterDeploy' can also work - let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); - let contractCode = codeGenerator.generateContractCode(contract, self.gasLimit); - RunCode.doEval(contractCode, {web3: self.web3}); + // TODO: can be moved into a afterDeploy event + // just need to figure out the gasLimit coupling issue + self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { + RunCode.doEval(contractCode, self.web3); + RunCode.doEval(contractCode, {web3: self.web3}); - let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions'); + let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions'); - async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) { - plugin.call(plugin, contract, nextEach); - }, () => { - callback(); + async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) { + plugin.call(plugin, contract, nextEach); + }, () => { + callback(); + }); }); + }); }); } diff --git a/lib/core/engine.js b/lib/core/engine.js index f93399003..388b4c5cc 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -162,18 +162,19 @@ class Engine { codeGeneratorService(_options) { let self = this; - const generateCode = function (contractsManager) { - let codeGenerator = new CodeGenerator({ - blockchainConfig: self.config.blockchainConfig, - contractsConfig: self.config.contractsConfig, - contractsManager: contractsManager, - plugins: self.plugins, - storageConfig: self.config.storageConfig, - communicationConfig: self.config.communicationConfig, - events: self.events - }); - codeGenerator.listenToCommands(); - codeGenerator.buildEmbarkJS(function() { + this.codeGenerator = new CodeGenerator({ + blockchainConfig: self.config.blockchainConfig, + contractsConfig: self.config.contractsConfig, + contractsManager: this.contractsManager, + plugins: self.plugins, + storageConfig: self.config.storageConfig, + communicationConfig: self.config.communicationConfig, + events: self.events + }); + this.codeGenerator.listenToCommands(); + + const generateCode = function () { + self.codeGenerator.buildEmbarkJS(function() { self.events.emit('code-generator-ready'); }); }; diff --git a/lib/core/events.js b/lib/core/events.js index de28c1897..2111e221c 100644 --- a/lib/core/events.js +++ b/lib/core/events.js @@ -40,7 +40,7 @@ EventEmitter.prototype.request = function() { }; EventEmitter.prototype.setCommandHandler = function(requestName, cb) { - log("setting command handler for: ", requestName); + log("setting command handler for: " + requestName); let listener = function(_cb) { cb.call(this, ...arguments); }; diff --git a/lib/index.js b/lib/index.js index b66da112a..0d3c9d381 100644 --- a/lib/index.js +++ b/lib/index.js @@ -130,8 +130,8 @@ class Embark { engine.startService("libraryManager"); engine.startService("web3"); engine.startService("pipeline"); - engine.startService("codeGenerator"); engine.startService("deployment"); + engine.startService("codeGenerator"); // TODO: this should be just 'storage' and the storage should figure out the module engine.startService(engine.config.storageConfig.provider); @@ -204,8 +204,8 @@ class Embark { engine.startService("libraryManager"); engine.startService("web3"); engine.startService("pipeline"); - engine.startService("codeGenerator"); engine.startService("deployment", {onlyCompile: options.onlyCompile}); + engine.startService("codeGenerator"); // TODO: this should be just 'storage' and the storage should figure out the modules to load engine.startService("ipfs"); engine.startService("swarm"); @@ -260,8 +260,8 @@ class Embark { engine.startMonitor(); engine.startService("libraryManager"); engine.startService("pipeline"); - engine.startService("codeGenerator"); engine.startService("deployment", {onlyCompile: true}); + engine.startService("codeGenerator"); engine.deployManager.deployContracts(function (err) { callback(err); @@ -319,8 +319,8 @@ class Embark { engine.startService("libraryManager"); engine.startService("web3"); engine.startService("pipeline"); - engine.startService("codeGenerator"); engine.startService("deployment"); + engine.startService("codeGenerator"); // TODO: this should be just 'storage' and the storage should figure out the modules to load engine.startService(platform.toLowerCase()); engine.startMonitor(); diff --git a/lib/tests/test.js b/lib/tests/test.js index d89a649c2..125a3fea5 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -68,13 +68,13 @@ Test.prototype.deployAll = function(contractsConfig, cb) { function startServices(callback) { //{abiType: 'contracts', embarkJS: false} self.engine.startService("libraryManager"); - self.engine.startService("codeGenerator"); self.engine.startService("web3", { web3: self.web3 }); self.engine.startService("deployment", { trackContracts: false }); + self.engine.startService("codeGenerator"); callback(); }, function deploy(callback) {