diff --git a/lib/core/plugins.js b/lib/core/plugins.js index 9c80276d7..ec8c35987 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -141,14 +141,12 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb) { return cb(args); } - //async.eachLimit(actionPlugins, 1, function(plugin, nextEach) { async.reduce(actionPlugins, args, function(current_args, plugin, nextEach) { if (typeof (args) === 'function') { plugin.call(plugin, (params) => { nextEach(null, (params || current_args)); }); } else { - //plugin.call(plugin, ...args, nextEach); plugin.call(plugin, args, (params) => { nextEach(null, (params || current_args)); }); diff --git a/lib/modules/deployment/contract_deployer.js b/lib/modules/deployment/contract_deployer.js index 32acc7e6b..57a0345f5 100644 --- a/lib/modules/deployment/contract_deployer.js +++ b/lib/modules/deployment/contract_deployer.js @@ -144,11 +144,7 @@ class ContractDeployer { if (process.env.isTest) { return self.deployContract(contract, next); } - // TODO: this should be a plugin API instead, if not existing, it should by default deploy the contract - //self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) { self.plugins.emitAndRunActionsForEvent('deploy:contract:shouldDeploy', {contract: contract, shouldDeploy: true}, function(_err, params) { - console.dir(contract.className); - console.dir(arguments); let trackedContract = params.contract; if (!params.shouldDeploy) { return next(); diff --git a/lib/modules/deploytracker/index.js b/lib/modules/deploytracker/index.js index 7406edb08..c086b25db 100644 --- a/lib/modules/deploytracker/index.js +++ b/lib/modules/deploytracker/index.js @@ -25,7 +25,6 @@ class DeployTracker { self.save(); }); - //this.events.setCommandHandler("deploy:contract:shouldDeploy", (contract, cb) => { self.embark.registerActionForEvent("deploy:contract:shouldDeploy", (params, cb) => { let contract = params.contract; let trackedContract = self.getContract(contract.className, contract.realRuntimeBytecode, contract.realArgs); diff --git a/lib/modules/specialconfigs/index.js b/lib/modules/specialconfigs/index.js index e3fa9b1ac..1486bee11 100644 --- a/lib/modules/specialconfigs/index.js +++ b/lib/modules/specialconfigs/index.js @@ -12,7 +12,7 @@ class SpecialConfigs { this.registerAfterDeployAction(); this.registerOnDeployAction(); - this.registerDeployIfAction() + this.registerDeployIfAction(); } replaceWithAddresses(cmd, cb) { @@ -109,19 +109,23 @@ class SpecialConfigs { const self = this; self.embark.registerActionForEvent("deploy:contract:shouldDeploy", (params, cb) => { - console.dir(params.contract.className) - console.dir(params.contract.classNideployIf) - self.embark.logger.info("===applying shouldDeploy plugin..."); - if (params.contract.deployIf === 'hello') { - console.dir("-------------") - console.dir("-------------") - console.dir("contract has the param") - console.dir("-------------") - console.dir("-------------") + let cmd = params.contract.deployIf; + if (!cmd) { + return cb(params); } - params.shouldDeploy = (params.contract.deployIf !== 'hello'); - //cb(true, contract); - cb(params); + + self.events.request('runcode:eval', cmd, (err, result) => { + if (err) { + self.logger.error(params.contract.className + ' deployIf directive has an error; contract will not deploy'); + self.logger.error(err); + params.shouldDeploy = false; + } else if (!result) { + self.logger.info(params.contract.className + ' deployIf directive returned false; contract will not deploy'); + params.shouldDeploy = false; + } + + cb(params); + }); }); } diff --git a/test_apps/test_app/config/contracts.js b/test_apps/test_app/config/contracts.js index b9909cab9..54238d58f 100644 --- a/test_apps/test_app/config/contracts.js +++ b/test_apps/test_app/config/contracts.js @@ -53,6 +53,7 @@ module.exports = { } }, SomeContract: { + deployIf: 'MyToken.methods.isAvailable().call()', args: [ ["$MyToken2", "$SimpleStorage"], 100 diff --git a/test_apps/test_app/contracts/token.sol b/test_apps/test_app/contracts/token.sol index 32b1dafdc..fc39b405b 100644 --- a/test_apps/test_app/contracts/token.sol +++ b/test_apps/test_app/contracts/token.sol @@ -63,4 +63,7 @@ contract Token { function safeToAdd(uint a, uint b) internal pure returns (bool) { return (a + b >= a); } + function isAvailable() public constant returns (bool) { + return true; + } }