conflict in code_generator

This commit is contained in:
Jonathan Rainville 2018-05-23 11:16:13 -04:00
parent 30b1975e34
commit 592b4ed4fd
6 changed files with 42 additions and 36 deletions

View File

@ -26,6 +26,7 @@ class CodeGenerator {
this.contractsConfig = options.contractsConfig || {}; this.contractsConfig = options.contractsConfig || {};
this.storageConfig = options.storageConfig || {}; this.storageConfig = options.storageConfig || {};
this.communicationConfig = options.communicationConfig || {}; this.communicationConfig = options.communicationConfig || {};
// TODO: this should also be removed and use events instead
this.contractsManager = options.contractsManager; this.contractsManager = options.contractsManager;
this.plugins = options.plugins; this.plugins = options.plugins;
this.events = options.events; this.events = options.events;
@ -107,6 +108,10 @@ class CodeGenerator {
self.buildContractJS(contractName, self.generateContractJSON(contractName, contract), cb); 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.events.setCommandHandler('embark-building-placeholder', (cb) => {
this.buildPlaceholderPage(cb); this.buildPlaceholderPage(cb);
}); });

View File

@ -4,13 +4,10 @@ let utils = require('../utils/utils.js');
let RunCode = require('../core/runCode.js'); let RunCode = require('../core/runCode.js');
let CodeGenerator = require('./code_generator.js');
class Deploy { class Deploy {
constructor(options) { constructor(options) {
this.blockchain = options.blockchain; this.blockchain = options.blockchain;
this.web3 = this.blockchain.web3; this.web3 = this.blockchain.web3;
this.contractsManager = options.contractsManager;
this.logger = options.logger; this.logger = options.logger;
this.events = options.events; this.events = options.events;
this.plugins = options.plugins; this.plugins = options.plugins;
@ -129,12 +126,12 @@ class Deploy {
contract.deployedAddress = trackedContract.address; contract.deployedAddress = trackedContract.address;
self.events.emit("deploy:contract:deployed", contract); self.events.emit("deploy:contract:deployed", contract);
// always run contractCode so other functionality like 'afterDeploy' can also work // TODO: can be moved into a afterDeploy event
let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); // just need to figure out the gasLimit coupling issue
let contractCode = codeGenerator.generateContractCode(contract, self.gasLimit); self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => {
RunCode.doEval(contractCode, {web3: self.web3}); RunCode.doEval(contractCode, {web3: self.web3});
return callback(); return callback();
});
} }
contractToDeploy(contract, params, callback) { contractToDeploy(contract, params, callback) {
@ -152,9 +149,10 @@ class Deploy {
contract.address = address; contract.address = address;
self.events.emit("deploy:contract:deployed", contract); self.events.emit("deploy:contract:deployed", contract);
// always run contractCode so other functionality like 'afterDeploy' can also work // TODO: can be moved into a afterDeploy event
let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); // just need to figure out the gasLimit coupling issue
let contractCode = codeGenerator.generateContractCode(contract, self.gasLimit); self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => {
RunCode.doEval(contractCode, self.web3);
RunCode.doEval(contractCode, {web3: self.web3}); RunCode.doEval(contractCode, {web3: self.web3});
let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions'); let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions');
@ -165,6 +163,8 @@ class Deploy {
callback(); callback();
}); });
}); });
});
}); });
} }

View File

