From 5a2cf62ee5c8f4effe15fab7fa703d40921b6bb9 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 14 Jun 2018 09:21:51 -0400 Subject: [PATCH] reload config; create a config so it doens't damage original --- lib/contracts/contract_deployer.js | 7 +++++-- lib/contracts/contracts.js | 16 +++++++++++++++- lib/core/config.js | 9 +++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/contracts/contract_deployer.js b/lib/contracts/contract_deployer.js index 546012c8..3385d642 100644 --- a/lib/contracts/contract_deployer.js +++ b/lib/contracts/contract_deployer.js @@ -216,10 +216,13 @@ class ContractDeployer { }, function estimateCorrectGas(next) { if (contract.gas === 'auto') { - return deployObject.estimateGas().then((gasValue) => { + return self.blockchain.estimateDeployContractGas(deployObject, (err, gasValue) => { + if (err) { + return next(err); + } contract.gas = gasValue; next(); - }).catch(next); + }); } next(); }, diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index 7e30d94d..5305558f 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -1,5 +1,6 @@ let toposort = require('toposort'); let async = require('async'); +const cloneDeep = require('clone-deep'); let utils = require('../utils/utils.js'); const constants = require('../constants'); @@ -10,7 +11,7 @@ class ContractsManager { constructor(options) { const self = this; this.contractFiles = options.contractFiles; - this.contractsConfig = options.contractsConfig; + this.contractsConfig = cloneDeep(options.contractsConfig || {}); this.contracts = {}; this.logger = options.logger; this.plugins = options.plugins; @@ -58,7 +59,20 @@ class ContractsManager { build(done) { let self = this; + self.contracts = {}; async.waterfall([ + function loadContractFiles(callback) { + self.events.request("config:contractsFiles", (contractsFiles) => { + self.contractsFiles = contractsFiles; + callback(); + }); + }, + function loadContractConfigs(callback) { + self.events.request("config:contractsConfig", (contractsConfig) => { + self.contractsConfig = cloneDeep(contractsConfig); + callback(); + }); + }, function compileContracts(callback) { self.events.emit("status", __("Compiling...")); if (process.env.isTest && self.compiledContracts && Object.keys(self.compiledContracts).length) { diff --git a/lib/core/config.js b/lib/core/config.js index dc124783..8b8e36c5 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -7,6 +7,7 @@ const deepEqual = require('deep-equal'); const constants = require('../constants'); var Config = function(options) { + const self = this; this.env = options.env; this.blockchainConfig = {}; this.contractsConfig = {}; @@ -22,6 +23,14 @@ var Config = function(options) { this.events = options.events; this.embarkConfig = {}; this.context = options.context || [constants.contexts.any]; + + self.events.setCommandHandler("config:contractsConfig", (cb) => { + cb(self.contractsConfig); + }); + + self.events.setCommandHandler("config:contractsFiles", (cb) => { + cb(self.contractsFiles); + }); }; Config.prototype.loadConfigFiles = function(options) {