From 41baca4b5143e788a25cb882de71318f60acadcd Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 21 Feb 2018 18:43:34 -0500 Subject: [PATCH] don't redeploy if an asset has been changed and not a contract --- lib/contracts/deploy_manager.js | 11 ++-------- lib/core/engine.js | 37 ++++++++++++++++++++------------- lib/tests/test.js | 1 + 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index adf00aec4..d79682c25 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -1,7 +1,6 @@ let async = require('async'); //require("../utils/debug_util.js")(__filename, async); let Deploy = require('./deploy.js'); -let ContractsManager = require('./contracts.js'); let RunCode = require('../core/runCode.js'); class DeployManager { @@ -14,6 +13,7 @@ class DeployManager { this.plugins = options.plugins; this.web3 = options.web3; this.chainConfig = (options.trackContracts !== false) ? this.config.chainTracker : false; + this.contractsManager = options.contractsManager; this.gasLimit = false; this.fatalErrors = false; } @@ -29,14 +29,7 @@ class DeployManager { async.waterfall([ function buildContracts(callback) { - let contractsManager = new ContractsManager({ - contractFiles: self.config.contractsFiles, - contractsConfig: self.config.contractsConfig, - logger: self.logger, - plugins: self.plugins, - gasLimit: self.gasLimit - }); - contractsManager.build(callback); + self.contractsManager.build(callback); }, function checkWeb3IsConnected(contractsManager, callback) { if (!self.web3) { diff --git a/lib/core/engine.js b/lib/core/engine.js index 81c2662dd..fe9ec0253 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -2,6 +2,7 @@ let Web3 = require('web3'); let Events = require('./events.js'); let Logger = require('./logger.js'); let Config = require('./config.js'); +let ContractsManager = require('../contracts/contracts.js'); let DeployManager = require('../contracts/deploy_manager.js'); let CodeGenerator = require('../contracts/code_generator.js'); let ServicesMonitor = require('./services_monitor.js'); @@ -99,13 +100,11 @@ class Engine { }); // TODO: still need to redeploy contracts because the original contracts // config is being corrupted - //this.events.on('file-event', function(fileType, path) { - // if (fileType === 'asset') { - // self.config.reloadConfig(); - // pipeline.build(self.abi, self.contractsJSON, path); - // self.events.emit('outputDone'); - // } - //}); + this.events.on('file-event', function(fileType, _path) { + if (fileType === 'asset') { + self.events.emit('asset-changed', self.contractsManager); + } + }); } codeGeneratorService(_options) { @@ -128,6 +127,7 @@ class Engine { }; this.events.on('contractsDeployed', generateCode); this.events.on('blockchainDisabled', generateCode); + this.events.on('asset-changed', generateCode); } deploymentService(options) { @@ -137,23 +137,32 @@ class Engine { contractDirectories: self.config.contractDirectories }); + this.contractsManager = new ContractsManager({ + contractFiles: this.config.contractsFiles, + contractsConfig: this.config.contractsConfig, + logger: this.logger, + plugins: this.plugins, + gasLimit: false + }); + this.deployManager = new DeployManager({ web3: options.web3 || self.web3, trackContracts: options.trackContracts, config: this.config, logger: this.logger, plugins: this.plugins, - events: this.events + events: this.events, + contractsManager: this.contractsManager }); - this.events.on('file-event', function (_fileType, _path) { + this.events.on('file-event', function (fileType, _path) { // TODO: for now need to deploy on asset chanes as well // because the contractsManager config is corrupted after a deploy - //if (fileType === 'contract' || fileType === 'config') { - self.config.reloadConfig(); - self.deployManager.deployContracts(function () { - }); - //} + if (fileType === 'contract' || fileType === 'config') { + self.config.reloadConfig(); + self.deployManager.deployContracts(function () { + }); + } }); } diff --git a/lib/tests/test.js b/lib/tests/test.js index 52a60ec99..9831900c1 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -77,6 +77,7 @@ Test.prototype.deployAll = function(contractsConfig, cb) { }); self.engine.deployManager.gasLimit = 6000000; + self.engine.contractsManager.gasLimit = 6000000; self.engine.deployManager.fatalErrors = true; self.engine.deployManager.deployContracts(function(err, _result) { if (err) {