@ -162,18 +162,19 @@ class Engine {
codeGeneratorService(_options) { codeGeneratorService(_options) {
let self = this; let self = this;
const generateCode = function (contractsManager) { this.codeGenerator = new CodeGenerator({
let codeGenerator = new CodeGenerator({
blockchainConfig: self.config.blockchainConfig, blockchainConfig: self.config.blockchainConfig,
contractsConfig: self.config.contractsConfig, contractsConfig: self.config.contractsConfig,
contractsManager: contractsManager, contractsManager: this.contractsManager,
plugins: self.plugins, plugins: self.plugins,
storageConfig: self.config.storageConfig, storageConfig: self.config.storageConfig,
communicationConfig: self.config.communicationConfig, communicationConfig: self.config.communicationConfig,
events: self.events events: self.events
}); });
codeGenerator.listenToCommands(); this.codeGenerator.listenToCommands();
codeGenerator.buildEmbarkJS(function() {
const generateCode = function () {
self.codeGenerator.buildEmbarkJS(function() {
self.events.emit('code-generator-ready'); self.events.emit('code-generator-ready');
}); });
}; };

View File

@ -40,7 +40,7 @@ EventEmitter.prototype.request = function() {
}; };
EventEmitter.prototype.setCommandHandler = function(requestName, cb) { EventEmitter.prototype.setCommandHandler = function(requestName, cb) {
log("setting command handler for: ", requestName); log("setting command handler for: " + requestName);
let listener = function(_cb) { let listener = function(_cb) {
cb.call(this, ...arguments); cb.call(this, ...arguments);
}; };

View File

@ -130,8 +130,8 @@ class Embark {
engine.startService("libraryManager"); engine.startService("libraryManager");
engine.startService("web3"); engine.startService("web3");
engine.startService("pipeline"); engine.startService("pipeline");
engine.startService("codeGenerator");
engine.startService("deployment"); engine.startService("deployment");
engine.startService("codeGenerator");
// TODO: this should be just 'storage' and the storage should figure out the module // TODO: this should be just 'storage' and the storage should figure out the module
engine.startService(engine.config.storageConfig.provider); engine.startService(engine.config.storageConfig.provider);
@ -204,8 +204,8 @@ class Embark {
engine.startService("libraryManager"); engine.startService("libraryManager");
engine.startService("web3"); engine.startService("web3");
engine.startService("pipeline"); engine.startService("pipeline");
engine.startService("codeGenerator");
engine.startService("deployment", {onlyCompile: options.onlyCompile}); 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 // TODO: this should be just 'storage' and the storage should figure out the modules to load
engine.startService("ipfs"); engine.startService("ipfs");
engine.startService("swarm"); engine.startService("swarm");
@ -260,8 +260,8 @@ class Embark {
engine.startMonitor(); engine.startMonitor();
engine.startService("libraryManager"); engine.startService("libraryManager");
engine.startService("pipeline"); engine.startService("pipeline");
engine.startService("codeGenerator");
engine.startService("deployment", {onlyCompile: true}); engine.startService("deployment", {onlyCompile: true});
engine.startService("codeGenerator");
engine.deployManager.deployContracts(function (err) { engine.deployManager.deployContracts(function (err) {
callback(err); callback(err);
@ -319,8 +319,8 @@ class Embark {
engine.startService("libraryManager"); engine.startService("libraryManager");
engine.startService("web3"); engine.startService("web3");
engine.startService("pipeline"); engine.startService("pipeline");
engine.startService("codeGenerator");
engine.startService("deployment"); engine.startService("deployment");
engine.startService("codeGenerator");
// TODO: this should be just 'storage' and the storage should figure out the modules to load // TODO: this should be just 'storage' and the storage should figure out the modules to load
engine.startService(platform.toLowerCase()); engine.startService(platform.toLowerCase());
engine.startMonitor(); engine.startMonitor();

View File

@ -68,13 +68,13 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
function startServices(callback) { function startServices(callback) {
//{abiType: 'contracts', embarkJS: false} //{abiType: 'contracts', embarkJS: false}
self.engine.startService("libraryManager"); self.engine.startService("libraryManager");
self.engine.startService("codeGenerator");
self.engine.startService("web3", { self.engine.startService("web3", {
web3: self.web3 web3: self.web3
}); });
self.engine.startService("deployment", { self.engine.startService("deployment", {
trackContracts: false trackContracts: false
}); });
self.engine.startService("codeGenerator");
callback(); callback();
}, },
function deploy(callback) { function deploy(callback) {