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.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);
});

View File

@ -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);
// 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,9 +149,10 @@ 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);
// 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');
@ -165,6 +163,8 @@ class Deploy {
callback();
});
});
});
});
}

View File

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

View File

@ -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);
};

View File

@ -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();

View File

@ -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) {